diff options
author | Neil <nyamatongwe@gmail.com> | 2025-02-09 14:01:52 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2025-02-09 14:01:52 +1100 |
commit | aecf061792cbdafcf3600aa086baddb1632af317 (patch) | |
tree | a86b60679562f05e0bce3fcf0669f35425efdcdb | |
parent | 50d1e46ea7d6de76fc8d676888d9e14475fda04f (diff) | |
download | scintilla-mirror-aecf061792cbdafcf3600aa086baddb1632af317.tar.gz |
Standardize DLL freeing.
-rw-r--r-- | win32/PlatWin.cxx | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 30a066083..846dfedfe 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -76,8 +76,12 @@ IDWriteFactory *pIDWriteFactory = nullptr; ID2D1Factory *pD2DFactory = nullptr; D2D1_DRAW_TEXT_OPTIONS d2dDrawTextOptions = D2D1_DRAW_TEXT_OPTIONS_NONE; -static HMODULE hDLLD2D {}; -static HMODULE hDLLDWrite {}; +namespace { + +HMODULE hDLLD2D{}; +HMODULE hDLLDWrite{}; + +} void LoadD2DOnce() noexcept { DWORD loadLibraryFlags = 0; @@ -4149,24 +4153,26 @@ void Platform_Initialise(void *hInstance) noexcept { ListBoxX_Register(); } +namespace { + +void ReleaseLibrary(HMODULE &hLib) noexcept { + if (hLib) { + FreeLibrary(hLib); + hLib = {}; + } +} + +} + void Platform_Finalise(bool fromDllMain) noexcept { -#if defined(USE_D2D) if (!fromDllMain) { +#if defined(USE_D2D) ReleaseUnknown(pIDWriteFactory); ReleaseUnknown(pD2DFactory); - if (hDLLDWrite) { - FreeLibrary(hDLLDWrite); - hDLLDWrite = {}; - } - if (hDLLD2D) { - FreeLibrary(hDLLD2D); - hDLLD2D = {}; - } - } + ReleaseLibrary(hDLLDWrite); + ReleaseLibrary(hDLLD2D); #endif - if (!fromDllMain && hDLLShcore) { - FreeLibrary(hDLLShcore); - hDLLShcore = {}; + ReleaseLibrary(hDLLShcore); } ListBoxX_Unregister(); } |