defaultvalue attribute
The [defaultvalue] attribute allows you to specify a default value for a typed optional parameter.
interface interface-name
{
return-type function-name(
mandatory-param-list,
[[attribute-list,] defaultvalue(value)] param-type param-name
[ , optional-param-list]);
}
Parameters
-
interface-name
-
Specifies the name of the interface.
-
return-type
-
Specifies the return type of the function.
-
function-name
-
Specifies the name of the function to which the [defaultvalue] attribute will be applied.
-
mandatory-param-list
-
Specifies on or more required parameters.
-
attribute-list
-
Specifies a list of one or more attributes, separated by commas, that apply to the parameter.
-
param-type
-
Indicates the type of the optional parameter.
-
param-name
-
Specifies the name of the optional parameter.
-
optional-param-list
-
Specifies zero or more additional parameters, each of which must have a default value.
Remarks
The default value you specify for the parameter can be any constant, or an expression that resolves to a constant, that can be represented by a VARIANT. Specifically, you cannot apply the [defaultvalue] attribute to a parameter that is a structure, an array, or a SAFEARRAY type.
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
Examples
interface IFace : IUnknown
{
HRESULT Ex1([defaultvalue(44)] LONG i);
HRESULT Ex2([defaultvalue(44)] SHORT i);
...
};
interface QueryDef : IUnknown
{
HRESULT OpenRecordset( [in, defaultvalue(DBOPENTABLE)]
LONG Type,
[out,retval] Recordset **pprst);
}
// Type is now known to be a LONG type (good for browser in VBA and
// good for a C/C++ programmer) and has a default value of
// DBOPENTABLE
See also