Visual Basic version 3.0 for Windows and Disptest (the automationcontroller that shipped with OLE version 2.0) have the followinglimitations as automation controllers in addition to those described onpages 67-69 of the OLE 2 Programmer's Reference, Volume 2:
- Parameters cannot be passed by reference to Automation properties or methods.
- Array elements cannot be accessed.
- When an exception is raised by an automation object, the value of the wCode field of the EXCEPINFO structure is not used. Instead the value 440 is displayed.
: All of these limitations have been removed in Visual Basic version4.0.
Parameters Cannot Be Passed by Reference
Visual Basic version 3.0 for Windows and Disptest cannot pass parameters byreference to automation properties and methods.
This is a limitation of Visual Basic version 3.0 and Disptest, not of OLEAutomation. OLE Automation allows building controllers that pass parametersby reference.
Here are three workarounds:
- Use return values of properties and methods to return a value instead of using byref parameters for this purpose. This approach cannot be used when a property or method returns multiple values. -or-
- Use third party controllers (see the list below) while you wait for a future version of Visual Basic, or use Visual Basic for Applications, which ships with Microsoft Excel version 5.0. Microsoft Visual Basic for Applications cannot be redistributed by or incorporated into products that are not manufactured by Microsoft. However, if user of your application has Microsoft Excel version 5.0 installed, you can use its Visual Basic for Applications as a controller of any Automation server.
Here are two known third-party controllers:
NOTE: The products included here are manufactured by vendors independent of Microsoft; we make no warranty, implied or otherwise, regarding these products' performance or reliability.
Softbridge Basic Language
Mystic River Software, Inc. 125 CambridgePark Drive, Cambridge MA 02140
Summit Software Company, 2844 Sweet Road, Jamesville, NY 13078
Internet: email@example.com -or-
- Write a DLL that has exported functions that correspond to Automation methods and properties exposed by the automation server. Visual Basic version 3.0 can call these exported DLL functions, which in turn can call the corresponding automation properties or methods in the automation server. This approach works because Visual Basic version 3.0 can pass parameters by reference to DLL functions.
The DLL functions can pass parameters by reference to the properties and methods of the automation method or property because OLE supports passing parameters by reference. This approach may not be suitable for some automation servers that implement nested objects.
Array Elements Cannot Be Accessed
Array elements cannot be accessed in Visual Basic version 3.0 or Disptest.As a result, code similar to the following code cannot be executed inVisual Basic version 3.0 or in Disptest if selection returns a safearray.This is because safearray elements cannot be accessed in Visual Basicversion 3.0 or in Disptest.
Value = ObjVar.Selection(I) ObjVar.Selection(I) = Value
Workarounds include using indexed properties, third-party controllers,Visual Basic for Applications in Microsoft Excel version 5.0, or waitingfor a future release of Visual Basic.
Indexed properties are properties that take parameters. For example,in the example code, Selection could be made a property that takes anindex parameter. Here is a description in the .ODL file of an indexedparameter called Value whose property type is VARIANT:
[propget] VARIANT Value(long index); [propput] void Value(long index, VARIANT NewValue);
In a dispinterface, an indexed property should be used under the 'methods'keyword. A Microsoft Foundations Classes (MFC) implementation can use theDISP_PROPERTY_PARAM macro in the dispatch map to implement an indexedproperty.
The disadvantage of implementing array element access using indexedproperties is the performance penalty caused by each indexed propertyaccess requiring the overhead of an RPC/LRPC call (for LocalServerAutomation objects).
Value of EXCEPINFO.wCode Not Displayed on Exceptions
When an automation object raises an exception by returning DISP_E_EXCEPTIONfrom IDispatch::Invoke and by filling the pexcepinfo parameter of thismethod, Visual Basic version 3.0 and Disptest will ignore the valuereturned in the wCode field of the EXCEPINFO structure, instead returningthe value 440. Note that either the wCode or scode field of EXCEPINFOshould be set to 0 -- both cannot be used.
Workarounds include using third-party controllers, Visual Basic forApplications in Microsoft Excel version 5.0, or waiting for a futurerelease of Visual Basic.