简体   繁体   English

如何从c#项目调试c ++ dll?

[英]How to debug the c++ dll from c# project?

I have created a visual c++ 6.0 dll project and using it from my c# code. 我创建了一个visual c++ 6.0 dll项目,并使用我的c#代码。 Now i want to debug the dll but i am not able to do it. 现在我想调试dll但我无法做到。

I choose the following option to do it: 我选择以下选项来执行此操作:

  • put the breaking point in my visual c++ project code. 把断点放在我的visual c++项目代码中。
  • build the dll and copy it into the directory of my c# project. 构建dll并将其复制到我的c#项目目录中。
  • Now i build my c# project and dll works fine (method are calling perfectly). 现在我构建我的c#项目并且dll工作正常(方法调用完美)。
  • Now i want to debug the dll . 现在我想调试dll
  • I follow a blog and open the c++ project and choose the Attach to process from vc++ . 我按照博客打开c++项目,然后从vc++选择Attach to process
  • but i am not able to find the running process of visual c# project, whereas it available at task manager process. 但我无法找到visual c# project的运行过程,而在任务管理器进程中可以找到它。

In my c# project solution i have two project ie 在我的c#项目解决方案中,我有两个项目即

  • web service (i called the dll method at the time of accessing a url) Web服务(我在访问URL时调用了dll方法)
  • Another one is webform application which starts the web services. 另一个是启动Web服务的webform application

Now please help me how should i debug my dll. 现在请帮助我如何调试我的DLL。 I have followed so many blogs but all of them are focusing on Attaching process method which is not working in my condition. 我已经关注了很多博客,但他们都专注于Attaching process方法,这种方法在我的条件下无效。 What should i do? 我该怎么办?

You'll need to enable unmanaged debugging, it is not turned on by default in either scenario because your main program is managed. 您需要启用非托管调试,在任一情况下都不会打开它,因为您的主程序是受管理的。

You do it in your C# project with Project > Properties > Debug tab > tick the "Enable unmanaged code debugging" checkbox. 您可以在C#项目中使用Project> Properties> Debug选项卡>勾选“启用非托管代码调试”复选框。

You do it with Tools > Attach to Process by clicking the Select button. 您可以通过单击“选择”按钮,使用“工具”>“附加到进程”来执 Choose the "Debug these code types" radio button and tick both Managed and Native. 选择“调试这些代码类型”单选按钮并勾选Managed和Native。 You may have to resort to only native if your process is 64-bit. 如果您的进程是64位,则可能不得不求助于本机。

Set a breakpoint in the DLL's source code and be sure to write C# code that exercises the DLL function. 在DLL的源代码中设置断点,并确保编写运行DLL函数的C#代码。 If you still have trouble getting a breakpoint then use Debug > Windows > Modules and verify that you see the DLL in the module list. 如果仍然无法获得断点,请使用Debug> Windows> Modules并验证您是否在模块列表中看到DLL。 Get additional troubleshooting info by right-clicking it, select Symbol Load Information. 通过右键单击获取其他疑难解答信息,选择符号加载信息。 Which shows a trace of where the debugger looked for the PDB file. 其中显示了调试器查找PDB文件的位置。

You can add C++ project to the your C# solution and add reference directly to the project (not dll), then you will not be needing to copy DLL. 您可以将C ++项目添加到C#解决方案并直接向项目添加引用(而不是dll),然后您将不需要复制DLL。 After that just start normal debugging (F5) of your C# project, and breakpoints will be working for C++ project too. 之后,只需启动C#项目的正常调试(F5),断点也将适用于C ++项目。 This way will be very comfortable for debugging. 这种方式非常适合调试。 I have tried such debugging and did not change any other settings. 我尝试过这样的调试,并没有改变任何其他设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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