What is the correct way of casting (in C++/CLI) from a native code enum
to a managed code enum
which contain the same enum
values? Is there any difference with using the C# way of casting like for example (int)
in C++/CLI.
相关问题
- javah not able to find android classes
- Visual Studio 2010 randomly says the command line
- efficiently calling unmanaged method taking unmana
- What is the fastest for Map keys: Enum.valueOf(~)
- Switch String with Enum variables
相关文章
-
What is the difference between
and in java - Enum with associated value conforming to CaseItera
- Why do I have to cast enums to int in C#?
- Why doesn't reflections.getSubTypesOf(Object.c
- How can I get enum possible values in a MySQL data
- Bind a char to an enum type
- Native hooking in Android Client
- ClassLoad an Enum type
Assuming your native code is
and your managed code is
You can cast from the managed to the native using
I always use
static_cast
, not the C# way of casting.It depends. for example, if you have a CLI enum that has an underlying type of ushort, it cannot hold a vallue of 257. By default the CLI enum is based on int, which should be fine in most cases. If your native C++ code use unsigned 32bit ints/64bit ints as the underlying type if enums, switch the base of your CLI enum to UInt32, long or ulong.