views:

303

answers:

1

I have converted a mixed mode MFC application from VS2005 to VS2008. It is compiling OK but when starting the application I get an assert in afxwin1.inl because afxCurrentResourceHandle = NULL.

This is before MyCWinApp::InitInstance is called. The call stack is

mfc90d.dll->AfxWinInit (with HINSTANCE = NULL)
myapp.exe!InternalDllMain
myapp.exe!PostDllMain
myapp.exe!dynamic intilizer for postDllMain::A0x61ae6c8e

The same project in VS2005 starts up fine and I notice that instead of PostDllMain beeing called WinMainCRTStarup is being called and it gets a defined instance handle:

mfc80d.dll!AfxWinInit (with HINSTANCE = 0x0040000)
mfc80d.dll!AfxWinMain
myApp.exe!WinMain
myApp.exe!__tmainCRTStartup
myapp.exe!WinMainCRTStartup

The app is compiled with /clr and links to both managed, unmanaged and mixed libs and dlls.

Can anyone shed some light on this issue? Are there any known differences in this area between VS2005 and VS2008?

Thanks!

+1  A: 

I got a nice answer from Rong-Chun Zhang on the MSDN forum:

Hello,

I performed a test on my side, and I didn't reproduce the problem on my side. However, the call stack in Vsiaul Studio 2008 looks like it is a DLL, so I tried add the _USRDLL in the Proprocessor Definitions(/D "_USRDLL") of the project settings, I got the same assertion as you described. Please check if the project is compiled with "_USRDLL".

More information http://support.microsoft.com/kb/115088

Let me know if this helps, if not, could you please show us the command line of the project settings?

Thanks, Rong-Chun Zhang


This was right on the mark!

Turns out that one of the projects in my solution which is set up as a static lib had _USRDLL defined in its preprocessor definitions. Somehow this is discarded in VS2005 but VS2008 clearly does not like it.

Thank you mr. Zhang!