Reputation: 1228
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.
Upvotes: 5
Views: 7326
Reputation: 3684
If you have a huge amount of header files, you can take a look at SWIG: http://www.swig.org/
This will generate C# files from C/C++ header files.
For more info see also: http://www.swig.org/Doc2.0/SWIGDocumentation.html#CSharp
The results are quite impressive! But the naming is more C++ like, than C# style... but this was expected...
Upvotes: 2
Reputation: 3207
It's not possible to include it.
You have 2 options really
As noted by others, you can automate the first one.
Upvotes: 5
Reputation: 2039
Unfortunately no, that isn't possible as the C# compiler doesn't understand what to do with .h files. Even it if did, it still illegal to have un-scoped variables declarations (constant or otherwise) in .NET.
You'll have to convert the file either by hand, or as mentioned in the comment by Joachim Pileborg, build a utility to auto-convert it to C# code for you.
Upvotes: 0