简体   繁体   English

从c#调用的非托管c ++ dll在dll中使用CString时崩溃

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

Hello Most excellent Stackoverflowians 您好最优秀的Stackoverflowians

Using visual studio 2008 Team System, 使用Visual Studio 2008团队系统,

I have a c++ dll (mfc statically linked regular dll) which has a simple function 我有一个C ++ dll(mfc静态链接的常规dll),它具有简单的功能

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 从c#应用程序到dll的DLLImport可以正常工作,我可以从c#代码的调试器中进入此函数。但是(是的,它来了!)在函数“ MyExportedFunction”内,如您所见,我实例化了一个CString,然后这个CString实例被击中了整个应用程序崩溃,调试器给了我

"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程序定义了一个CWinApp对象实例TheApp,用于管理新对象和删除对象。

MFC regular DLLs defines their own theApp object, while MFC extension DLLs uses another module 's "theApp". MFC常规DLL定义了它们自己的theApp对象,而MFC扩展DLL使用了另一个模块的“ theApp”。

I think your crash is consistent with a missing/non-initialized "theApp". 我认为您的崩溃与丢失的/未初始化的“ theApp”一致。 If this is the case memory allocation will fail and CString uses memory allocation. 如果是这种情况,内存分配将失败并且CString使用内存分配。

Two posibilities: 两种可能性:

  • You call an MFC extension DLL from .NET. 您从.NET调用MFC扩展DLL。 (the extension DLL does not provide it's own theApp) (扩展DLL不提供它自己的theApp)

  • You call a regular MFC DLL, where the theApp object is not initialized properly. 您调用一个常规的MFC DLL,其中theApp对象未正确初始化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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