diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2022-01-05 13:20:09 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2022-01-05 13:12:00 +0100 |
commit | d75bf2c7703d6a741f04e4a3fc5a6180428f53b2 (patch) | |
tree | 58d4e9d1cee91463e08ac73e82f7549d78ee0614 /shell/source | |
parent | 9fb45044d93ffcaa63cfe3275c8fb5feb8c00504 (diff) |
tdf#146554: use GetModuleHandleExW instead of GetModuleHandleW
This allows to avoid use of module name when obtaining current module
handle, which needs to be synchronized and thus is error-prone.
Change-Id: I2f0e0af7f616c3582b0a3271cf9e06420a9dfc8e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127993
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'shell/source')
4 files changed, 23 insertions, 4 deletions
diff --git a/shell/source/win32/shlxthandler/propsheets/listviewbuilder.cxx b/shell/source/win32/shlxthandler/propsheets/listviewbuilder.cxx index 08beac81985c..5f0705c74d7a 100644 --- a/shell/source/win32/shlxthandler/propsheets/listviewbuilder.cxx +++ b/shell/source/win32/shlxthandler/propsheets/listviewbuilder.cxx @@ -22,6 +22,7 @@ #include "document_statistic.hxx" #include <utilities.hxx> #include <config.hxx> +#include <global.hxx> #include <commctrl.h> #include <resource.h> @@ -87,7 +88,7 @@ void list_view_builder::build(statistic_group_list_t& gl) void list_view_builder::setup_list_view() { HIMAGELIST h_ils = ImageList_Create(16,15,ILC_MASK, 7, 0); - HBITMAP h_bmp = LoadBitmapW(GetModuleHandleW(MODULE_NAME), MAKEINTRESOURCEW(IDB_PROPERTY_IMAGES)); + HBITMAP h_bmp = LoadBitmapW(GetCurrentModuleHandle(), MAKEINTRESOURCEW(IDB_PROPERTY_IMAGES)); ImageList_AddMasked(h_ils, h_bmp, RGB(255, 0, 255)); (void) ListView_SetImageList(hwnd_list_view_, h_ils, LVSIL_SMALL); diff --git a/shell/source/win32/shlxthandler/propsheets/propsheets.cxx b/shell/source/win32/shlxthandler/propsheets/propsheets.cxx index 218b921332a0..48a125d581fc 100644 --- a/shell/source/win32/shlxthandler/propsheets/propsheets.cxx +++ b/shell/source/win32/shlxthandler/propsheets/propsheets.cxx @@ -171,7 +171,7 @@ HRESULT STDMETHODCALLTYPE CPropertySheet::AddPages(LPFNSVADDPROPSHEETPAGE lpfnAd // add the summary property page psp.dwSize = sizeof(psp); psp.dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USECALLBACK; - psp.hInstance = GetModuleHandleW(MODULE_NAME); + psp.hInstance = GetCurrentModuleHandle(); psp.lParam = reinterpret_cast<LPARAM>(this); psp.pfnCallback = reinterpret_cast<LPFNPSPCALLBACKW>(CPropertySheet::PropPageSummaryCallback); diff --git a/shell/source/win32/shlxthandler/shlxthdl.cxx b/shell/source/win32/shlxthandler/shlxthdl.cxx index 6383cc2f60c0..9a5b8a37917c 100644 --- a/shell/source/win32/shlxthandler/shlxthdl.cxx +++ b/shell/source/win32/shlxthandler/shlxthdl.cxx @@ -303,7 +303,7 @@ STDAPI DllRegisterServer() WCHAR ModuleFileName[MAX_PATH]; GetModuleFileNameW( - GetModuleHandleW(MODULE_NAME), + GetCurrentModuleHandle(), ModuleFileName, sizeof(ModuleFileName)/sizeof(ModuleFileName[0])); diff --git a/shell/source/win32/shlxthandler/util/utilities.cxx b/shell/source/win32/shlxthandler/util/utilities.cxx index 489474b53baf..27bf12c211c7 100644 --- a/shell/source/win32/shlxthandler/util/utilities.cxx +++ b/shell/source/win32/shlxthandler/util/utilities.cxx @@ -22,6 +22,7 @@ #include <memory> #include <config.hxx> +#include <global.hxx> #include <utilities.hxx> // constants @@ -81,7 +82,7 @@ std::wstring GetResString(int ResId) { wchar_t szResStr[MAX_RES_STRING]; - int rc = LoadStringW( GetModuleHandleW(MODULE_NAME), ResId, szResStr, sizeof(szResStr) ); + int rc = LoadStringW( GetCurrentModuleHandle(), ResId, szResStr, sizeof(szResStr) ); OutputDebugStringFormatW( L"GetResString: read %d chars\n", rc ); // OSL_ENSURE(rc, "String resource not found"); @@ -544,4 +545,21 @@ LCID LocaleSetToLCID( const LocaleSet_t & Locale ) return MAKELCID( MAKELANGID( usPrimaryLang, usSubLang ), SORT_DEFAULT ); } +// The function is defined in the static library, and thus its address is local to current module +HMODULE GetCurrentModuleHandle() +{ + HMODULE h{}; + + if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS + | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + reinterpret_cast<LPCWSTR>(&GetCurrentModuleHandle), &h) + == 0) + { + const DWORD dwError = GetLastError(); + OutputDebugStringFormatW( + L"GetCurrentModuleHandle: GetModuleHandleExW failed, error is 0x%X", dwError); + } + return h; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |