I wonder if there is any way to debug c++ dll called from C# PInvoke in VS 2010. I tried to attach the project into c# application but it didn't work - didn't stop at a break point.
I also tried to record anything with OutputDebugString in C++ project but nothing printed with PInvoke call. Despite these issues, the actual function runs well.
Any advice will be appreciated.
Debug from the DLL project Set breakpoints in the DLL project. Right-click the DLL project and choose Set as Startup Project. Make sure the Solutions Configuration field is set to Debug. Press F5, click the green Start arrow, or select Debug > Start Debugging.
Visual Studio Code supports the following debuggers for C/C++ depending on the operating system you are using: Linux: GDB. macOS: LLDB or GDB. Windows: the Visual Studio Windows Debugger or GDB (using Cygwin or MinGW)
Both require turning on the same option: Project > Properties > Debug tab > tick the "Enable unmanaged code debugging" option.
You can now set a breakpoint in the native DLL code, it will turn from hollow to solid as soon as the C# project loads the DLL. And OutputDebugString() output will go to the Output window thanks to the unmanaged debugging engine being used.
If you run up a C++ debugger while your program is running, and then go to Debug->Attach To Process->Find your process and attach to it. You should be able to debug it.
Make sure that you have compiled your DLL with the debugger symbols. (.pdb) file and that they are in the directory where you run things from.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With