简体   繁体   中英

How to debug the code inside the DLL

I have a C# program from which I am calling some functions/variables from C++. The C++ program itself runs fine, and is checked. But, when I build this DLL and use it for C#, there is some bug in the interfacing code that is preventing me to get the correct result in C#.

Most probably, there is some error in export variables/exported functions giving out the results, which I want to check.

My primary question is : How do I debug this DLL, as in by putting breakpoints etc. and following along by seeing the results as we could do for any other program?

如果要调试DLL,则应在C ++环境中工作,在c ++代码中放置断点,但使用c#生成的可执行文件。

Assuming you have source code and debug symbols for the native (C++) DLL, you can check the "Enable unmanaged code debugging" option on the "Debug" tab of the managed (C#) EXE project, and then set breakpoints, inspect variables etc. in the C++ code as usual. You can add the C++ project to the solution, or just open a single C++ source code file and set breakpoints there.

The best way to debug this kind of scenario, is by either using Visual Studio mixed mode debugging (via devenv /debugexe yourapp.name.exe command) or using Windbg + SOS extension (steeper learning curve, but this would show a lot more information, like you type sizes in native and managed code) To learn how to use Windbg + SOS, please see Advanced .NET Debugging by Mario Hewardt

Note, that often these kind of issues are caused by 1) Incorrectly chosen C# data type to use with C++ APIs 2) Incorrectly specified / unspecified function calling convention http://blogs.msdn.com/b/adam_nathan/archive/2003/05/21/56690.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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