optional attribute

The [optional] attribute specifies an optional parameter for a member function.

return-type function-name([optional [, other-attributes]] parameter-type parameter-name)

Parameters

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.

Remarks

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):

  1. Required parameters (parameters that do not have the [defaultvalue] or [optional] attributes),
  2. Optional parameters with or without the [defaultvalue] attribute,
  3. Parameters with the [optional] attribute and without the [defaultvalue] attribute,
  4. [lcid] parameter, if any,
  5. [retval] parameter

You cannot apply the [optional] attribute to a parameter that also has the [lcid] or [retval] attributes.

Examples

HRESULT MyFunc([in, optional] VARIANT Param1, 
               [out, optional] VARIANT Param2)

See also

defaultvalue

Generating a Type Library With MIDL

lcid

ODL File Example

ODL File Syntax

retval