4.6 Calling a Method with Byref and Optional Arguments

This example shows a sequence of messages between an automation client and a server to call a method with a byref and an optional argument. The signature of the function is:

 HRESULT test ([in, optional] VARIANT A, [in, out, optional] VARIANT *B);
  1. The client calls the GetIDsOfName method on the server for the method named test. The server returns the DISPID (section 2.2.32) in the pointer passed by the client.

  2. The client calls the Invoke method, filling the parameters as shown in the following figure. In the following example, the client is not passing any value for the first optional argument; thus, the VARIANT in rgVarg[1] has to have the field vt set to VT_ERROR and scode set to DISP_E_PARAMNOTFOUND. rgVarg[0] has the vt field set to VT_EMPTY. rgVarRef[0] is a VARIANT with the VT_BYREF bit flag set.

  3. On return from Invoke, rgVarRef[0] with the server-updated value is passed back to the client.

Calling a method with Byref and optional arguments

Figure 8: Calling a method with Byref and optional arguments

Note For brevity, the Invoke method's dispid, riid, and lcid parameters are not shown.