Initial commit
[yaffs-website] / node_modules / node-gyp / src / win_delay_load_hook.cc
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 'node.exe' or 'iojs.exe'
4  * dynamically. Instead of trying to locate the .exe file it'll just return
5  * a handle to the process image.
6  *
7  * This allows compiled addons to work when node.exe or iojs.exe is renamed.
8  */
9
10 #ifdef _MSC_VER
11
12 #ifndef WIN32_LEAN_AND_MEAN
13 #define WIN32_LEAN_AND_MEAN
14 #endif
15
16 #include <windows.h>
17
18 #include <delayimp.h>
19 #include <string.h>
20
21 static FARPROC WINAPI load_exe_hook(unsigned int event, DelayLoadInfo* info) {
22   HMODULE m;
23   if (event != dliNotePreLoadLibrary)
24     return NULL;
25
26   if (_stricmp(info->szDll, "iojs.exe") != 0 &&
27       _stricmp(info->szDll, "node.exe") != 0)
28     return NULL;
29
30   m = GetModuleHandle(NULL);
31   return (FARPROC) m;
32 }
33
34 decltype(__pfnDliNotifyHook2) __pfnDliNotifyHook2 = load_exe_hook;
35
36 #endif