Search code examples
c#visual-c++managed

Including a C++ header file in a c# file


I was converting a Managed c++ project to a C# one. The C++ project includes a constants C++ header file which is an external dependency present outside of the project.

In the newly created C# file, is there a way to include this C++ header file? I dont want to redefine these constants in a C# file as changes by clients will take place on the C++ header file.


Solution

  • It's not possible to include it.

    You have 2 options really

    • duplicate it for the managed layer, and maintain it in synch with the C++ header.
    • read and parse it at runtime, and use reflection in the C# parts that require those symbols.

    As noted by others, you can automate the first one.