I have a C# assembly containing an enum:
public enum MyEnum
{
OK = 0,
NOT_OK = -1
}
I’ve added the reference to the C++/CLI project but I don’t know how to return a value from a function.
Header:
#pragma once
using namespace System;
using namespace MyNamespace;
namespace NativeWrapper {
public ref class API
{
public:
static MyNamespace::MyEnum Go();
};
}
CPP:
#include "StdAfx.h"
#include "API.h"
using namespace NativeWrapper;
MyNamespace::MyEnum API::Go()
{
return MyEnum.OK;
}
I get the following when I build the project:
error C2275: 'MyNamespace::MyEnum' : illegal use of this type as an expression
You need colons, not a period.
Also, note that if MyEnum was originally written in C++/CLI, you’d need to declare it as
public enum class MyEnum { ... }to make it a managed enum that you can use from C#.