I have a COM server with a method currently returning an integer:
[
object,
uuid("..."),
dual,
helpstring("IMyCOMServer Interface"),
pointer_default(unique)
]
__interface IMyCOMServer : IDispatch
{
[id(1), helpstring("method MyQuery")]
HRESULT MyQuery([in] BSTR instr, [out,retval] int* outint);
};
This compiles fine, but I'd rather return an enum: (this code is actually above the interface definition)
typedef
[
uuid("..."),
v1_enum,
helpstring("Enum")
]
enum {
value_a,
value_b,
value_c
} MyEnum;
Which again compile fine of its own right, but as soon as I change the int*
to MyEnum*
in the interface and implementation, I get linker errors:
[id(1), helpstring("method MyQuery")]
HRESULT MyQuery([in] BSTR instr, [out,retval] MyEnum* outint);
error MIDL2025 : syntax error : expecting a type specification near "MyEnum"
Whichever way I do it, I can't get it to compile.
Thanks to Euro Micelli it turns out that the real problem is that my User Defined Type (the enum) wasn't making it into the generated .IDL file. Judging by forum queries online, this seems to be a common problem.
A blog article Star Tech: UDT (User Defined Types) and COM guided me down the right path. It seems that a workaround is needed when using attributed ATL.
In summary, I made the following changes:
Created udt.idl
:
import "oaidl.idl";
import "ocidl.idl";
[
uuid("..."),
v1_enum,
helpstring("Enum")
]
typedef enum MyEnum {
value_a,
value_b,
value_c
} MyEnum_t;
[
version(1.0),
uuid(...),
helpstring(...)
]
library MyLibrary
{
enum MyEnum;
}
Added the following line prior to the module attribute in the main .cpp
file so that the above IDL gets imported into the generated file:
[importidl("udt.idl")];