简体   繁体   中英

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. Now i want to debug the dll but i am not able to do it.

I choose the following option to do it:

  • put the breaking point in my visual c++ project code.
  • build the dll and copy it into the directory of my c# project.
  • Now i build my c# project and dll works fine (method are calling perfectly).
  • Now i want to debug the dll .
  • I follow a blog and open the c++ project and choose the Attach to process from vc++ .
  • but i am not able to find the running process of visual c# project, whereas it available at task manager process.

In my c# project solution i have two project ie

  • web service (i called the dll method at the time of accessing a url)
  • Another one is webform application which starts the web services.

Now please help me how should i debug my dll. I have followed so many blogs but all of them are focusing on Attaching process method which is not working in my condition. 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.

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. You may have to resort to only native if your process is 64-bit.

Set a breakpoint in the DLL's source code and be sure to write C# code that exercises the DLL function. If you still have trouble getting a breakpoint then use Debug > Windows > Modules and verify that you see the DLL in the module list. 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.

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. After that just start normal debugging (F5) of your C# project, and breakpoints will be working for C++ project too. This way will be very comfortable for debugging. I have tried such debugging and did not change any other settings.

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