LispWorks COM/Automation User Guide and Reference Manual > 1 Using COM > 1.7 Calling COM interface methods > 1.7.1 Data conversion when calling COM methods

NextPrevUpTopContentsIndex

1.7.1.2 Out parameters

Out parameters are always of type pointer in COM and never appear as positional arguments in the Lisp call. Instead, there is a keyword argument named after the parameter, which can be used to pass an object to be modified by the method. In addition, each out parameter generates a return value, which will be eq to the value of keyword argument if it was passed and otherwise depends on the type of the parameter as described below.

For example, given the IDL

import "unknwn.idl";
 
[ object,
  uuid(E37A70A0-EFC9-11D5-BF02-000347024BE1)
]
interface IArgumentExamples : IUnknown
{
  typedef [string] char *argString;
 
  HRESULT outMethod([out] int *outInt,
                    [out] argString *outString,
                    [in] int outArraySize,
                    [out, size_is(outArraySize)] int *outArray);
}

the method out-method can return Lisp objects like this:

(multiple-value-bind (hres int string array)
    (call-com-interface (arg-example i-argument-examples
                                     out-method)
                        8)
  ;; int is of type integer
  ;; string is of type string
  ;; array is of type array
  )

or fill an existing array like this:

(let ((out-array (make-array 5)))
  (multiple-value-bind (hres int string array)
      (call-com-interface (arg-example i-argument-examples
                                       out-method)
                          (length out-array)
                          :out-array out-array)
    ;; int is of type integer
    ;; string is of type string
    ;; array is eq to out-array and was filled
    ))

or set the contents of foreign memory like this:

(fli:with-dynamic-foreign-objects ((out-int :int)
                                   (out-string WIN32:LPSTR))
  (let* ((out-farray-size 5)
         (out-farray (fli:allocate-dynamic-foreign-object
                      :type :int
                      :nelems out-farray-size)))
    (multiple-value-bind (hres int string array)
        (call-com-interface (arg-example i-argument-examples
                                         out-method)
                            out-farray-size
                            :out-int out-int
                            :out-string out-string
                            :out-array out-farray)
      ;; Each foreign pointer contains the method's results
      ;; int is the foreign pointer out-int
      ;; string is the foreign pointer out-string
      ;; array is the foreign pointer out-array
      ;; Note that the string must be freed as follows:
      (co-task-mem-free (fli:dereference out-string)))))

LispWorks COM/Automation User Guide and Reference Manual - 22 Dec 2009

NextPrevUpTopContentsIndex