Search code examples
c#visual-studiovisual-c++c++-clivisual-studio-debugging

How can we debug DLL (bulit with native C/C++) source with WPF/C# executable?


Assume we have WPF/C# Project called A (A.exe). It's using DLL built with C++/CLI ;which is project B (B.Dll) And project B depends upon project D, which also a DLL built with native C/C++( D.Dll).

Simply A.exe -> uses B.Dll -> uses D.Dll

Here is my native environment is - Windows 10 ,Visual Studio 2017 ,Visual C/C++ 141 .NET 4.6.1/4.7.1.

Note that C++/CLI (CLR) project is a wrapper for native C/C++ functions, which means it's being used as a mediator between native C/C++ and WPF/C# and also all projects built under one Visual Studio Solution, therefore respective project was added as reference to other project.

Startup program is A.exe as mentioned above which is WPF/C# project.

Problem is I cannot debug C/C++ while running the project through Visual Studio 2017.

Following things I have already tried:

  • Set up working directory to built path(All DLLs,PDBs and exe there) in all projects.

  • Set up Symbol path in Visual Studio 2017.

  • Set Debugger Type to Mixed within respective projects (under Project properties -> Debugging).

  • Set(checked) Use Managed Compatibility Mode(under Visual Studio Debug->Options->Debugging).

  • Set(checked) Enable native code debugging option in WPF project(Project properties->Debug->Debugger engines).

I couldn't break the execution at least on single breakpoint marked on C++ code. Please help to solve this issue.

Thank you.


Solution

  • Target output file name for each project should be differ, else firstly loaded module's symbols will be visible to debugger. In my case A and D had similar target out file names(not implies project names). Since A is the target executable,its pdb overwrites Projects D's pdb. Nevertheless,it's wise to configure things I mentioned in my questions.