diff options
author | George Hazan <ghazan@miranda.im> | 2018-07-31 17:51:37 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-07-31 17:51:37 +0300 |
commit | 2b6d90564fa3cf379cfd57dfbfdf4cf750e994b1 (patch) | |
tree | 42276091fc22e825eb1cf60f5c8fade8cfaa03e6 /build | |
parent | 29077096131fad5026780272a870a4a07bad76d2 (diff) |
exe loader extracted to the separate module, now it's possible to compile all exe using shared runtime modules
Diffstat (limited to 'build')
-rw-r--r-- | build/appstub/appstub.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/build/appstub/appstub.cpp b/build/appstub/appstub.cpp new file mode 100644 index 0000000000..67e4159c8e --- /dev/null +++ b/build/appstub/appstub.cpp @@ -0,0 +1,37 @@ +#include <Windows.h> + +#include <delayimp.h> +#pragma comment(lib, "delayimp.lib") + +static HANDLE hUcrtDll = nullptr; + +EXTERN_C HANDLE WINAPI hook(unsigned mode, PDelayLoadInfo) +{ + if (mode == dliNotePreLoadLibrary && hUcrtDll == nullptr) { + wchar_t wszPath[MAX_PATH]; + GetModuleFileNameW(nullptr, wszPath, _countof(wszPath)); + + // if current dir isn't set + for (int i = lstrlenW(wszPath); i >= 0; i--) + if (wszPath[i] == '\\') { + wszPath[i] = 0; + break; + } + + SetCurrentDirectoryW(wszPath); + + lstrcatW(wszPath, L"\\libs"); + SetDllDirectoryW(wszPath); + +#ifdef _DEBUG + lstrcatW(wszPath, L"\\ucrtbased.dll"); +#else + lstrcatW(wszPath, L"\\ucrtbase.dll"); +#endif + hUcrtDll = LoadLibraryW(wszPath); + } + + return 0; +} + +EXTERN_C const PfnDliHook __pfnDliNotifyHook2 = (PfnDliHook)&hook; |