Click here to Skip to main content
13,198,068 members (50,069 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


6 bookmarked
Posted 8 Apr 2009

Break Application on DLL Load

, 8 Apr 2009
Rate this:
Please Sign up or sign in to vote.
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)


About the Author

Software Developer (Senior)
Singapore Singapore
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171020.1 | Last Updated 8 Apr 2009
Article Copyright 2009 by Naveen
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid