Is there any way to debug c++ dll called from C# DllImport?

Tae-Sung Shin picture Tae-Sung Shin · Sep 20, 2012 · Viewed 13.2k times · Source

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.

Answer

Hans Passant picture Hans Passant · Sep 20, 2012

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.