Monday, June 14, 2010

How to fix : DoModal inside a DLL Crashes with VS2005 SP1

ISSUE :

I had been experiencing a strange crash in my application since I installed VS2005 SP1.

It was an MFC-based add-in (i.e. a DLL) for MS Excel which did a DoModal internally to show up a Dialog. When I debugged I saw that the culprit was the following code segment in dlgcore.cpp.

image Basically the AfxGetApp() returned NULL leading to an assertion fail.

FIX :

I inserted the code CWinApp theApp; in one of the source files in my DLL making a CWinApp-derived object available to the DLL. That solved my problem.

No comments: