user888270
user888270

Reputation: 631

LoadLibrary never returning in visual studio 2013 c++ project

I have written a static library which depends on 3 librarys a.lib, b.lib, c.dll. Now i have written a test project and it works fine with this project. But there is another project which includes this static library in one of its dll say x.dll and later use this dll in project.

Now when project tries to load x.dll using LoadLibrary it never returns and keep on waiting. I have kept c.dll b.lib and a.lib all at the same location still its unable to load. Tried using dependency walker but cant see much differnce with before and after including this library.

How should i go about identifying the problem? Can i by any chance include every dependency in .lib? I felt since its the static library it should include all the dependencies in itself. thanks in advance for your help. The project is visual c++ in visual studio 2013.

Upvotes: 1

Views: 384

Answers (1)

Keyu Gan
Keyu Gan

Reputation: 711

LoadLibrary calls DllMain() of a DLL file. It is like a main() for DLL. There must be something deadlocked in DllMain.

Note: Sometimes there's no DllMain in DLL's code, but the compiler would automatically create one for initializing global variables with constructors, which could also lead to the problem.

To clarify, you could use LoadLibraryEx with DONT_RESOLVE_DLL_REFERENCES set. The flag will disable DllMain and disable loading dependencies. If it succeeds, the problem is in DllMain. (But you cannot use the DLL now, almost all modern DLLs behave incorretly without DllMain)

To debug, you could breakpoint on Ntdll.LdrpCallInitRoutine, DllMain() is called in this function.

Upvotes: 1

Related Questions