简体   繁体   中英

unmanaged c++ dll called from c#, crashes when CString used in dll

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM