LoadLibrary is failing with module not found error -- possible dependency problems

17,943

Solution 1

Well I solved my problem, and unfortunately it's a fairly obvious solution. I added the directory that contained my dll to the PATH variable. Apparently dlls don't look in their own directory for their dependencies.

Solution 2

Can you debug into the DllMain of the other dll? If yes you could check directly in the debugger. With Windbg you can break on module load so you can single step what happens. Do you link directly against the lib of the dll? If not you could try to do so to check what error message the OS will show you. If it is 0xC0000142 then DllMain did return false. If it is 0xC0000022 then the executable or one of the dependant dlls do not have execute rights. You code 126 is simply Module not found which seems to tell the whole story. You could set the PATH variable to the directory by hand to the location of the missing dll. Do you deploy the dll to some other machine? If yes it could be that you are linking against the debug C-Runtime which is not installed on normal machines.

Yours, Alois Kraus

Share:
17,943
Ash
Author by

Ash

I'm an entry level C++ developer.

Updated on June 04, 2022

Comments

  • Ash
    Ash almost 2 years

    I have been trying to load a 32-bit dll using C++ (from a 32-bit application, on windows 7 64-bit). LoadLibrary returns NULL, and GetLastError returns 126 for "The specified module could not be found."

    I am passing in the complete address to the LoadLibrary function. I opened the dll in Dependency Walker, which said GPSVC.dll was a missing dependency.

    From the googling I've done, it looks like Dependency Walker often falsely shows this GPSVC.dll as a missing dependency, and there is no 32-bit version of the it, so I don't think that that's the actual problem.

    I haven't done too much finagling with dlls in the past, so hopefully it's a relatively simple problem that I can learn from.

    Thanks in advance for any help!

  • Jim Mischel
    Jim Mischel about 13 years
    That works, but isn't secure. See the "Security Remarks" at msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx. Also look at msdn.microsoft.com/en-us/library/ms682586(v=VS.85).aspx.