Skip to content

Commit

Permalink
fix: apply dll load macro to win32api
Browse files Browse the repository at this point in the history
  • Loading branch information
CristiFati committed Jun 24, 2024
1 parent a1cbfc3 commit bac97b8
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions win32/src/win32apimodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4778,10 +4778,7 @@ static PyObject *PySetSystemTime(PyObject *self, PyObject *args)
{
return ReturnAPIError("SetSystemTime");
}
else
{
return Py_BuildValue("i", result);
}
else { return Py_BuildValue("i", result); }
}

// @pymethod |win32api|SetThreadLocale|Sets the current thread's locale.
Expand Down Expand Up @@ -6263,18 +6260,13 @@ PYWIN_MODULE_INIT_FUNC(win32api)
PyModule_AddIntConstant(module, "VS_FF_PRIVATEBUILD", VS_FF_PRIVATEBUILD);
PyModule_AddIntConstant(module, "VS_FF_SPECIALBUILD", VS_FF_SPECIALBUILD);

HMODULE hmodule = GetModuleHandle(TEXT("secur32.dll"));
if (hmodule == NULL)
hmodule = LoadLibrary(TEXT("secur32.dll"));
if (hmodule != NULL) {
// clang-format off
PYWIN_BEGIN_LOAD_LIBRARY("secur32.dll")
pfnGetUserNameEx = (GetUserNameExfunc)GetProcAddress(hmodule, "GetUserNameExW");
pfnGetComputerObjectName = (GetUserNameExfunc)GetProcAddress(hmodule, "GetComputerObjectNameW");
}
PYWIN_END_LOAD_LIBRARY

hmodule = GetModuleHandle(TEXT("kernel32.dll"));
if (hmodule == NULL)
hmodule = LoadLibrary(TEXT("kernel32.dll"));
if (hmodule != NULL) {
PYWIN_BEGIN_LOAD_LIBRARY("kernel32.dll")
pfnGetComputerNameEx = (GetComputerNameExfunc)GetProcAddress(hmodule, "GetComputerNameExW");
pfnGetLongPathNameA = (GetLongPathNameAfunc)GetProcAddress(hmodule, "GetLongPathNameA");
pfnGetLongPathNameW = (GetLongPathNameWfunc)GetProcAddress(hmodule, "GetLongPathNameW");
Expand All @@ -6287,12 +6279,10 @@ PYWIN_MODULE_INIT_FUNC(win32api)
pfnSetDllDirectory = (SetDllDirectoryfunc)GetProcAddress(hmodule, "SetDllDirectoryW");
pfnSetSystemPowerState = (SetSystemPowerStatefunc)GetProcAddress(hmodule, "SetSystemPowerState");
pfnGetNativeSystemInfo = (GetNativeSystemInfofunc)GetProcAddress(hmodule, "GetNativeSystemInfo");
}
PYWIN_END_LOAD_LIBRARY


hmodule = GetModuleHandle(TEXT("user32.dll"));
if (hmodule == NULL)
hmodule = LoadLibrary(TEXT("user32.dll"));
if (hmodule != NULL) {
PYWIN_BEGIN_LOAD_LIBRARY("user32.dll")
pfnEnumDisplayMonitors = (EnumDisplayMonitorsfunc)GetProcAddress(hmodule, "EnumDisplayMonitors");
pfnEnumDisplayDevices = (EnumDisplayDevicesfunc)GetProcAddress(hmodule, "EnumDisplayDevicesW");
pfnChangeDisplaySettingsEx = (ChangeDisplaySettingsExfunc)GetProcAddress(hmodule, "ChangeDisplaySettingsExW");
Expand All @@ -6302,12 +6292,9 @@ PYWIN_MODULE_INIT_FUNC(win32api)
pfnGetMonitorInfo = (GetMonitorInfofunc)GetProcAddress(hmodule, "GetMonitorInfoW");
pfnEnumDisplaySettingsEx = (EnumDisplaySettingsExfunc)GetProcAddress(hmodule, "EnumDisplaySettingsExW");
pfnGetLastInputInfo = (GetLastInputInfofunc)GetProcAddress(hmodule, "GetLastInputInfo");
}
PYWIN_END_LOAD_LIBRARY

hmodule = GetModuleHandle(TEXT("Advapi32.dll"));
if (hmodule == NULL)
hmodule = LoadLibrary(TEXT("Advapi32.dll"));
if (hmodule != NULL) {
PYWIN_BEGIN_LOAD_LIBRARY("Advapi32.dll")
pfnRegRestoreKey = (RegRestoreKeyfunc)GetProcAddress(hmodule, "RegRestoreKeyW");
pfnRegSaveKeyEx = (RegSaveKeyExfunc)GetProcAddress(hmodule, "RegSaveKeyExW");
pfnRegCreateKeyTransacted = (RegCreateKeyTransactedfunc)GetProcAddress(hmodule, "RegCreateKeyTransactedW");
Expand All @@ -6318,7 +6305,8 @@ PYWIN_MODULE_INIT_FUNC(win32api)
pfnRegDeleteTree = (RegDeleteTreefunc)GetProcAddress(hmodule, "RegDeleteTreeW");
pfnRegOpenCurrentUser = (RegOpenCurrentUserfunc)GetProcAddress(hmodule, "RegOpenCurrentUser");
pfnRegOverridePredefKey = (RegOverridePredefKeyfunc)GetProcAddress(hmodule, "RegOverridePredefKey");
}
PYWIN_END_LOAD_LIBRARY
// clang-format on

PYWIN_MODULE_INIT_RETURN_SUCCESS;
}

0 comments on commit bac97b8

Please sign in to comment.