UNPKG

872 Btext/x-cView Raw
1/*
2 * When this file is linked to a DLL, it sets up a delay-load hook that
3 * intervenes when the DLL is trying to load the host executable
4 * dynamically. Instead of trying to locate the .exe file it'll just
5 * return a handle to the process image.
6 *
7 * This allows compiled addons to work when the host executable is renamed.
8 */
9
10#ifdef _MSC_VER
11
12#pragma managed(push, off)
13
14#ifndef WIN32_LEAN_AND_MEAN
15#define WIN32_LEAN_AND_MEAN
16#endif
17
18#include <windows.h>
19
20#include <delayimp.h>
21#include <string.h>
22
23static FARPROC WINAPI load_exe_hook(unsigned int event, DelayLoadInfo* info) {
24 HMODULE m;
25 if (event != dliNotePreLoadLibrary)
26 return NULL;
27
28 if (_stricmp(info->szDll, HOST_BINARY) != 0)
29 return NULL;
30
31 m = GetModuleHandle(NULL);
32 return (FARPROC) m;
33}
34
35decltype(__pfnDliNotifyHook2) __pfnDliNotifyHook2 = load_exe_hook;
36
37#pragma managed(pop)
38
39#endif