"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/node-gyp/src/win_delay_load_hook.cc" (8 Mar 2017, 875 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    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