Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 i.e.

  • 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?

like image 238
Amit Pal Avatar asked Dec 28 '12 12:12

Amit Pal


1 Answers

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.

like image 108
Hans Passant Avatar answered Sep 21 '22 05:09

Hans Passant