Load .dll symbols in a similar way.

This commit is contained in:
John Preston 2021-05-10 18:27:23 +04:00
parent 6b10045b7b
commit 9f41461209
2 changed files with 52 additions and 105 deletions

View File

@ -14,7 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <d3d11.h> #include <d3d11.h>
#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 Platform {
namespace Dlls { 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 // D3D11.DLL
HRESULT (__stdcall *D3D11CreateDevice)( HRESULT (__stdcall *D3D11CreateDevice)(
@ -100,57 +78,57 @@ void start() {
init(); init();
const auto LibShell32 = SafeLoadLibrary(u"shell32.dll"_q); const auto LibShell32 = SafeLoadLibrary(u"shell32.dll"_q);
LoadMethod(LibShell32, "SHAssocEnumHandlers", SHAssocEnumHandlers); LOAD_SYMBOL(LibShell32, SHAssocEnumHandlers);
LoadMethod(LibShell32, "SHCreateItemFromParsingName", SHCreateItemFromParsingName); LOAD_SYMBOL(LibShell32, SHCreateItemFromParsingName);
LoadMethod(LibShell32, "SHOpenWithDialog", SHOpenWithDialog); LOAD_SYMBOL(LibShell32, SHOpenWithDialog);
LoadMethod(LibShell32, "OpenAs_RunDLLW", OpenAs_RunDLL); LOAD_SYMBOL(LibShell32, OpenAs_RunDLL);
LoadMethod(LibShell32, "SHQueryUserNotificationState", SHQueryUserNotificationState); LOAD_SYMBOL(LibShell32, SHQueryUserNotificationState);
LoadMethod(LibShell32, "SHChangeNotify", SHChangeNotify); LOAD_SYMBOL(LibShell32, SHChangeNotify);
LoadMethod(LibShell32, "SetCurrentProcessExplicitAppUserModelID", SetCurrentProcessExplicitAppUserModelID); LOAD_SYMBOL(LibShell32, SetCurrentProcessExplicitAppUserModelID);
const auto LibUxTheme = SafeLoadLibrary(u"uxtheme.dll"_q); const auto LibUxTheme = SafeLoadLibrary(u"uxtheme.dll"_q);
LoadMethod(LibUxTheme, "SetWindowTheme", SetWindowTheme); LOAD_SYMBOL(LibUxTheme, SetWindowTheme);
//if (IsWindows10OrGreater()) { //if (IsWindows10OrGreater()) {
// static const auto kSystemVersion = QOperatingSystemVersion::current(); // static const auto kSystemVersion = QOperatingSystemVersion::current();
// static const auto kMinor = kSystemVersion.minorVersion(); // static const auto kMinor = kSystemVersion.minorVersion();
// static const auto kBuild = kSystemVersion.microVersion(); // static const auto kBuild = kSystemVersion.microVersion();
// if (kMinor > 0 || (kMinor == 0 && kBuild >= 17763)) { // if (kMinor > 0 || (kMinor == 0 && kBuild >= 17763)) {
// if (kBuild < 18362) { // if (kBuild < 18362) {
// LoadMethod(LibUxTheme, "AllowDarkModeForApp", AllowDarkModeForApp, 135); // LOAD_SYMBOL(LibUxTheme, AllowDarkModeForApp, 135);
// } else { // } else {
// LoadMethod(LibUxTheme, "SetPreferredAppMode", SetPreferredAppMode, 135); // LOAD_SYMBOL(LibUxTheme, SetPreferredAppMode, 135);
// } // }
// LoadMethod(LibUxTheme, "AllowDarkModeForWindow", AllowDarkModeForWindow, 133); // LOAD_SYMBOL(LibUxTheme, AllowDarkModeForWindow, 133);
// LoadMethod(LibUxTheme, "RefreshImmersiveColorPolicyState", RefreshImmersiveColorPolicyState, 104); // LOAD_SYMBOL(LibUxTheme, RefreshImmersiveColorPolicyState, 104);
// LoadMethod(LibUxTheme, "FlushMenuThemes", FlushMenuThemes, 136); // LOAD_SYMBOL(LibUxTheme, FlushMenuThemes, 136);
// } // }
//} //}
if (IsWindowsVistaOrGreater()) { if (IsWindowsVistaOrGreater()) {
const auto LibWtsApi32 = SafeLoadLibrary(u"wtsapi32.dll"_q); const auto LibWtsApi32 = SafeLoadLibrary(u"wtsapi32.dll"_q);
LoadMethod(LibWtsApi32, "WTSRegisterSessionNotification", WTSRegisterSessionNotification); LOAD_SYMBOL(LibWtsApi32, WTSRegisterSessionNotification);
LoadMethod(LibWtsApi32, "WTSUnRegisterSessionNotification", WTSUnRegisterSessionNotification); LOAD_SYMBOL(LibWtsApi32, WTSUnRegisterSessionNotification);
const auto LibPropSys = SafeLoadLibrary(u"propsys.dll"_q); const auto LibPropSys = SafeLoadLibrary(u"propsys.dll"_q);
LoadMethod(LibPropSys, "PropVariantToString", PropVariantToString); LOAD_SYMBOL(LibPropSys, PropVariantToString);
LoadMethod(LibPropSys, "PSStringFromPropertyKey", PSStringFromPropertyKey); LOAD_SYMBOL(LibPropSys, PSStringFromPropertyKey);
const auto LibDwmApi = SafeLoadLibrary(u"dwmapi.dll"_q); const auto LibDwmApi = SafeLoadLibrary(u"dwmapi.dll"_q);
LoadMethod(LibDwmApi, "DwmIsCompositionEnabled", DwmIsCompositionEnabled); LOAD_SYMBOL(LibDwmApi, DwmIsCompositionEnabled);
LoadMethod(LibDwmApi, "DwmSetWindowAttribute", DwmSetWindowAttribute); LOAD_SYMBOL(LibDwmApi, DwmSetWindowAttribute);
} }
const auto LibPsApi = SafeLoadLibrary(u"psapi.dll"_q); const auto LibPsApi = SafeLoadLibrary(u"psapi.dll"_q);
LoadMethod(LibPsApi, "GetProcessMemoryInfo", GetProcessMemoryInfo); LOAD_SYMBOL(LibPsApi, GetProcessMemoryInfo);
const auto LibUser32 = SafeLoadLibrary(u"user32.dll"_q); const auto LibUser32 = SafeLoadLibrary(u"user32.dll"_q);
LoadMethod(LibUser32, "SetWindowCompositionAttribute", SetWindowCompositionAttribute); LOAD_SYMBOL(LibUser32, SetWindowCompositionAttribute);
const auto LibD3D11 = SafeLoadLibrary(u"d3d11.dll"_q); const auto LibD3D11 = SafeLoadLibrary(u"d3d11.dll"_q);
LOAD_METHOD(LibD3D11, D3D11CreateDevice); LOAD_SYMBOL(LibD3D11, D3D11CreateDevice);
const auto LibDXGI = SafeLoadLibrary(u"dxgi.dll"_q); const auto LibDXGI = SafeLoadLibrary(u"dxgi.dll"_q);
LOAD_METHOD(LibDXGI, CreateDXGIFactory1); LOAD_SYMBOL(LibDXGI, CreateDXGIFactory1);
} }
} // namespace Dlls } // namespace Dlls

View File

@ -23,25 +23,20 @@ namespace Platform {
namespace Dlls { namespace Dlls {
void init(); void init();
// KERNEL32.DLL
using f_SetDllDirectory = BOOL(FAR STDAPICALLTYPE*)(LPCWSTR lpPathName);
extern f_SetDllDirectory SetDllDirectory;
void start(); void start();
// KERNEL32.DLL
inline BOOL(__stdcall *SetDllDirectory)(LPCWSTR lpPathName);
// UXTHEME.DLL // UXTHEME.DLL
using f_SetWindowTheme = HRESULT(FAR STDAPICALLTYPE*)( inline HRESULT(__stdcall *SetWindowTheme)(
HWND hWnd, HWND hWnd,
LPCWSTR pszSubAppName, LPCWSTR pszSubAppName,
LPCWSTR pszSubIdList); LPCWSTR pszSubIdList);
extern f_SetWindowTheme SetWindowTheme;
//using f_RefreshImmersiveColorPolicyState = void(FAR STDAPICALLTYPE*)(); //inline void(__stdcall *RefreshImmersiveColorPolicyState)();
//extern f_RefreshImmersiveColorPolicyState RefreshImmersiveColorPolicyState;
// //
//using f_AllowDarkModeForApp = BOOL(FAR STDAPICALLTYPE*)(BOOL allow); //inline BOOL(__stdcall *AllowDarkModeForApp)(BOOL allow);
//extern f_AllowDarkModeForApp AllowDarkModeForApp;
// //
//enum class PreferredAppMode { //enum class PreferredAppMode {
// Default, // Default,
@ -51,101 +46,74 @@ extern f_SetWindowTheme SetWindowTheme;
// Max // Max
//}; //};
// //
//using f_SetPreferredAppMode = PreferredAppMode(FAR STDAPICALLTYPE*)(PreferredAppMode appMode); //inline PreferredAppMode(__stdcall *SetPreferredAppMode)(
//extern f_SetPreferredAppMode SetPreferredAppMode; // PreferredAppMode appMode);
// //inline BOOL(__stdcall *AllowDarkModeForWindow)(HWND hwnd, BOOL allow);
//using f_AllowDarkModeForWindow = BOOL(FAR STDAPICALLTYPE*)(HWND hwnd, BOOL allow); //inline void(__stdcall *FlushMenuThemes)();
//extern f_AllowDarkModeForWindow AllowDarkModeForWindow;
//
//using f_FlushMenuThemes = void(FAR STDAPICALLTYPE*)();
//extern f_FlushMenuThemes FlushMenuThemes;
// SHELL32.DLL // SHELL32.DLL
using f_SHAssocEnumHandlers = HRESULT(FAR STDAPICALLTYPE*)( inline HRESULT(__stdcall *SHAssocEnumHandlers)(
PCWSTR pszExtra, PCWSTR pszExtra,
ASSOC_FILTER afFilter, ASSOC_FILTER afFilter,
IEnumAssocHandlers **ppEnumHandler); IEnumAssocHandlers **ppEnumHandler);
extern f_SHAssocEnumHandlers SHAssocEnumHandlers; inline HRESULT(__stdcall *SHCreateItemFromParsingName)(
using f_SHCreateItemFromParsingName = HRESULT(FAR STDAPICALLTYPE*)(
PCWSTR pszPath, PCWSTR pszPath,
IBindCtx *pbc, IBindCtx *pbc,
REFIID riid, REFIID riid,
void **ppv); void **ppv);
extern f_SHCreateItemFromParsingName SHCreateItemFromParsingName; inline HRESULT(__stdcall *SHOpenWithDialog)(
using f_SHOpenWithDialog = HRESULT(FAR STDAPICALLTYPE*)(
HWND hwndParent, HWND hwndParent,
const OPENASINFO *poainfo); const OPENASINFO *poainfo);
extern f_SHOpenWithDialog SHOpenWithDialog; inline HRESULT(__stdcall *OpenAs_RunDLL)(
using f_OpenAs_RunDLL = HRESULT(FAR STDAPICALLTYPE*)(
HWND hWnd, HWND hWnd,
HINSTANCE hInstance, HINSTANCE hInstance,
LPCWSTR lpszCmdLine, LPCWSTR lpszCmdLine,
int nCmdShow); int nCmdShow);
extern f_OpenAs_RunDLL OpenAs_RunDLL; inline HRESULT(__stdcall *SHQueryUserNotificationState)(
using f_SHQueryUserNotificationState = HRESULT(FAR STDAPICALLTYPE*)(
QUERY_USER_NOTIFICATION_STATE *pquns); QUERY_USER_NOTIFICATION_STATE *pquns);
extern f_SHQueryUserNotificationState SHQueryUserNotificationState; inline void(__stdcall *SHChangeNotify)(
using f_SHChangeNotify = void(FAR STDAPICALLTYPE*)(
LONG wEventId, LONG wEventId,
UINT uFlags, UINT uFlags,
__in_opt LPCVOID dwItem1, __in_opt LPCVOID dwItem1,
__in_opt LPCVOID dwItem2); __in_opt LPCVOID dwItem2);
extern f_SHChangeNotify SHChangeNotify; inline HRESULT(__stdcall *SetCurrentProcessExplicitAppUserModelID)(
__in PCWSTR AppID);
using f_SetCurrentProcessExplicitAppUserModelID
= HRESULT(FAR STDAPICALLTYPE*)(__in PCWSTR AppID);
extern f_SetCurrentProcessExplicitAppUserModelID SetCurrentProcessExplicitAppUserModelID;
// WTSAPI32.DLL // WTSAPI32.DLL
using f_WTSRegisterSessionNotification = BOOL(FAR STDAPICALLTYPE*)( inline BOOL(__stdcall *WTSRegisterSessionNotification)(
HWND hWnd, HWND hWnd,
DWORD dwFlags); DWORD dwFlags);
extern f_WTSRegisterSessionNotification WTSRegisterSessionNotification; inline BOOL(__stdcall *WTSUnRegisterSessionNotification)(
using f_WTSUnRegisterSessionNotification = BOOL(FAR STDAPICALLTYPE*)(
HWND hWnd); HWND hWnd);
extern f_WTSUnRegisterSessionNotification WTSUnRegisterSessionNotification;
// PROPSYS.DLL // PROPSYS.DLL
using f_PropVariantToString = HRESULT(FAR STDAPICALLTYPE*)( inline HRESULT(__stdcall *PropVariantToString)(
_In_ REFPROPVARIANT propvar, _In_ REFPROPVARIANT propvar,
_Out_writes_(cch) PWSTR psz, _Out_writes_(cch) PWSTR psz,
_In_ UINT cch); _In_ UINT cch);
extern f_PropVariantToString PropVariantToString; inline HRESULT(__stdcall *PSStringFromPropertyKey)(
using f_PSStringFromPropertyKey = HRESULT(FAR STDAPICALLTYPE*)(
_In_ REFPROPERTYKEY pkey, _In_ REFPROPERTYKEY pkey,
_Out_writes_(cch) LPWSTR psz, _Out_writes_(cch) LPWSTR psz,
_In_ UINT cch); _In_ UINT cch);
extern f_PSStringFromPropertyKey PSStringFromPropertyKey;
// DWMAPI.DLL // DWMAPI.DLL
using f_DwmIsCompositionEnabled = HRESULT(FAR STDAPICALLTYPE*)( inline HRESULT(__stdcall *DwmIsCompositionEnabled)(
_Out_ BOOL* pfEnabled); _Out_ BOOL* pfEnabled);
extern f_DwmIsCompositionEnabled DwmIsCompositionEnabled; inline HRESULT(__stdcall *DwmSetWindowAttribute)(
using f_DwmSetWindowAttribute = HRESULT(FAR STDAPICALLTYPE*)(
HWND hwnd, HWND hwnd,
DWORD dwAttribute, DWORD dwAttribute,
_In_reads_bytes_(cbAttribute) LPCVOID pvAttribute, _In_reads_bytes_(cbAttribute) LPCVOID pvAttribute,
DWORD cbAttribute); DWORD cbAttribute);
extern f_DwmSetWindowAttribute DwmSetWindowAttribute;
// PSAPI.DLL // PSAPI.DLL
using f_GetProcessMemoryInfo = BOOL(FAR STDAPICALLTYPE*)( inline BOOL(__stdcall *GetProcessMemoryInfo)(
HANDLE Process, HANDLE Process,
PPROCESS_MEMORY_COUNTERS ppsmemCounters, PPROCESS_MEMORY_COUNTERS ppsmemCounters,
DWORD cb); DWORD cb);
extern f_GetProcessMemoryInfo GetProcessMemoryInfo;
// USER32.DLL // USER32.DLL
@ -186,8 +154,9 @@ struct WINDOWCOMPOSITIONATTRIBDATA {
SIZE_T cbData; SIZE_T cbData;
}; };
using f_SetWindowCompositionAttribute = BOOL(WINAPI *)(HWND hWnd, WINDOWCOMPOSITIONATTRIBDATA*); inline BOOL(__stdcall *SetWindowCompositionAttribute)(
extern f_SetWindowCompositionAttribute SetWindowCompositionAttribute; HWND hWnd,
WINDOWCOMPOSITIONATTRIBDATA*);
} // namespace Dlls } // namespace Dlls
} // namespace Platform } // namespace Platform