Search code examples
c++visual-c++comidl

How to declare IN, OPTIONAL parameter along with OUT, RETVAL parameter in IDL


I have an existing Interface API, which has an OUT, RETVAL parameter like below

HRESULT Test([out, retval] VARIANT_BOOL *pVal);

I was asked to add an optional IN parameter, hence I tried the below, since RETVAL parameter by rule should be the last parameter I was forced to put the optional IN parameter as a first parameter

HRESULT Test([in, optional, defaultvalue(VARIANT_FALSE)] VARIANT_BOOL optFlag, [out, retval] VARIANT_BOOL *pVal);

When I tried to call this API like below, with only the mandatory OUT parameter from a C++ component compiler errors out saying two parameters are required for this call

VARIANT_BOOL outFlag;
pInterface->Test(&outFlag);

Please let me know what I am missing here to achieve this combination.


Solution

  • The C++ bindings generated by microsofts IDL compiler do not support the optional and/or default value feature.

    Try it from C# or similar.