Reach managed c++ Enum from C#

G

Guest

I'm trying to use an enum created in Managed c++ in a C# project. I can reach
the enums name, i.e.

namespace MyNS
{
public enum MyEnum
{
EOne,
ETwo
};
}

in C++ makes me able to reach MyNS, but not MyNS.EOne. Why?
 
C

Clive Dixon

Presumably you need to use MyNS.MyEnum.EOne. In using enum values you need
to use <enum_type_name>.<value> and can't access <value> directly.
 
G

Guest

Thank you Clive,

However, I have tried that too and it doesn't work.

Regards,
Joachim
 
W

Willy Denoyette [MVP]

Joachim said:
I'm trying to use an enum created in Managed c++ in a C# project. I can reach
the enums name, i.e.

namespace MyNS
{
public enum MyEnum
{
EOne,
ETwo
};
}

in C++ makes me able to reach MyNS, but not MyNS.EOne. Why?


Because you have declared a *native* enum. You'll have to declare a managed enum to be
usable in other managed code.
Try this:
public enum class MyEnum
or..
public enum struct MyEnum

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top