有什么方法可以调试从C#DllImport调用的c ++ dll? [英] Is there any way to debug c++ dll called from C# DllImport?
问题描述
我想知道是否有任何方法可以调试在VS 2010中从C#PInvoke调用的c ++ dll.我试图将项目附加到c#应用程序中,但没有用-并没有在断点处停止.
I wonder if there is any way to debug c++ dll called from C# PInvoke in VS 2010. I tried to attach the project into c# application but it didn't work - didn't stop at a break point.
我还尝试在C ++项目中使用OutputDebugString记录任何内容,但没有通过PInvoke调用打印任何内容.尽管存在这些问题,但实际功能运行良好.
I also tried to record anything with OutputDebugString in C++ project but nothing printed with PInvoke call. Despite these issues, the actual function runs well.
任何建议将不胜感激.
推荐答案
两者都需要打开相同的选项:项目">属性">调试"选项卡>选中启用非托管代码调试"选项.
Both require turning on the same option: Project > Properties > Debug tab > tick the "Enable unmanaged code debugging" option.
您现在可以在本机DLL代码中设置一个断点,一旦C#项目加载DLL,它就会从空心变为实心.由于使用了非托管调试引擎,因此OutputDebugString()的输出将进入输出"窗口.
You can now set a breakpoint in the native DLL code, it will turn from hollow to solid as soon as the C# project loads the DLL. And OutputDebugString() output will go to the Output window thanks to the unmanaged debugging engine being used.
这篇关于有什么方法可以调试从C#DllImport调用的c ++ dll?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!