From ed1e4236ba8da73af8969c5ca0798b1700497746 Mon Sep 17 00:00:00 2001 From: Luca Bacci Date: Fri, 30 Dec 2022 16:42:02 +0100 Subject: [PATCH] Use GetModuleHandleW () Also fix an unwanted ref-count increment on a module HANDLE --- app/gui/gui-unique.c | 2 +- app/main.c | 6 +++--- libgimp/gimp.c | 6 +++--- modules/gimpinputdevicestore-dx.c | 7 ++++--- plug-ins/screenshot/screenshot-win32.c | 4 ++-- plug-ins/twain/tw_win.c | 4 ++-- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/gui/gui-unique.c b/app/gui/gui-unique.c index 1a5fede07f..e8707165ea 100644 --- a/app/gui/gui-unique.c +++ b/app/gui/gui-unique.c @@ -221,7 +221,7 @@ gui_unique_win32_init (Gimp *gimp) /* register window class for proxy window */ memset (&wc, 0, sizeof (wc)); - wc.hInstance = GetModuleHandle (NULL); + wc.hInstance = GetModuleHandleW (NULL); wc.lpfnWndProc = gui_unique_win32_message_handler; wc.lpszClassName = GIMP_UNIQUE_WIN32_WINDOW_CLASS; diff --git a/app/main.c b/app/main.c index e83a6cc2c0..54d12050e4 100644 --- a/app/main.c +++ b/app/main.c @@ -613,7 +613,7 @@ main (int argc, t_SetDllDirectoryA p_SetDllDirectoryA; p_SetDllDirectoryA = - (t_SetDllDirectoryA) GetProcAddress (GetModuleHandle ("kernel32.dll"), + (t_SetDllDirectoryA) GetProcAddress (GetModuleHandleW (L"kernel32.dll"), "SetDllDirectoryA"); if (p_SetDllDirectoryA) (*p_SetDllDirectoryA) (""); @@ -647,7 +647,7 @@ main (int argc, t_SetProcessDEPPolicy p_SetProcessDEPPolicy; p_SetProcessDEPPolicy = - (t_SetProcessDEPPolicy) GetProcAddress (GetModuleHandle ("kernel32.dll"), + (t_SetProcessDEPPolicy) GetProcAddress (GetModuleHandleW (L"kernel32.dll"), "SetProcessDEPPolicy"); if (p_SetProcessDEPPolicy) (*p_SetProcessDEPPolicy) (PROCESS_DEP_ENABLE|PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION); @@ -660,7 +660,7 @@ main (int argc, t_SetCurrentProcessExplicitAppUserModelID p_SetCurrentProcessExplicitAppUserModelID; p_SetCurrentProcessExplicitAppUserModelID = - (t_SetCurrentProcessExplicitAppUserModelID) GetProcAddress (GetModuleHandle ("shell32.dll"), + (t_SetCurrentProcessExplicitAppUserModelID) GetProcAddress (GetModuleHandleW (L"shell32.dll"), "SetCurrentProcessExplicitAppUserModelID"); if (p_SetCurrentProcessExplicitAppUserModelID) (*p_SetCurrentProcessExplicitAppUserModelID) (L"gimp.GimpApplication"); diff --git a/libgimp/gimp.c b/libgimp/gimp.c index 9aa67858a9..186ebcbe13 100644 --- a/libgimp/gimp.c +++ b/libgimp/gimp.c @@ -200,7 +200,7 @@ gimp_main (GType plug_in_type, typedef BOOL (WINAPI *t_SetDllDirectoryA) (LPCSTR lpPathName); t_SetDllDirectoryA p_SetDllDirectoryA; - p_SetDllDirectoryA = (t_SetDllDirectoryA) GetProcAddress (GetModuleHandle ("kernel32.dll"), + p_SetDllDirectoryA = (t_SetDllDirectoryA) GetProcAddress (GetModuleHandleW (L"kernel32.dll"), "SetDllDirectoryA"); if (p_SetDllDirectoryA) (*p_SetDllDirectoryA) (""); @@ -269,7 +269,7 @@ gimp_main (GType plug_in_type, typedef BOOL (WINAPI *t_SetProcessDEPPolicy) (DWORD dwFlags); t_SetProcessDEPPolicy p_SetProcessDEPPolicy; - p_SetProcessDEPPolicy = GetProcAddress (GetModuleHandle ("kernel32.dll"), + p_SetProcessDEPPolicy = GetProcAddress (GetModuleHandleW (L"kernel32.dll"), "SetProcessDEPPolicy"); if (p_SetProcessDEPPolicy) (*p_SetProcessDEPPolicy) (PROCESS_DEP_ENABLE|PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION); @@ -281,7 +281,7 @@ gimp_main (GType plug_in_type, typedef HRESULT (WINAPI *t_SetCurrentProcessExplicitAppUserModelID) (PCWSTR lpPathName); t_SetCurrentProcessExplicitAppUserModelID p_SetCurrentProcessExplicitAppUserModelID; - p_SetCurrentProcessExplicitAppUserModelID = (t_SetCurrentProcessExplicitAppUserModelID) GetProcAddress (GetModuleHandle ("shell32.dll"), + p_SetCurrentProcessExplicitAppUserModelID = (t_SetCurrentProcessExplicitAppUserModelID) GetProcAddress (GetModuleHandleW (L"shell32.dll"), "SetCurrentProcessExplicitAppUserModelID"); if (p_SetCurrentProcessExplicitAppUserModelID) (*p_SetCurrentProcessExplicitAppUserModelID) (L"gimp.GimpApplication"); diff --git a/modules/gimpinputdevicestore-dx.c b/modules/gimpinputdevicestore-dx.c index 6e389e44b4..7e7e210fab 100644 --- a/modules/gimpinputdevicestore-dx.c +++ b/modules/gimpinputdevicestore-dx.c @@ -204,9 +204,10 @@ gimp_input_device_store_init (GimpInputDeviceStore *store) gtk_list_store_set_column_types (GTK_LIST_STORE (store), G_N_ELEMENTS (types), types); - if (!GetModuleHandleEx (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, - (LPCTSTR) &gimp_input_device_store_init, - &thismodule)) + if (!GetModuleHandleExW (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | + GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + (LPCTSTR) &gimp_input_device_store_init, + &thismodule)) return; if ((store->window = create_aux_window (store)) == NULL) diff --git a/plug-ins/screenshot/screenshot-win32.c b/plug-ins/screenshot/screenshot-win32.c index 2c531ec099..a2b8c04ad3 100644 --- a/plug-ins/screenshot/screenshot-win32.c +++ b/plug-ins/screenshot/screenshot-win32.c @@ -790,7 +790,7 @@ doCaptureMagnificationAPI (HWND selectedHwnd, /* Create the host window that will store the mag child window */ hwndHost = CreateWindowEx (0x08000000 | 0x080000 | 0x80 | 0x20, APP_NAME, NULL, 0x80000000, - 0, 0, 0, 0, NULL, NULL, GetModuleHandle (NULL), NULL); + 0, 0, 0, 0, NULL, NULL, GetModuleHandleW (NULL), NULL); if (!hwndHost) { @@ -808,7 +808,7 @@ doCaptureMagnificationAPI (HWND selectedHwnd, hwndMag = CreateWindow (WC_MAGNIFIER, TEXT ("MagnifierWindow"), magStyles, 0, 0, round4Rect.right - round4Rect.left, round4Rect.bottom - round4Rect.top, - hwndHost, NULL, GetModuleHandle (NULL), NULL); + hwndHost, NULL, GetModuleHandleW (NULL), NULL); /* Set the callback function that will be called by the api to get the pixels */ if (!MagSetImageScalingCallback (hwndMag, (MagImageScalingCallback)doCaptureMagnificationAPI_callback)) diff --git a/plug-ins/twain/tw_win.c b/plug-ins/twain/tw_win.c index 84cc8437fa..9a0cd4a009 100644 --- a/plug-ins/twain/tw_win.c +++ b/plug-ins/twain/tw_win.c @@ -346,9 +346,9 @@ twainMain (void) pTW_SESSION twSession = initializeTwain(); /* Since we are not using our own WinMain anymore where we - could get hInst we get it here using GetModuleHandle. */ + could get hInst we get it here using GetModuleHandleW. */ if (!hInst) - hInst = GetModuleHandle(NULL); + hInst = GetModuleHandleW(NULL); /* Perform instance initialization */ if (!InitApplication(hInst))