From 9f414612099c89db721c70a22d4229b76adfba9f Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 10 May 2021 18:27:23 +0400 Subject: [PATCH] Load .dll symbols in a similar way. --- .../SourceFiles/platform/win/windows_dlls.cpp | 70 +++++---------- .../SourceFiles/platform/win/windows_dlls.h | 87 ++++++------------- 2 files changed, 52 insertions(+), 105 deletions(-) diff --git a/Telegram/SourceFiles/platform/win/windows_dlls.cpp b/Telegram/SourceFiles/platform/win/windows_dlls.cpp index ee01699960..ce84175f57 100644 --- a/Telegram/SourceFiles/platform/win/windows_dlls.cpp +++ b/Telegram/SourceFiles/platform/win/windows_dlls.cpp @@ -14,7 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include -#define LOAD_METHOD(lib, name) ::base::Platform::LoadMethod(lib, #name, name) +#define LOAD_SYMBOL(lib, name) ::base::Platform::LoadMethod(lib, #name, name) namespace Platform { namespace Dlls { @@ -54,28 +54,6 @@ void init() { } } -f_SetWindowTheme SetWindowTheme; -//f_RefreshImmersiveColorPolicyState RefreshImmersiveColorPolicyState; -//f_AllowDarkModeForApp AllowDarkModeForApp; -//f_SetPreferredAppMode SetPreferredAppMode; -//f_AllowDarkModeForWindow AllowDarkModeForWindow; -//f_FlushMenuThemes FlushMenuThemes; -f_OpenAs_RunDLL OpenAs_RunDLL; -f_SHOpenWithDialog SHOpenWithDialog; -f_SHAssocEnumHandlers SHAssocEnumHandlers; -f_SHCreateItemFromParsingName SHCreateItemFromParsingName; -f_WTSRegisterSessionNotification WTSRegisterSessionNotification; -f_WTSUnRegisterSessionNotification WTSUnRegisterSessionNotification; -f_SHQueryUserNotificationState SHQueryUserNotificationState; -f_SHChangeNotify SHChangeNotify; -f_SetCurrentProcessExplicitAppUserModelID SetCurrentProcessExplicitAppUserModelID; -f_PropVariantToString PropVariantToString; -f_PSStringFromPropertyKey PSStringFromPropertyKey; -f_DwmIsCompositionEnabled DwmIsCompositionEnabled; -f_DwmSetWindowAttribute DwmSetWindowAttribute; -f_GetProcessMemoryInfo GetProcessMemoryInfo; -f_SetWindowCompositionAttribute SetWindowCompositionAttribute; - // D3D11.DLL HRESULT (__stdcall *D3D11CreateDevice)( @@ -100,57 +78,57 @@ void start() { init(); 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); + LOAD_SYMBOL(LibShell32, SHAssocEnumHandlers); + LOAD_SYMBOL(LibShell32, SHCreateItemFromParsingName); + LOAD_SYMBOL(LibShell32, SHOpenWithDialog); + LOAD_SYMBOL(LibShell32, OpenAs_RunDLL); + LOAD_SYMBOL(LibShell32, SHQueryUserNotificationState); + LOAD_SYMBOL(LibShell32, SHChangeNotify); + LOAD_SYMBOL(LibShell32, SetCurrentProcessExplicitAppUserModelID); const auto LibUxTheme = SafeLoadLibrary(u"uxtheme.dll"_q); - LoadMethod(LibUxTheme, "SetWindowTheme", SetWindowTheme); + LOAD_SYMBOL(LibUxTheme, SetWindowTheme); //if (IsWindows10OrGreater()) { // static const auto kSystemVersion = QOperatingSystemVersion::current(); // static const auto kMinor = kSystemVersion.minorVersion(); // static const auto kBuild = kSystemVersion.microVersion(); // if (kMinor > 0 || (kMinor == 0 && kBuild >= 17763)) { // if (kBuild < 18362) { - // LoadMethod(LibUxTheme, "AllowDarkModeForApp", AllowDarkModeForApp, 135); + // LOAD_SYMBOL(LibUxTheme, AllowDarkModeForApp, 135); // } else { - // LoadMethod(LibUxTheme, "SetPreferredAppMode", SetPreferredAppMode, 135); + // LOAD_SYMBOL(LibUxTheme, SetPreferredAppMode, 135); // } - // LoadMethod(LibUxTheme, "AllowDarkModeForWindow", AllowDarkModeForWindow, 133); - // LoadMethod(LibUxTheme, "RefreshImmersiveColorPolicyState", RefreshImmersiveColorPolicyState, 104); - // LoadMethod(LibUxTheme, "FlushMenuThemes", FlushMenuThemes, 136); + // LOAD_SYMBOL(LibUxTheme, AllowDarkModeForWindow, 133); + // LOAD_SYMBOL(LibUxTheme, RefreshImmersiveColorPolicyState, 104); + // LOAD_SYMBOL(LibUxTheme, FlushMenuThemes, 136); // } //} if (IsWindowsVistaOrGreater()) { const auto LibWtsApi32 = SafeLoadLibrary(u"wtsapi32.dll"_q); - LoadMethod(LibWtsApi32, "WTSRegisterSessionNotification", WTSRegisterSessionNotification); - LoadMethod(LibWtsApi32, "WTSUnRegisterSessionNotification", WTSUnRegisterSessionNotification); + LOAD_SYMBOL(LibWtsApi32, WTSRegisterSessionNotification); + LOAD_SYMBOL(LibWtsApi32, WTSUnRegisterSessionNotification); const auto LibPropSys = SafeLoadLibrary(u"propsys.dll"_q); - LoadMethod(LibPropSys, "PropVariantToString", PropVariantToString); - LoadMethod(LibPropSys, "PSStringFromPropertyKey", PSStringFromPropertyKey); + LOAD_SYMBOL(LibPropSys, PropVariantToString); + LOAD_SYMBOL(LibPropSys, PSStringFromPropertyKey); const auto LibDwmApi = SafeLoadLibrary(u"dwmapi.dll"_q); - LoadMethod(LibDwmApi, "DwmIsCompositionEnabled", DwmIsCompositionEnabled); - LoadMethod(LibDwmApi, "DwmSetWindowAttribute", DwmSetWindowAttribute); + LOAD_SYMBOL(LibDwmApi, DwmIsCompositionEnabled); + LOAD_SYMBOL(LibDwmApi, DwmSetWindowAttribute); } const auto LibPsApi = SafeLoadLibrary(u"psapi.dll"_q); - LoadMethod(LibPsApi, "GetProcessMemoryInfo", GetProcessMemoryInfo); + LOAD_SYMBOL(LibPsApi, GetProcessMemoryInfo); const auto LibUser32 = SafeLoadLibrary(u"user32.dll"_q); - LoadMethod(LibUser32, "SetWindowCompositionAttribute", SetWindowCompositionAttribute); + LOAD_SYMBOL(LibUser32, SetWindowCompositionAttribute); const auto LibD3D11 = SafeLoadLibrary(u"d3d11.dll"_q); - LOAD_METHOD(LibD3D11, D3D11CreateDevice); + LOAD_SYMBOL(LibD3D11, D3D11CreateDevice); const auto LibDXGI = SafeLoadLibrary(u"dxgi.dll"_q); - LOAD_METHOD(LibDXGI, CreateDXGIFactory1); + LOAD_SYMBOL(LibDXGI, CreateDXGIFactory1); } } // namespace Dlls diff --git a/Telegram/SourceFiles/platform/win/windows_dlls.h b/Telegram/SourceFiles/platform/win/windows_dlls.h index 7f34e59e42..0a31aaba2f 100644 --- a/Telegram/SourceFiles/platform/win/windows_dlls.h +++ b/Telegram/SourceFiles/platform/win/windows_dlls.h @@ -23,25 +23,20 @@ namespace Platform { namespace Dlls { void init(); - -// KERNEL32.DLL -using f_SetDllDirectory = BOOL(FAR STDAPICALLTYPE*)(LPCWSTR lpPathName); -extern f_SetDllDirectory SetDllDirectory; - void start(); +// KERNEL32.DLL +inline BOOL(__stdcall *SetDllDirectory)(LPCWSTR lpPathName); + // UXTHEME.DLL -using f_SetWindowTheme = HRESULT(FAR STDAPICALLTYPE*)( +inline HRESULT(__stdcall *SetWindowTheme)( HWND hWnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList); -extern f_SetWindowTheme SetWindowTheme; -//using f_RefreshImmersiveColorPolicyState = void(FAR STDAPICALLTYPE*)(); -//extern f_RefreshImmersiveColorPolicyState RefreshImmersiveColorPolicyState; +//inline void(__stdcall *RefreshImmersiveColorPolicyState)(); // -//using f_AllowDarkModeForApp = BOOL(FAR STDAPICALLTYPE*)(BOOL allow); -//extern f_AllowDarkModeForApp AllowDarkModeForApp; +//inline BOOL(__stdcall *AllowDarkModeForApp)(BOOL allow); // //enum class PreferredAppMode { // Default, @@ -51,101 +46,74 @@ extern f_SetWindowTheme SetWindowTheme; // Max //}; // -//using f_SetPreferredAppMode = PreferredAppMode(FAR STDAPICALLTYPE*)(PreferredAppMode appMode); -//extern f_SetPreferredAppMode SetPreferredAppMode; -// -//using f_AllowDarkModeForWindow = BOOL(FAR STDAPICALLTYPE*)(HWND hwnd, BOOL allow); -//extern f_AllowDarkModeForWindow AllowDarkModeForWindow; -// -//using f_FlushMenuThemes = void(FAR STDAPICALLTYPE*)(); -//extern f_FlushMenuThemes FlushMenuThemes; +//inline PreferredAppMode(__stdcall *SetPreferredAppMode)( +// PreferredAppMode appMode); +//inline BOOL(__stdcall *AllowDarkModeForWindow)(HWND hwnd, BOOL allow); +//inline void(__stdcall *FlushMenuThemes)(); // SHELL32.DLL -using f_SHAssocEnumHandlers = HRESULT(FAR STDAPICALLTYPE*)( +inline HRESULT(__stdcall *SHAssocEnumHandlers)( PCWSTR pszExtra, ASSOC_FILTER afFilter, IEnumAssocHandlers **ppEnumHandler); -extern f_SHAssocEnumHandlers SHAssocEnumHandlers; - -using f_SHCreateItemFromParsingName = HRESULT(FAR STDAPICALLTYPE*)( +inline HRESULT(__stdcall *SHCreateItemFromParsingName)( PCWSTR pszPath, IBindCtx *pbc, REFIID riid, void **ppv); -extern f_SHCreateItemFromParsingName SHCreateItemFromParsingName; - -using f_SHOpenWithDialog = HRESULT(FAR STDAPICALLTYPE*)( +inline HRESULT(__stdcall *SHOpenWithDialog)( HWND hwndParent, const OPENASINFO *poainfo); -extern f_SHOpenWithDialog SHOpenWithDialog; - -using f_OpenAs_RunDLL = HRESULT(FAR STDAPICALLTYPE*)( +inline HRESULT(__stdcall *OpenAs_RunDLL)( HWND hWnd, HINSTANCE hInstance, LPCWSTR lpszCmdLine, int nCmdShow); -extern f_OpenAs_RunDLL OpenAs_RunDLL; - -using f_SHQueryUserNotificationState = HRESULT(FAR STDAPICALLTYPE*)( +inline HRESULT(__stdcall *SHQueryUserNotificationState)( QUERY_USER_NOTIFICATION_STATE *pquns); -extern f_SHQueryUserNotificationState SHQueryUserNotificationState; - -using f_SHChangeNotify = void(FAR STDAPICALLTYPE*)( +inline void(__stdcall *SHChangeNotify)( LONG wEventId, UINT uFlags, __in_opt LPCVOID dwItem1, __in_opt LPCVOID dwItem2); -extern f_SHChangeNotify SHChangeNotify; - -using f_SetCurrentProcessExplicitAppUserModelID - = HRESULT(FAR STDAPICALLTYPE*)(__in PCWSTR AppID); -extern f_SetCurrentProcessExplicitAppUserModelID SetCurrentProcessExplicitAppUserModelID; +inline HRESULT(__stdcall *SetCurrentProcessExplicitAppUserModelID)( + __in PCWSTR AppID); // WTSAPI32.DLL -using f_WTSRegisterSessionNotification = BOOL(FAR STDAPICALLTYPE*)( +inline BOOL(__stdcall *WTSRegisterSessionNotification)( HWND hWnd, DWORD dwFlags); -extern f_WTSRegisterSessionNotification WTSRegisterSessionNotification; - -using f_WTSUnRegisterSessionNotification = BOOL(FAR STDAPICALLTYPE*)( +inline BOOL(__stdcall *WTSUnRegisterSessionNotification)( HWND hWnd); -extern f_WTSUnRegisterSessionNotification WTSUnRegisterSessionNotification; // PROPSYS.DLL -using f_PropVariantToString = HRESULT(FAR STDAPICALLTYPE*)( +inline HRESULT(__stdcall *PropVariantToString)( _In_ REFPROPVARIANT propvar, _Out_writes_(cch) PWSTR psz, _In_ UINT cch); -extern f_PropVariantToString PropVariantToString; - -using f_PSStringFromPropertyKey = HRESULT(FAR STDAPICALLTYPE*)( +inline HRESULT(__stdcall *PSStringFromPropertyKey)( _In_ REFPROPERTYKEY pkey, _Out_writes_(cch) LPWSTR psz, _In_ UINT cch); -extern f_PSStringFromPropertyKey PSStringFromPropertyKey; // DWMAPI.DLL -using f_DwmIsCompositionEnabled = HRESULT(FAR STDAPICALLTYPE*)( +inline HRESULT(__stdcall *DwmIsCompositionEnabled)( _Out_ BOOL* pfEnabled); -extern f_DwmIsCompositionEnabled DwmIsCompositionEnabled; - -using f_DwmSetWindowAttribute = HRESULT(FAR STDAPICALLTYPE*)( +inline HRESULT(__stdcall *DwmSetWindowAttribute)( HWND hwnd, DWORD dwAttribute, _In_reads_bytes_(cbAttribute) LPCVOID pvAttribute, DWORD cbAttribute); -extern f_DwmSetWindowAttribute DwmSetWindowAttribute; // PSAPI.DLL -using f_GetProcessMemoryInfo = BOOL(FAR STDAPICALLTYPE*)( +inline BOOL(__stdcall *GetProcessMemoryInfo)( HANDLE Process, PPROCESS_MEMORY_COUNTERS ppsmemCounters, DWORD cb); -extern f_GetProcessMemoryInfo GetProcessMemoryInfo; // USER32.DLL @@ -186,8 +154,9 @@ struct WINDOWCOMPOSITIONATTRIBDATA { SIZE_T cbData; }; -using f_SetWindowCompositionAttribute = BOOL(WINAPI *)(HWND hWnd, WINDOWCOMPOSITIONATTRIBDATA*); -extern f_SetWindowCompositionAttribute SetWindowCompositionAttribute; +inline BOOL(__stdcall *SetWindowCompositionAttribute)( + HWND hWnd, + WINDOWCOMPOSITIONATTRIBDATA*); } // namespace Dlls } // namespace Platform