Reputation: 501
I'm using VS2010, I'm try to use a C# dll to get any enum member name in C++,
My C# dll source code:
namespace CSharpFuncion
{
public class CSFun
{
public string GetEnumName(Enum en)
{
return Enum.GetName(typeof(Enum), en);
}
}
}
My C++ code
#using "CSharpFuncion.dll"
using namespace CSharpFuncion;
CSFun ^ csFun = gcnew CSFun;
cout << csFun->GetEnumName(MyTestEnum::E_A) << endl;
Error message:
cannot convert parameter from 'MyTestEnum' to 'System::Enum ^'
How can I fix it?
Upvotes: 0
Views: 448
Reputation: 3191
Rather than
public enum MyTestEnum
{
E_A = 1,
E_B = 2
};
You need to make it
public enum class MyTestEnum
{
E_A = 1,
E_B = 2
};
So just add the class
keyword.
And change return Enum.GetName(typeof(Enum), en);
to return en.ToString()
Upvotes: 1
Reputation: 1685
you have to give Enum.GetName(typeof(MyTestEnum ), 1);
to get the name of value (E_A) in that enum
Upvotes: 0