diff options
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; |