I'm having issues using a public enum
defined in C# within a C++ Interface. The .NET project is exposed to COM to be used within C++ and VB legacy 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 the 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 stating
Excepting Type Specification near TestEnum
I'm assuming there's something I'm not doing correctly. MethodOne
seems to be finding the reference correctly.
Is there some magic to referencing .NET enum object in C++ interface?
Enums are a fairly quirky, the type library that you got from your C# project does not have a typedef for TestEnum
. You can write it like this instead:
[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 multiple places or need it in your C++ code, put it before your interface declaration:
typedef enum TestEnum TestEnum;
You probably prefer the latter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With