How to marshal C ++ overflow in C #

I need to create a wrapper between C ++ and C #. I have a function very similar to this:

virtual SOMEINTERFACE* MethodName(ATTRIBUTE_TYPE attribType = ATTRIBUTE_TYPE::ATTRIB_STANDARD) = 0; 

enum declared as follows:

 enum class ATTRIBUTE_TYPE { ATTRIB_STANDARD, ATTRIB_LENGTH }; 

How to wrap this enumeration with ATTRIBUTE_TYPE?

+8
c ++ c # marshalling pinvoke
source share
1 answer

Your C ++ enum is defined as follows:

 enum class ATTRIBUTE_TYPE { ATTRIB_STANDARD, ATTRIB_LENGTH }; 

By default, enum class types are int . This means that you can translate this into C # as follows:

 enum ATTRIBUTE_TYPE { ATTRIB_STANDARD, ATTRIB_LENGTH }; 

That's all. The C # enumeration is blittable, and this C # enumeration exactly matches your C ++ enumeration.

+8
source share

All Articles