optional attribute
The [optional] attribute specifies an optional parameter for a member function.
return-type function-name([optional [, other-attributes]] parameter-type parameter-name)
-
return-type
-
Specifies the return type of the function.
-
function-name
-
Specifies the name of the function as defined in the IDL file.
-
other-attributes
-
Zero or more optional MIDL attributes.
-
parameter-type
-
The data type of the optional parameter.
-
parameter-name
-
Specifies the name of the optional parameter.
The [optional] attribute is valid only if the parameter is of type VARIANT or VARIANTÂ *.
The MIDL compiler accepts the following parameter ordering (from left-to-right):
- Required parameters (parameters that do not have the [defaultvalue] or [optional] attributes),
- Optional parameters with or without the [defaultvalue] attribute,
- Parameters with the [optional] attribute and without the [defaultvalue] attribute,
- [lcid] parameter, if any,
- [retval] parameter
You cannot apply the [optional] attribute to a parameter that also has the [lcid] or [retval] attributes.
HRESULT MyFunc([in, optional] VARIANT Param1,
[out, optional] VARIANT Param2)