在 C# 中调试 C++ dll

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1062910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 07:19:56  来源:igfitidea点击:

Debug c++ dll in C#

c#c++debuggingdllexe

提问by

I have a .dll from c++ and I want to debug it in C#, but I don't know how to.

我有一个来自 c++ 的 .dll,我想在 C# 中调试它,但我不知道如何。

When I compiled the c++ project, Visual studio asked me to execute an ".exe".

当我编译 c++ 项目时,Visual Studio 要求我执行一个“.exe”。

I supposed that I had to create a project to execute the dll.

我想我必须创建一个项目来执行 dll。

But I am lost, how could I debug it?

但是我迷路了,我怎么调试呢?

回答by JohnIdol

Visual Studio cannot execute a dll on its own.

Visual Studio 无法自行执行 dll。

You need to set the startup .exe that will be using your C++ dll in the properties of your dll project. You can do so from properties --> debugging --> commandspecifying the path of the executable that's gonna call your dll and any command line argument needed.

您需要在 dll 项目的属性中设置将使用 C++ dll 的启动 .exe。您可以从属性 --> 调试 --> 命令指定将调用您的 dll 的可执行文件的路径以及所需的任何命令行参数。

回答by CCicotta

If I understand you correctly, you want to debug a C++ coded DLL that you created, in a C# project that calls the DLL, which you also created?

如果我理解正确,您想在调用 DLL 的 C# 项目中调试您创建的 C++ 编码的 DLL,该 DLL 也是您创建的?

I've done this before by going into your C# project properties, and under the Debug section, checking the "Enable unmanaged code debugging" check box. This should allow you to step into your C++ DLL.

我之前通过进入 C# 项目属性并在“调试”部分下选中“启用非托管代码调试”复选框来完成此操作。这应该允许您进入您的 C++ DLL。

回答by heavyd

To debug a C++ from C# there a couple of things you have to do.

要从 C# 调试 C++,您必须做几件事。

  1. Add a C# project to you solution for your debug application.
  2. Edit the properties of the C# project to "Allow unmanaged code debugging" on the "Debug" tab of the project properties.
  3. Set the C++ project as a dependency of the C# project.
  4. Write code in your C# project to use the DLL either using P/Invoke or COM.
  5. Set some breakpoints in your C++ code and run the C# project.
  1. 将 C# 项目添加到调试应用程序的解决方案中。
  2. 在项目属性的“调试”选项卡上,将 C# 项目的属性编辑为“允许非托管代码调试”。
  3. 将 C++ 项目设置为 C# 项目的依赖项。
  4. 在 C# 项目中编写代码以使用 P/Invoke 或 COM 使用 DLL。
  5. 在 C++ 代码中设置一些断点并运行 C# 项目。

回答by Vivek chandra Joshi

SOS (Son of Strike) Debugging Extension (SOS.dll) helps you debug managed code in Visual Studio by providing information about the internal CLR environment

SOS (Son of Strike) 调试扩展 (SOS.dll) 通过提供有关内部 CLR 环境的信息来帮助您调试 Visual Studio 中的托管代码

refer the below article:-

请参阅以下文章:-

MSDN ARTICLE

MSDN文章

回答by user10044681

For VS 2017 Pro, go to the property page of the main project (your c# project in the solution) by right mouse clicking it. At the Debug menu item, find the option in Debugger engines, choose Enable native code debugging.

对于 VS 2017 Pro,通过鼠标右键单击它转到主项目(解决方案中的 c# 项目)的属性页面。在调试菜单项中,找到调试器引擎中的选项,选择启用本机代码调试。