Amit Pal
Amit Pal

Reputation: 11062

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:

In my c# project solution i have two project i.e.

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?

Upvotes: 5

Views: 6804

Answers (2)

Hans Passant
Hans Passant

Reputation: 942197

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.

Upvotes: 9

SergeyS
SergeyS

Reputation: 3553

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.

Upvotes: 0

Related Questions