File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed
Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 11{
22 'target_defaults' : {
33 'type' : 'loadable_module' ,
4+ 'win_delay_load_hook' : 'false' ,
45 'product_prefix' : '' ,
6+
57 'include_dirs' : [
68 '<(node_root_dir)/src' ,
79 '<(node_root_dir)/deps/uv/include' ,
1315 'product_extension' : 'node' ,
1416 'defines' : [ 'BUILDING_NODE_EXTENSION' ],
1517 }],
18+
1619 ['_type=="static_library"' , {
1720 # set to `1` to *disable* the -T thin archive 'ld' flag.
1821 # older linkers don't support this flag.
1922 'standalone_static_library' : '<(standalone_static_library)'
2023 }],
24+
25+ ['_win_delay_load_hook=="true"' , {
26+ # If the addon specifies `'win_delay_load_hook': 'true'` in its
27+ # binding.gyp, link a delay-load hook into the DLL. This hook ensures
28+ # that the addon will work regardless of whether the node/iojs binary
29+ # is named node.exe, iojs.exe, or something else.
30+ 'conditions' : [
31+ [ 'OS=="win"' , {
32+ 'sources' : [
33+ 'src/win_delay_load_hook.c' ,
34+ ],
35+ 'msvs_settings' : {
36+ 'VCLinkerTool' : {
37+ 'DelayLoadDLLs' : [ 'iojs.exe' , 'node.exe' ],
38+ # Don't print a linker warning when no imports from either .exe
39+ # are used.
40+ 'AdditionalOptions' : [ '/ignore:4199' ],
41+ },
42+ },
43+ }],
44+ ],
45+ }],
2146 ],
2247
2348 'conditions' : [
Original file line number Diff line number Diff line change 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+ #define WIN32_LEAN_AND_MEAN
13+ #include <windows.h>
14+
15+ #include <delayimp.h>
16+ #include <string.h>
17+
18+ static FARPROC WINAPI load_exe_hook (unsigned int event , DelayLoadInfo * info ) {
19+ if (event != dliNotePreLoadLibrary )
20+ return NULL ;
21+
22+ if (_stricmp (info -> szDll , "iojs.exe" ) != 0 &&
23+ _stricmp (info -> szDll , "node.exe" ) != 0 )
24+ return NULL ;
25+
26+ HMODULE m = GetModuleHandle (NULL );
27+ return (FARPROC ) m ;
28+ }
29+
30+ PfnDliHook __pfnDliNotifyHook2 = load_exe_hook ;
31+
32+ #endif
You can’t perform that action at this time.
0 commit comments