0

My app loads several user plugins while starting using the LoadLibrary function.

_handle = LoadLibrary(fileName);
if (! _handle)
{
    printf("GetLastError: %d\n", GetLastError());
    return false;
}

return true;

Until now, it works. Since few days, despite the fileName is valid, the LoadLibrary function fails and GetLastError returns 6 (ERROR_INVALID_HANDLE).

This behavior is not systematic. Sometime the LoadLibrary function succeed.

Any ideas on how to debug this and find why my app cannot loads the plugins ?

  • 3
    What's in `fileName`? If it's just a filename (without a path), does your app always have the same current directory? – Jonathan Potter Jan 09 '18 at 09:37
  • *how to debug ?*- set `LdrpDebugFlags` to `0xFFFFFFBF` and look debug output. also what `RtlGetLastNtStatus()` return ? this is more informative compare `GetLastError()` - many status codes converted to the same win32 error. – RbMm Jan 09 '18 at 09:56
  • Probably the issue is in DllMain of the dll or one of its dependencies – David Heffernan Jan 09 '18 at 10:02
  • @DavidHeffernan - but in this case must be `ERROR_DLL_INIT_FAILED` error. the `ERROR_INVALID_HANDLE` (if this is true) very unsual – RbMm Jan 09 '18 at 10:05
  • Thanks for the advises. The file name given to the LoadLibrary function is an absolute file name. I tried using LdrpDebugFlags (using gflags.exe) and the error has changed. It is now ERROR_MOD_NOT_FOUND. The code in the issue is simplified version. In fact, the file name (that is already an absolute file name) is re-resolved before loading the DLL. This re-resolve transform it to the empty string. As usual the error is not where I looked first. – Lionel Lagarde Jan 09 '18 at 12:23
  • 1
    *and the error has changed. It is now `ERROR_MOD_NOT_FOUND`* - not think. think error all time was `ERROR_MOD_NOT_FOUND` – RbMm Jan 09 '18 at 13:00
  • Does this answer your question? [LoadLibraryExW() fails, last error is ERROR\_MOD\_NOT\_FOUND, but no missing dependencies?](https://stackoverflow.com/questions/16700810/loadlibraryexw-fails-last-error-is-error-mod-not-found-but-no-missing-depend) – GuidedHacking Jun 10 '20 at 19:45

0 Answers0