73b088f7aea3a51efd45c9272496c0feda636de22e714d4d3092530d01d53d7fb0cdf2e6f29157b2f3d0e43713f56dc17bb1a4f2353ae53fbff46f4c5ec962 997 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. #ifdef _MSC_VER
  10. #pragma managed(push, off)
  11. #ifndef WIN32_LEAN_AND_MEAN
  12. #define WIN32_LEAN_AND_MEAN
  13. #endif
  14. #include <windows.h>
  15. #include <delayimp.h>
  16. #include <string.h>
  17. static FARPROC WINAPI load_exe_hook(unsigned int event, DelayLoadInfo* info) {
  18. HMODULE m;
  19. if (event != dliNotePreLoadLibrary)
  20. return NULL;
  21. if (_stricmp(info->szDll, HOST_BINARY) != 0)
  22. return NULL;
  23. // try for libnode.dll to compat node.js that using 'vcbuild.bat dll'
  24. m = GetModuleHandle("libnode.dll");
  25. if (m == NULL) m = GetModuleHandle(NULL);
  26. return (FARPROC) m;
  27. }
  28. decltype(__pfnDliNotifyHook2) __pfnDliNotifyHook2 = load_exe_hook;
  29. #pragma managed(pop)
  30. #endif