using enums from C++ headers in C#

  • Thread starter Thread starter Steve Roberts
  • Start date Start date
S

Steve Roberts

Hi,

I've got an unmanaged C++ DLL that I'm calling functions in from a C# EXE,
via a managed C++ DLL.
My problem is that I have a lot of enumerated types defined in C++ headers -
is there a way that I can use these enumerations in all of the modules,
rather than having to rewrite them for the C# ?

e.g. if I have:

enum ColorValue { red, green, blue };

in my C++ .h file, is there a way that I can use ColorValue in my C# code ?

Thanks for any help,
Steve
 
Steve,

You could always declare the enumerations as managed enumerations, then
they would be accessible to any assembly that manages the referenced
assembly.

Basically, you would do:

enum class MyEnum {Value1, Value2};

I think this uses the new CLI bindings for C++. I am not sure what the
managed extensions for C++ syntax would be though.

Hope this helps.
 
Not automatically - you'll have to copy-paste them and compile them into a
..net assembly, use the integer values, or create a quick tool to do the
copy/paste/fix/compile steps for you. your c# code can't use the enums
directly from c++ . The syntax is so close (as in, the same) that you
should be able to do much of it easily, though
 
Back
Top