Knowledge Base

PRB: MFCArray Fails When Using Early Binding in Visual Basic

Article ID: 189351

Article Last Modified on 12/2/2003


APPLIES TO


This article was previously published under Q189351

SYMPTOMS

When you use early binding of an automation server in Visual Basic and you pass a SafeArray as a Variant, the following error occurs:
Run-time error '1001':

Type Mismatch in Parameter. Pass a string array by reference.
You can use the MFCArray sample to observe this behavior:

140202 SAMPLE: MFCARRAY Using Safe Arrays in MFC Automation

CAUSE

For late binding, which is used for MFCArray, Visual Basic uses the Automation DLL's to package up the SafeArray in a Variant or Variant* for use in the server. However, for early binding Visual Basic must package up the SafeArray itself, therefore implementation in Visual Basic is limited to Variant*.

RESOLUTION

If you do not have access to the source code for the server, then you must use late binding in Visual Basic.

If you have access to the source code of the server, you can update the server so that the array of strings is passed to the method in a VARIANT* instead of a "const VARIANT&". This technique is discussed in the following article in the Microsoft Knowledge Base:

167668 HOWTO: Passing a SafeArray of Strings in a VARIANT*

Passing a SafeArray to a method in a Variant* works in Visual Basic for both early and late binding of automation servers.

STATUS

The requirement that you use Variant* to pass a SafeArray when using early binding in Visual Basic is by design.

NOTE: The current version of the MFCArray sample was intended to show only late binding of automation servers.

REFERENCES

For more information, please see the following articles in the Microsoft Knowledge Base:

140202 SAMPLE: MFCARRAY: Using Safe Arrays in MFC Automation

167668 HOWTO: Passing a SafeArray of strings in a VARIANT

Keywords: kberrmsg kbfile kbautomation kbprb kbsample kbcollectionclass KB189351