Debug info hidden when calling C++ function from C

2019-09-07 01:56发布

问题:

I have a VS2013 solution which consists of 2 projects:

  • a C# project
  • and a C++ (CLR/DLL) project

I am currently trying to solve these problems, but I haven't been able to so far.

  1. If I put a break point in the C++ code and run the C# project, the debugger doesn't break/halt when the C++ code is called from C#.

  2. I can't debug (i.e. see the values) of local variables in the C++ entry function:

  1. I get this warning when I build the solution in VS2013:

C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5):

warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "C:\Projects\MyProject\Debug\DSPClassLibrary.dll", "x86".

This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.

The C# project target platform is set to : AnyCPU

The C++ project target platform is set to : Win32

I am not sure what the right setting is or how I solve this problem.

回答1:

  1. You have to set "enable native code debugging" In the Project settings of your C# project. Than your breakpoints in native code will be reached. Sometimes (in VS2010 very often) you have to change the debugger settings in your C++/CLI to mixed debugging (it is set to auto by default).

  2. See 1

  3. C# Projects are always AnyCPU by default. They can run in 32Bit or 64Bit environment. C++ are 32Bit on default if created with VS2013. You should set your C# build settings to 32Bit to ensure that all will work proper on different enviroments. The setting is "x86" for 32bit.



标签: c# c++ interop clr