LoadLibrary does not work with module error - possible dependency problems

I am 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 pass the full address of the LoadLibrary function. I opened the DLL in Dependency Walker, which said GPSVC.dll is a missing dependency.

From googling, which I did, it seems that Dependency Walker often mistakenly shows this GPSVC.dll file as a missing dependency, and there is no 32-bit version of it, so I don't think the actual problem.

I have not done too many finalists with dlls in the past, so hopefully this is a relatively simple problem that I can learn about.

Thanks in advance for your help!

+4
source share
2 answers

Well, I solved my problem, and unfortunately this is a pretty obvious solution. I added the directory containing my dll to the PATH variable. Apparently dlls don't look in their directory for their dependencies.

+3
source

Is it possible to debug in DllMain from another dll? If so, you can check directly in the debugger. With Windbg, you can break the load on the module so you can take one step what happens. Are you directly linking to the dll library lib? If not, you can try to do this to check which error message the OS shows you. If it is 0xC0000142, then DllMain will return false. If it is 0xC0000022, then the executable file or one of the dependent dlls do not have execute rights. You code 126 is just a module that is not found, which seems to tell the whole story. You can manually set the PATH variable to a directory manually at the address of the missing dll. Do you deploy dll on any other machine? If so, maybe you are linking a debugged C-Runtime that is not installed on regular machines.

Regards, Alois Kraus

+1
source

Source: https://habr.com/ru/post/1339903/


All Articles