diff --git a/Telegram/SourceFiles/platform/win/windows_dlls.cpp b/Telegram/SourceFiles/platform/win/windows_dlls.cpp index ec40c3f58..2a7278c86 100644 --- a/Telegram/SourceFiles/platform/win/windows_dlls.cpp +++ b/Telegram/SourceFiles/platform/win/windows_dlls.cpp @@ -7,26 +7,43 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "platform/win/windows_dlls.h" +#include "base/platform/win/base_windows_safe_library.h" + #include #include namespace Platform { namespace Dlls { -f_SetDllDirectory SetDllDirectory; - -HINSTANCE LibKernel32; +using base::Platform::SafeLoadLibrary; +using base::Platform::LoadMethod; void init() { static bool inited = false; if (inited) return; inited = true; - LibKernel32 = LoadLibrary(L"KERNEL32.DLL"); - load(LibKernel32, "SetDllDirectoryW", SetDllDirectory); - if (SetDllDirectory) { - // Remove the current directory from the DLL search order. - SetDllDirectory(L""); + // Remove the current directory from the DLL search order. + ::SetDllDirectory(L""); + + const auto list = { + u"dbghelp.dll"_q, + u"dbgcore.dll"_q, + u"propsys.dll"_q, + u"winsta.dll"_q, + u"textinputframework.dll"_q, + u"uxtheme.dll"_q, + u"igdumdim32.dll"_q, + u"amdhdl32.dll"_q, + u"wtsapi32.dll"_q, + u"propsys.dll"_q, + u"combase.dll"_q, + u"dwmapi.dll"_q, + u"rstrtmgr.dll"_q, + u"psapi.dll"_q, + }; + for (const auto &lib : list) { + SafeLoadLibrary(lib); } } @@ -53,59 +70,50 @@ f_RmShutdown RmShutdown; f_RmEndSession RmEndSession; f_GetProcessMemoryInfo GetProcessMemoryInfo; -HINSTANCE LibUxTheme; -HINSTANCE LibShell32; -HINSTANCE LibWtsApi32; -HINSTANCE LibPropSys; -HINSTANCE LibComBase; -HINSTANCE LibDwmApi; -HINSTANCE LibRstrtMgr; -HINSTANCE LibPsApi; - void start() { init(); - LibShell32 = LoadLibrary(L"SHELL32.DLL"); - load(LibShell32, "SHAssocEnumHandlers", SHAssocEnumHandlers); - load(LibShell32, "SHCreateItemFromParsingName", SHCreateItemFromParsingName); - load(LibShell32, "SHOpenWithDialog", SHOpenWithDialog); - load(LibShell32, "OpenAs_RunDLLW", OpenAs_RunDLL); - load(LibShell32, "SHQueryUserNotificationState", SHQueryUserNotificationState); - load(LibShell32, "SHChangeNotify", SHChangeNotify); - load(LibShell32, "SetCurrentProcessExplicitAppUserModelID", SetCurrentProcessExplicitAppUserModelID); + const auto LibShell32 = SafeLoadLibrary(u"shell32.dll"_q); + LoadMethod(LibShell32, "SHAssocEnumHandlers", SHAssocEnumHandlers); + LoadMethod(LibShell32, "SHCreateItemFromParsingName", SHCreateItemFromParsingName); + LoadMethod(LibShell32, "SHOpenWithDialog", SHOpenWithDialog); + LoadMethod(LibShell32, "OpenAs_RunDLLW", OpenAs_RunDLL); + LoadMethod(LibShell32, "SHQueryUserNotificationState", SHQueryUserNotificationState); + LoadMethod(LibShell32, "SHChangeNotify", SHChangeNotify); + LoadMethod(LibShell32, "SetCurrentProcessExplicitAppUserModelID", SetCurrentProcessExplicitAppUserModelID); - LibUxTheme = LoadLibrary(L"UXTHEME.DLL"); - load(LibUxTheme, "SetWindowTheme", SetWindowTheme); + const auto LibUxTheme = SafeLoadLibrary(u"uxtheme.dll"_q); + LoadMethod(LibUxTheme, "SetWindowTheme", SetWindowTheme); if (IsWindowsVistaOrGreater()) { - LibWtsApi32 = LoadLibrary(L"WTSAPI32.DLL"); - load(LibWtsApi32, "WTSRegisterSessionNotification", WTSRegisterSessionNotification); - load(LibWtsApi32, "WTSUnRegisterSessionNotification", WTSUnRegisterSessionNotification); + const auto LibWtsApi32 = SafeLoadLibrary(u"wtsapi32.dll"_q); + LoadMethod(LibWtsApi32, "WTSRegisterSessionNotification", WTSRegisterSessionNotification); + LoadMethod(LibWtsApi32, "WTSUnRegisterSessionNotification", WTSUnRegisterSessionNotification); - LibPropSys = LoadLibrary(L"PROPSYS.DLL"); - load(LibPropSys, "PropVariantToString", PropVariantToString); - load(LibPropSys, "PSStringFromPropertyKey", PSStringFromPropertyKey); + const auto LibPropSys = SafeLoadLibrary(u"propsys.dll"_q); + LoadMethod(LibPropSys, "PropVariantToString", PropVariantToString); + LoadMethod(LibPropSys, "PSStringFromPropertyKey", PSStringFromPropertyKey); if (IsWindows8OrGreater()) { - LibComBase = LoadLibrary(L"COMBASE.DLL"); - load(LibComBase, "RoGetActivationFactory", RoGetActivationFactory); - load(LibComBase, "WindowsCreateStringReference", WindowsCreateStringReference); - load(LibComBase, "WindowsDeleteString", WindowsDeleteString); + const auto LibComBase = SafeLoadLibrary(u"combase.dll"_q); + LoadMethod(LibComBase, "RoGetActivationFactory", RoGetActivationFactory); + LoadMethod(LibComBase, "WindowsCreateStringReference", WindowsCreateStringReference); + LoadMethod(LibComBase, "WindowsDeleteString", WindowsDeleteString); } - LibDwmApi = LoadLibrary(L"DWMAPI.DLL"); - load(LibDwmApi, "DwmIsCompositionEnabled", DwmIsCompositionEnabled); + const auto LibDwmApi = SafeLoadLibrary(u"dwmapi.dll"_q); + LoadMethod(LibDwmApi, "DwmIsCompositionEnabled", DwmIsCompositionEnabled); - LibRstrtMgr = LoadLibrary(L"RSTRTMGR.DLL"); - load(LibRstrtMgr, "RmStartSession", RmStartSession); - load(LibRstrtMgr, "RmRegisterResources", RmRegisterResources); - load(LibRstrtMgr, "RmGetList", RmGetList); - load(LibRstrtMgr, "RmShutdown", RmShutdown); - load(LibRstrtMgr, "RmEndSession", RmEndSession); + const auto LibRstrtMgr = SafeLoadLibrary(u"rstrtmgr.dll"_q); + LoadMethod(LibRstrtMgr, "RmStartSession", RmStartSession); + LoadMethod(LibRstrtMgr, "RmRegisterResources", RmRegisterResources); + LoadMethod(LibRstrtMgr, "RmGetList", RmGetList); + LoadMethod(LibRstrtMgr, "RmShutdown", RmShutdown); + LoadMethod(LibRstrtMgr, "RmEndSession", RmEndSession); } - LibPsApi = LoadLibrary(L"PSAPI.DLL"); - load(LibPsApi, "GetProcessMemoryInfo", GetProcessMemoryInfo); + const auto LibPsApi = SafeLoadLibrary(u"psapi.dll"_q); + LoadMethod(LibPsApi, "GetProcessMemoryInfo", GetProcessMemoryInfo); } } // namespace Dlls diff --git a/Telegram/SourceFiles/platform/win/windows_dlls.h b/Telegram/SourceFiles/platform/win/windows_dlls.h index 8844d87ef..c76865e78 100644 --- a/Telegram/SourceFiles/platform/win/windows_dlls.h +++ b/Telegram/SourceFiles/platform/win/windows_dlls.h @@ -30,14 +30,6 @@ extern f_SetDllDirectory SetDllDirectory; void start(); -template -bool load(HINSTANCE library, LPCSTR name, Function &func) { - if (!library) return false; - - func = reinterpret_cast(GetProcAddress(library, name)); - return (func != nullptr); -} - // UXTHEME.DLL using f_SetWindowTheme = HRESULT(FAR STDAPICALLTYPE*)( HWND hWnd, diff --git a/Telegram/lib_base b/Telegram/lib_base index 3017da83c..01ca681ab 160000 --- a/Telegram/lib_base +++ b/Telegram/lib_base @@ -1 +1 @@ -Subproject commit 3017da83c15e5e27244ab66526fea8cc3bddb7cf +Subproject commit 01ca681ab3aecda8c372b1bb77999f3b7b7a52c6 diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 262b3eb33..09918f013 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 262b3eb33593c638c46a30423c3774d9fe8171fc +Subproject commit 09918f0133ce0070000b9ca2a798057e6ad8bd5d diff --git a/cmake b/cmake index 6b36a649d..9346d5f89 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit 6b36a649dc0061138cf60bac65d9a40a5c9faea3 +Subproject commit 9346d5f89510c4f9e340a0e26a1f8c2244e7de29