Replace dynamic loading of always-present Win10 APIs with static linking
Historical reference only:
stale-v0.72a-experimental-cleanandanalysis\stale-v0.72a-experimental-cleanare retired reference sources, not active branch targets or current baselines. Use them only as provenance or idea-extraction sources; landed status is determined againstmain. See Historical References.
Summary¶
Several Win10-always-present APIs are loaded dynamically via GetProcAddress
as a relic of Win9x/XP compatibility. Since the project targets Win10+ only,
these can be called directly via their normal headers and import libraries,
removing the boilerplate LoadLibrary/GetProcAddress/FreeLibrary chains.
Landed — 2026-04-19¶
Landed on main in commit 6ae47ec (REF-020: remove dead Win10 compatibility paths).
The final scope was slightly broader than the original wrapper-only draft:
- removed the dead DEP runtime setup entirely on the Win10+ baseline
- replaced the heap, DWM, known-folder, message-filter, and crash-dump dynamic probes with direct Win10-era behavior
- simplified
DetectWinVersion()to return the supported Win10 baseline instead of probingRtlGetVersion - removed obsolete Win10-always-present
DelayLoadDLLsentries and the related stale GDI+ linker comments
Revalidation — 2026-04-13¶
Current main still has 10 LoadLibrary sites and 21 GetProcAddress sites in
srchybrid, but only a subset are compatibility debt. Dynamic loads for optional
modules such as MediaInfo, UnRAR, and language DLLs are still legitimate.
The Win10-always-present cleanup subset still live in current main is:
Emule.cpp:181-182—GetProcessDEPPolicy/SetProcessDEPPolicyEmule.cpp:269—HeapSetInformationEmuleDlg.cpp:382—ChangeWindowMessageFilterEmuleDlg.cpp:3907-3914—DwmGetColorizationColorPreferences.cpp:2976—SHGetKnownFolderPathPreferences.cpp:3181-3186—DwmIsCompositionEnabledMdump.cpp:65-71—MiniDumpWriteDump
Items¶
DWM functions (EmuleDlg.cpp, Preferences.cpp)¶
// EmuleDlg.cpp:334 / Preferences.cpp:2818 — pattern:
HMODULE hDwmApi = LoadLibrary(_T("dwmapi.dll"));
if (hDwmApi) {
typedef HRESULT (WINAPI *PFN_DwmIsCompositionEnabled)(BOOL*);
auto pfn = (PFN_DwmIsCompositionEnabled)GetProcAddress(hDwmApi, "DwmIsCompositionEnabled");
if (pfn) pfn(&bEnabled);
FreeLibrary(hDwmApi);
}
On Win10, DwmIsCompositionEnabled always returns TRUE and DwmGetColorizationColor
is always available. Replace with:
#include <dwmapi.h>
// link: dwmapi.lib
BOOL bEnabled = TRUE; // always true on Win10; or call directly:
DwmIsCompositionEnabled(&bEnabled);
Add dwmapi.lib to the linker inputs if not already present.
SHGetKnownFolderPath (Preferences.cpp)¶
// Dynamic load pattern for SHGetKnownFolderPath
HMODULE hShell32 = LoadLibrary(_T("shell32.dll"));
// ... GetProcAddress("SHGetKnownFolderPath") ...
SHGetKnownFolderPath is in shell32.dll which is always loaded on Win10.
Replace with direct call:
#include <shlobj.h>
// link: shell32.lib (already linked)
PWSTR pszPath = nullptr;
SHGetKnownFolderPath(FOLDERID_..., 0, nullptr, &pszPath);
MiniDumpWriteDump (Mdump.cpp:65-71)¶
// Mdump.cpp:66-72 — loads dbghelp.dll dynamically:
HMODULE hDbgHelp = LoadLibrary(_T("dbghelp.dll"));
typedef BOOL (WINAPI *MiniDumpWriteDumpFn)(...);
auto pfn = (MiniDumpWriteDumpFn)GetProcAddress(hDbgHelp, "MiniDumpWriteDump");
dbghelp.dll ships with Windows and is always available on Win10+. For crash
dump generation it is acceptable to link statically:
#include <dbghelp.h>
#pragma comment(lib, "dbghelp.lib")
MiniDumpWriteDump(hProcess, processId, hFile, type, pExceptionParam, nullptr, nullptr);
Note: if side-by-side dbghelp.dll (from Debugging Tools) is desired, keep
the dynamic load but simplify the null-check logic.
Files to Modify¶
| File | Change |
|---|---|
srchybrid/Emule.cpp |
Replace DEP / heap hardening GetProcAddress wrappers |
srchybrid/EmuleDlg.cpp |
Replace ChangeWindowMessageFilter and DWM dynamic loads |
srchybrid/Preferences.cpp |
Replace DWM dynamic load and SHGetKnownFolderPath wrapper |
srchybrid/Mdump.cpp |
Replace MiniDumpWriteDump dynamic load |
Project linker settings (.vcxproj or CMakeLists) |
Add dwmapi.lib, dbghelp.lib if missing |
Acceptance Criteria¶
- [x] No
LoadLibrary(_T("dwmapi.dll"))in the codebase - [x] No
GetProcAddresswrappers forHeapSetInformation,ChangeWindowMessageFilter,SHGetKnownFolderPath, orMiniDumpWriteDump - [x] Dead DEP runtime setup removed instead of preserved as a direct-call path
- [x]
Mdump.cpplinksdbghelp.libstatically - [x]
dwmapi.libanddbghelp.libare linked directly - [x] Win10-always-present
DelayLoadDLLsentries were removed from the app project
Experimental Reference Implementation¶
Status in stale-v0.72a-experimental-clean: Done in commit b9f4cfa (REFAC: statically link always-present Win10 APIs). Key changes:
- Emule.cpp: GetProcessDEPPolicy / SetProcessDEPPolicy — function pointers and GetProcAddress chains removed; SetProcessDEPPolicy(PROCESS_DEP_ENABLE) called directly (it is a Win7+ API, always present on Win10)
- Emule.cpp: HeapSetInformation — GetProcAddress removed; ::HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0) called directly
- EmuleDlg.cpp: ChangeWindowMessageFilter — GetProcAddress boilerplate replaced with direct call; LoadLibrary("dwmapi.dll") + DwmGetColorizationColor dynamic load replaced with direct include + static link
- Mdump.cpp: MiniDumpWriteDump already static-linked in experimental
- MediaInfo_DLL.cpp: MediaInfo DLL loading moved to a dedicated loader class (MediaInfo_DLL.cpp) with cleaner probe-and-validate logic
Porting note: The Emule.cpp changes are ~20-line reductions of boilerplate. EmuleDlg.cpp DWM change adds #include <dwmapi.h> and removes LoadLibrary; verify dwmapi.lib is in linker inputs (it is in the current .vcxproj via project defaults).