Reputation: 4004
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
Upvotes: 1
Views: 4421
Reputation: 27864
You need colons, not a period.
MyNamespace::MyEnum API::Go()
{
return MyEnum::OK;
}
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#.
Upvotes: 10