The information in this article applies to:
SUMMARYOLE Automation does not allow structures to be passed as parameters. Automation servers that work with standard controllers like Visual Basic can model a structure as an automation object or pass simple structures as a safearray of VT_UI1. Automation servers that work with custom controllers can pass structures as a safearray of VT_UI1 or by passing a data transfer object that supports IDataObject. MORE INFORMATION
OLE Automation does not support passing structures as parameters to
automation methods and properties. Here are some ways to work around this:
This could modeled as an automation object with two properties, x and y.
Visual Basic code such as the following could be used to get and set the
values of the properties.NOTE: The CreateLine method, which required two points as parameters, is implemented as taking references to two automation objects.
The CreatePoint method returns a Point automation object whose x & y
properties are set. The type of the value returned by CreatePoint is
IDispatch* or a pointer to an object that supports automation. The
CreateLine method takes two parameters of type IDispatch* or a pointer
to an object that supports automation.The disadvantage of this solution is that if the automation server is not an inproc server, each property access will result in the overhead of an LRPC/RPC call. If the automation server is designed to work with custom controllers, the structure could be serialized into a safearray of VT_UI1 and the resultant binary data could be passed as a parameter of type SAFEARRAY(unsigned char). Another solution is to create a data transfer object that supports IDataObject. The IUnknown of this data transfer object could be passed in a parameter of type IUnknown*. The server could then use IDataObject::GetData with a private clipboard format to get the storage medium in which the structure was serialized. Simple structures can be passed from Visual Basic using a safearray of VT_UI1 as described in Don Box's OLE column in the June 1996 issue of the Microsoft Systems Journal. NOTE: Serializing the structure into a BSTR will not work because the Unicode-ANSI conversions done by OLE's 16:32 bit interoperablity layer assumes that BSTRs contain strings and not binary data. Consequently, binary data passed in BSTRs can be corrupted by such conversions. However, serializing binary data into BSTRs will work if both controller and server are 16-bit. It will also work if both the controller and server are 32-bit and both support Unicode. This is because 32-bit OLE supports only Unicode, not ANSI. A safearray of VT_UI is preferred because of these limitations of passing binary data through BSTRs. Additional query words: 2.00 3.00
Keywords : kbcode kbole kbAutomation kbVBp300 kbGrpCom kbDSupport LeTwoAto |
Last Reviewed: October 26, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |