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

Ash picture Ash · Feb 15, 2011 · Viewed 17.6k times · Source

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!

Answer

Ash picture Ash · Feb 15, 2011

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.