I’m currently working on creating a new C# project that needs to interact with an older C++ application. There is an error enumeration that already exists in the C++ app that I need to use in the C# app.
I don’t want to just re declare the enumeration in C# because that could cause sync issues down the line if the files aren’t updated together.
All that being said my question is this: Is there a way for me to taken an enumeration declared like so:
typedef enum { eDEVICEINT_ERR_FATAL = 0x10001 ... } eDeviceIntErrCodes;
and use it in a C# program like so:
eDeviceIntErrCodes.eDEVICEINT_ERR_FATAL
Check out the PInvoke Interop Assistant tool http://www.codeplex.com/clrinterop/Release/ProjectReleases.aspx?ReleaseId=14120. Its a useful tool for generating PInvoke signatures for native methods.
If I feed it your enum it generates this code. There is a command line version of the tool included so you could potentially build an automated process to keep the C# definition of the enum up to date whenever the C++ version changes.