Click here to Skip to main content
15,614,943 members
Articles / Programming Languages / C++
Posted 8 Apr 2009

Tagged as


6 bookmarked

Break Application on DLL Load

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
8 Apr 2009CPOL1 min read
Break application on DLL load

What will you do if you encounter a crash in an application before it reaches the entry point ok EXE, i.e., the crash happens before the control reaches the WinMain. In such cases, the crash might have happened in the DLL loaded by the EXE. To be more specific, say in the DllMain() of DLLs. In most cases, we will not be having the source code of all DLLs so that we can put some breakpoint in the DllMain() and debug. So how to track which DLL is causing the problem...

The windows loader provides an option to break the debugee while loading DLLs. For this, we have to set appropriate values under "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options" key.

Suppose I have an application which has dependency with "Foo.dll" and I want the bebugger to break just before loading "Foo.dll". To do so, create a key under the "Image File Execution Options" like:

"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\Foo.dll".

Add a DWORD value under this key with name "BreakOnDllLoad" and set its value as one.

Now if you start the application from the debugger. The debugger will report a breakpoint hit during startup. This break point will be just above the call to DLL entry point of foo.dll. (The entry point is _DllMainCRTStartup if the DLL is written using VC++. This function later calls DllMain()).


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer (Senior)
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

-- There are no messages in this forum --