Data Model > Extending the UNICOM Intelligence Data Model > Adding function libraries > Functions with optional or variable parameters
 
Functions with optional or variable parameters
The IDL definition for the GetTimeZone function shows how to implement an optional argument by including the optional attribute in the parameter definition:
[id(17), helpstring("method GetTimeZone")] HRESULT MR_RTLCID_GetTimeZone(
[in] IDispatch* pEngine, [in] IDispatch* pProgram,
[in] long lInputLCID, [in] long lOutputLCID,
[in, optional] VARIANT Val,
[out, retval] long* plResult);
To specify a default value for an optional argument
Add the defaultvalue(..) attribute to the parameter definition, as shown in the IDL definition for the Format function:
[id(20), helpstring("method Format")] HRESULT MR_LCIDMDMID_Format(
[in] long lInputLCID, [in] long lOutputLCID, [in] IUnknown* pLevel, [in] BSTR sId,
[in] VARIANT Val,
[in, defaultvalue("")] BSTR Style,
[in, defaultvalue(0)] long Width,
[in, defaultvalue(-1)] long Locale,
[out, retval] BSTR* psResult);
To define a function that has a variable number of arguments
Include the vararg optional attribute in the function definition and make sure that the last parameter is a safe array of the VARIANT type. The IDL definition for the BitOr function shows an example of this:
[id(10), vararg, helpstring("method BitOr")] HRESULT MR_LCID_BitOr(
[in] long lInputLCID, [in] long lOutputLCID,
[in] long Val1,
[in] SAFEARRAY(VARIANT) Vals,
[out, retval] long* psResult);
For more information, see Microsoft Interface Definition Language:
http://msdn2.microsoft.com/en-us/library/aa367091.aspx
See also
Adding function libraries