开发者

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开发者_StackOverflow社区 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜