Reputation: 133
I have large legacy C++ application (Visual Studio 2010), and I need to execute some code before a specific dll is loaded. The problem is the dll is getting loaded before I execute any code, so I'm trying to figure out what's triggering it to load.
I've specified /DELAYLOAD for the dll in the link options, which should stop the dll loading before it's needed. But it's still getting loaded before I execute any code. The application is MFC, so my entry point is an override of CWinApp::InitApplication().
I suspect it must be a global variable in the application that's referencing a type in the dll, but I'm not sure how to find the variable (the code base is large, and globals are not consistently named).
Any ideas how to find what's triggering the dll load, or how to find the global variable?
Upvotes: 3
Views: 772
Reputation: 133
I fixed the problem by setting a breakpoint on the delay-load helper function, __delayLoadHelper2
. This function can be found in:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\delayhlp.cpp
It's called when a dll marked for delay-load is loaded.
I set the breakpoint in __delayLoadHelper2
and viewed the call-stack when it was hit. This showed the function in my code that was triggering the dll-load.
It was triggered by a global singleton constructor, which created a type from the dll. This code gets executed before CWinApp::InitApplication()
.
Upvotes: 5