MS IDL has syntax for specifying a defaultvalue
for parameters.
I tried to specify a default value for a function that accepts a VARIANT_BOOL
:
[id(42)] HRESULT Foo([in, defaultvalue(VARIANT_TRUE)] VARIANT_BOOL bar);
And got the following error message:
error MIDL2035 : constant expression expected
What is the correct syntax for specifying that the default value of bar
should be VARIANT_TRUE
?
VARIANT_TRUE is #defined in WTypes.h. You can't directly use it in your .idl. The common approach is to simply use the value directly, like it is done in mshtml.idl for example:
[id(42)] HRESULT Foo([in, defaultvalue(-1)] VARIANT_BOOL bar);
Or you can add a #define to your .idl if you prefer, put it somewhere near the top:
#define VARIANT_TRUE -1
#define VARIANT_FALSE 0
Although one should not mix up bool
, BOOL
and VARIANT_BOOL
it appears that in idl BOOL
is interpreted as a VARIANT_BOOL
value.
[id(42)] HRESULT Foo([in, defaultvalue(TRUE)] VARIANT_BOOL bar);
When called from VBScript with no parameter specified this reaches the C++ code as -1
.
I'm not sure which way is more idiomatic TRUE
or as @Hans suggested -1
.
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