uIM7AI9S
uIM7AI9S

Reputation: 399

Cannot debug C++ dll loaded in C#

I wanna debug a dll made in C++ while it is inside an executable built from C# with Release mode. The C# app is supposed to not be aware. After I run the C# app I'm able to inject the dll manually which currently opens another window (so I know it was a success)

I built the dll in Debug mode in VS2019. I go Debug > Attach to Process. When I put a breakpoint it says me that it won't be hit as the symbols are not loaded. After injecting they indeed are not hit. The dll does not appear in Debug > Windows > Modules

I tried the same tasks but this time with notepad.exe as target rather than my C# app. It worked flawlessly. I guess Notepad is built with C++ or C rather than C#

Is it impossible to debug my injected C++ dll without touching the C# project?

Upvotes: 0

Views: 439

Answers (1)

Blindy
Blindy

Reputation: 67564

The dll does not appear in Debug > Windows > Modules

Look in the output window, it will tell you every library it's loading at run-time and whether or not it found symbols for it.

If it says symbols aren't there, make sure the .pdb file is in the same folder with the same name a the .dll, and try again.

Also since you're debugging a .Net application, make sure you set your debugger to also debug native code (the C++ library), because by default the VS debugger will only attach the managed debugger to the application: enter image description here

As a last thing to check, make sure "Just My Code" debugging isn't selected in VS's options, since the library you want to debug isn't considered "my code" from the point of view of the .Net host application.

Upvotes: 4

Related Questions