0

I have a code running that successfully register Excel AddIn using C# Automation and talks to C++ though C# layer

// Tools -> Create GUID -> Register Format
namespace MyExcelAddins
{
    [ClassInterface(ClassInterfaceType.AutoDual), ComVisible(true)]
    [Guid("6F89542F-3DAC-471F-86DD-145F5E456968")]

    public class MyExcelFunctions : AddInRegistrator
    {
        [DllImport(@"C:\Users\Ilya\Documents\Visual Studio 2012\Projects\UnmanegedTester\x64\Debug\")]
        public static extern double AddNumbers(double a, double b);

        public double SampleAdd(double a, double b)
        {
            double res = AddNumbers(a, b);
            return res;
        }
    }
}

Here is the view of my solution where C++ project I added from another directory.

solution explorer view

I was able to debug C# code and now I want to try to debug the C++ part. I set the debug property of C# project to

C# project debug properties

and when click run, the error I got is

error when running

If I uncheck "Enable Native Code Debugging", I do not have the error but of course cannot debug C++. My guess I'm missing something in the settings. Please let me know if anyone has an idea how to fix that.

If I continue debugging I can hit breakpoint in C# but not in C++

enter image description here

ilyaw77
  • 937
  • 3
  • 10
  • 15
  • Debugging imported libraries can be tricky even if you own them. I think you need to manually add the PDB of the C code since VS sees to _actual_ link between the projects. Take a look here: https://stackoverflow.com/questions/17634266/how-to-load-symbols-in-visual-studio-2012 Keep in mind you can also use `C++/CLI` which works very well with native debugging and the C# code wouldn't need to use `import` or any of that. – Everyone May 26 '19 at 05:49
  • The simplest way to do this is to right-click the UnmanagedC project and select "Set as StartUp Project". Right-click again > Properties > Debugging, set the Command property to excel.exe. You now only have the unmanaged debugging engine active when you press F5. If you still have breakpoint problems then use Debug > Break All and Debug > Windows > Modules. Do note that this DLL can never get loaded if you use the 32-bit version of Excel. – Hans Passant May 26 '19 at 06:55
  • Thanks for your suggestion guys. I marked below answer as correct one. Only thing I had to do is to continue debugging. Even though break point was telling that it did not load any symbols but code indeed hit it when running. – ilyaw77 May 26 '19 at 16:00

1 Answers1

1

That error message is telling you that you don't have debug symbols for excel.exe, which is not surprising since it is a Microsoft program. You can continue debugging, and your code (which should have debugging information) will still be debuggable. For example, you can set a breakpoint in some of your code that will be called by Excel and the debugger will stop on it when it is reached.

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
  • If I continue debugging I can hit break point in C# but not in C++ and I want to be able hit breakpoints in both languages. – ilyaw77 May 26 '19 at 05:32
  • @ilyaw77 Enabling Native debugging should allow for debugging the C++ code, although it won't be visible until the code in question is loaded, which might not be until you try to call `AddNumbers` from within `SampleAdd`. – 1201ProgramAlarm May 26 '19 at 05:35
  • Thanks 1201ProgramAlarm. You were right. If I simply ignore the message and continue debugging it indeed hit break point! – ilyaw77 May 26 '19 at 16:01