"Fossies" - the Fresh Open Source Software Archive

Member "node-v12.18.4-win-x64/node_modules/npm/node_modules/node-gyp/src/win_delay_load_hook.cc" (14 Feb 2020, 911 Bytes) of package /windows/www/node-v12.18.4-win-x64.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 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 
   23 static 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 
   35 decltype(__pfnDliNotifyHook2) __pfnDliNotifyHook2 = load_exe_hook;
   36 
   37 #pragma managed(pop)
   38 
   39 #endif