J
Jeremy
Hello all,
I'm having some problems working with enumerations. A function call to
a 3rd party dll has in it's parameter list an enumerated type which
connects me to a COM port. I'm trying to convert a stored parameter
from a database into this enumerated value and can't seem to get
anything to work. In some VB.NET code that was written, it works fine
and that's the frustrating part. I've included some code below:
Old vb.net code to get the enumerated value from a string:
myEnum = [Enum].Parse(GetType(EnumType), "Enum Member")
This code works fine, unfortunatly VB has no problems converting from
an Object to EnumType. When I try the same thing in VC++ with:
myEnum = Enum:arse(__typeof(EnumType), "Enum Member");
I get the compiler error C2440: Cannot convert from 'Object *' to
'EnumType'. I've also tried several ways of casting and had no luck
with that either, so what I've had to resort is below:
String *myItem = "Enum member;
EnumType myEnum;
if (myItem->Equals(__box(EnumType::Even)->ToString()))
theParity = EnumType::Even;
else if (myItem->Equals(__box(EnumType::Mark)->ToString()))
theParity = EnumType::Mark;
else if (myItem->Equals(__box(EnumType::None)->ToString()))
theParity = EnumType::None;
etc...
If anyone has any insight on converting a string or an integer to an
enumerated type, it would be greatly appreciated.
Thanks,
Jeremy
I'm having some problems working with enumerations. A function call to
a 3rd party dll has in it's parameter list an enumerated type which
connects me to a COM port. I'm trying to convert a stored parameter
from a database into this enumerated value and can't seem to get
anything to work. In some VB.NET code that was written, it works fine
and that's the frustrating part. I've included some code below:
Old vb.net code to get the enumerated value from a string:
myEnum = [Enum].Parse(GetType(EnumType), "Enum Member")
This code works fine, unfortunatly VB has no problems converting from
an Object to EnumType. When I try the same thing in VC++ with:
myEnum = Enum:arse(__typeof(EnumType), "Enum Member");
I get the compiler error C2440: Cannot convert from 'Object *' to
'EnumType'. I've also tried several ways of casting and had no luck
with that either, so what I've had to resort is below:
String *myItem = "Enum member;
EnumType myEnum;
if (myItem->Equals(__box(EnumType::Even)->ToString()))
theParity = EnumType::Even;
else if (myItem->Equals(__box(EnumType::Mark)->ToString()))
theParity = EnumType::Mark;
else if (myItem->Equals(__box(EnumType::None)->ToString()))
theParity = EnumType::None;
etc...
If anyone has any insight on converting a string or an integer to an
enumerated type, it would be greatly appreciated.
Thanks,
Jeremy