I've compiled a dll in c++ with an enum that needs to be use in a c++ project and ac# project. With the c++ project there were no problems but in c# pops up that DllImport can only be used for methods
I've thought about functions to solve this problems but it's all a mess. I simply need to access c++ enums from c#
this is the c++ enum inside the dll:
enum DLL_PUBLIC ByteCode
{
// Stuffs...
};
and this is how i tried to import it in c#:
[DllImport("ByteCodes.dll", CallingConvention = CallingConvention.Cdecl)]
enum ByteCodes;
Here i got that DllImport
can only be used for methods but i need it for enums. What can i do?
You can re-declare the members of the enum as simple const int
values in the C# side. Or you can simply redeclare the enum, making sure to define the members with = 1
, etc. to match the C++ declaration.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.