如何调试用C#中使用的Native C ++编写的dll [英] How to debug into a dll written in Native C++ Used in C#
问题描述
我正在使用Native C ++编写程序作为dll,使用C ++ CLI作为包装器,使用C#编写UI。当我在调试模式下构建它时,它工作正常,但在发布模式下它会抛出一个访问异常。更糟糕的是,当我从C#代码调试它时,我无法调试到CLI代码,更不用说Native C ++ DLL代码了。但程序抛出的异常表明dll中存在错误,我无法调试它。任何帮助?
可能会产生如下异常:
在C#中,我按下按钮A,然后在Native C ++ DLL中,有一个类A使用malloc来分配内存,而类B有一个256个字符的数组,而A类将动态分配内存来创建动态链接列表。第一次总是工作正常,按下按钮B后,删除A类和B类没有任何问题。当我再次按下按钮A时,A类和B类是使用new运算符创建的,没有任何问题,但是当我访问B类中的char数组时,程序抛出异常。如果我在A类中评论动态链接列表代码,则异常消失。所以我认为问题来自分配的内存。但是,我无法调试它。
任何帮助
我从这里得到了方法。 http ://stackoverflow.com/questions/57840/how-to-attach-debugger-to-step-into-native-c-code-from-a-managed-c-wrappe [ ^ ]
但我想修复异常,我正在尝试。
将Native C ++工作区作为启动项目。
在发布模式下,从项目 - >中禁用优化。属性 - >配置属性 - > C / C ++ - >优化
。
设置断点并按F5
。
当它要求时可执行文件,浏览到加载此DLL的EXE。
您好,
您应该使用WinDbg
快速启动使用WinDbg
i am writting a program using Native C++ as dll , C++ CLI as a wrapper and C# for the UI. When I build it in Debug mode, it works fine , but in Release mode it throws an Access Exception. what''s worse , when i debug it from C# code,i could not debug into the CLI code,much less the Native C++ DLL Code. But the exception throwed by the program showed that the error exists in the dll, i could not debug into it . Any help?
The exception may be produced like this:
In C# , i press button A, and then in Native C++ DLL , there is a class A uses malloc to allocate the memory and class B has an array of 256 chars and Class A will dynamic allocate the memory for creating a dynamic link list. The first time always works fine,after press button B,class A and Class B is deleted with out any problem. when i press Button A again.,The class A and Class B is created using new operator with out any problem, But when i access the char array in Class B, the program throws out the exception. If i commented dynamic link list code in class A , the exception gone. so i think the problem comes from the memory allocated . but , i could not debug into it.
Any help
I got the method from here.http://stackoverflow.com/questions/57840/how-to-attach-debugger-to-step-into-native-c-code-from-a-managed-c-wrappe[^]
but i want to fix the exception , i am trying .
Make the Native C++ workspace as the startup project.
In Release mode, disable optimization fromProject -> Properties -> Configuration Properties -> C/C++ -> Optimization
.
Set the break point and pressF5
.
When it asks for the executable, browse to the EXE that loads this DLL.
Hi,
you should use WinDbg
Quick-start-to-using-WinDbg
这篇关于如何调试用C#中使用的Native C ++编写的dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!