C # Enum in C ++ Library

I am having problems using the public enum defined in C # in the C ++ interface. The .NET project works with COM, which will be used in C ++ and VB software.

C # code:

 namespace ACME.XXX.XXX.XXX.Interfaces.Object { [Guid(".....")] [InterfaceType(ComInterfaceType.InterfaceIsDual)] [ComVisible(true)] public interface TestInterface { void Stub(); } [ComVisible(true)] public enum TestEnum { a = 1, b = 2 } } 

C ++ Code:

Edit: In the idl for the project, I imported tlb. ( importlib("\..\ACME.XXX.XXX.XXX.Interfaces.tlb") )

 interface ITestObject : IDispatch { [id(1), helpstring("one")] HRESULT MethodOne([in] TestInterface *a); [id(2), helpstring("two")] HRESULT MethodTwo([in] TestEnum a); } 

In MethodTwo , I keep getting errors indicating

Except for the type specification near TestEnum

I guess I'm doing something wrong. MethodOne seems to find the link correctly.

Is there any magic for referencing a .NET enum object in a C ++ interface?

+7
c ++ enums c # com
source share
1 answer

Enumerations are quite complex, the type library obtained from your C # project does not have a typedef for TestEnum . You can write it like this:

  [id(2), helpstring("two")] HRESULT MethodTwo([in] enum TestEnum a); 

Note the added enum keyword. Or you can declare your own typedef, if you use the identifier in several places or need it in your C ++ code, put it before the interface declaration:

  typedef enum TestEnum TestEnum; 

You probably prefer the latter.

+2
source share

All Articles