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

Arsen Mkrtchyan
  • 49,896
  • 32
  • 148
  • 184
Buzz
  • 11
  • 3
  • It was a nightmare for me to compile my Managed C++ library that linked to a static lib using CString. I don't exactly remember but there was always a link error saying the CString is using the older version and a new version is already linked. Have you tried using std::string? – A9S6 Feb 11 '10 at 05:59
  • Copy and paste the last lines in the Output window into your post. – Hans Passant Feb 11 '10 at 06:37
  • The program '[2408] RoadSnappa.exe: Managed' has exited with code -1073741819 (0xc0000005). The program '[2408] RoadSnappa.exe: Native' has exited with code -1073741819 (0xc0000005). – Buzz Feb 12 '10 at 04:26

1 Answers1

1

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
  • 7,284
  • 5
  • 37
  • 41
  • hmm - well there is a constructor CorgarApp::CorgarApp() and it is getting called - i stuck a breakpoint in. Though it has no body. also CorgarApp::InitInstance is also getting called... and it just called "CWinApp::Initinstance" all of which was code generated automagically... Buzz – Buzz Feb 12 '10 at 03:29