views:

166

answers:

1

Hello Most excellent Stackoverflowians

Using visual studio 2008 Team System,

I have a c++ dll (mfc statically linked regular dll) which has a simple function

extern "C" __declspec(dllexport) int MyExportedFunction( )
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState( ))

   CString tempString ;
....
}

The DLLImport from the c# application tothe dll works and i can step inside this function from the debugger from my c# code However (yes here it comes!) inside the function "MyExportedFunction" , as you can see i instantiate a CString, and w hen this CString instantiation is hit the whole app crashes and the debugger gives me

"Unable to step. the process has been terminated refresh the process list before attempting another attach"

does anyone have any suggestions as to what i might to do fix this problems?

regards Buzz

+1  A: 

MFC programs ned an CWinApp object instance, theApp, that manages new and delete.

MFC regular DLLs defines their own theApp object, while MFC extension DLLs uses another module 's "theApp".

I think your crash is consistent with a missing/non-initialized "theApp". If this is the case memory allocation will fail and CString uses memory allocation.

Two posibilities:

  • You call an MFC extension DLL from .NET. (the extension DLL does not provide it's own theApp)

  • You call a regular MFC DLL, where the theApp object is not initialized properly.

Arve
hmm - well there is a constructor CorgarApp::CorgarApp()and it is getting called - i stuck a breakpoint in.Though it has no body.alsoCorgarApp::InitInstance is also getting called...and it just called "CWinApp::Initinstance"all of which was code generated automagically...Buzz
Buzz