非托管 c++从 C# 调用的 dll,在 dll 中使用 CString 时崩溃
你好最优秀的Stackoverflowians
使用Visual Studio 2008 Team System,
我有一个C++ DLL(MFC静态链接的常规DLL),它有一个简单的函数
extern "C" __declspec(dllexport) int MyExportedFunction( )
{
AFX_MANAGE_STATE(AfxGetStaticModuleState( ))
CString tempString ;
....
}
DLLImport从C#应用程序到DLL工作,我可以从我的C#调试器进入这个函数代码 然而(是的,它来了!) 在函数“MyExportedFunction”内部,如您所见,我实例化了一个 CString,当这个 CString 实例化被击中时,整个应用程序崩溃 调试器给我
“无法单步执行。进程已终止” 在尝试另一个附加之前刷新进程列表”
有人对我可以解决此问题有什么建议?
是否 嗡嗡声
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MFC 程序需要一个 CWinApp 对象实例 theApp,用于管理新建和删除。
MFC 常规 DLL 定义自己的 theApp 对象,而 MFC 扩展 DLL 使用另一个模块的“theApp”。
我认为您的崩溃与丢失/未初始化的“theApp”一致。如果是这种情况,内存分配将会失败,CString 使用内存分配。
两种可能性:
您可以从以下位置调用 MFC 扩展 DLL
。网。 (扩展 DLL 不
提供它自己的应用程序)
您调用常规 MFC DLL,其中 theApp 对象未正确初始化。
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.