PRB: MFCArray Fails When Using Early Binding in Visual Basic (189351)



The information in this article applies to:

  • Microsoft Visual C++ 2.0
  • Microsoft Visual C++ 2.1
  • Microsoft Visual C++ 2.2
  • Microsoft Visual C++ 4.0
  • Microsoft Visual C++ 4.1
  • Microsoft Visual C++, 32-bit Enterprise Edition 4.2
  • Microsoft Visual C++, 32-bit Enterprise Edition 5.0
  • Microsoft Visual C++, 32-bit Professional Edition 4.2
  • Microsoft Visual C++, 32-bit Professional Edition 5.0
  • Microsoft Visual Basic Control Creation Edition for Windows 5.0
  • Microsoft Visual Basic Enterprise Edition for Windows 5.0

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


Modification Type:MajorLast Reviewed:12/2/2003
Keywords:kbAutomation kbCollectionClass kberrmsg kbfile kbprb kbSample KB189351