INFO: Variant Handling in an MFC Server w/ VB 4.0 as Its Client (142223)
The information in this article applies to:
- Microsoft Visual Basic Standard Edition for Windows 4.0
- Microsoft Visual Basic Professional Edition for Windows 4.0
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++, 32-bit Editions 2.0
- Microsoft Visual C++, 32-bit Editions 2.1
- Microsoft Visual C++, 32-bit Editions 2.2
- Microsoft Visual C++, 32-bit Editions 4.0
This article was previously published under Q142223 SUMMARY
It is possible for Visual Basic 4.0 to pass parameters to automation
methods either by value (ByVal) or by reference (ByRef). For a method that
expects a non-VARIANT parameter passed by value, MFC's implementation of
IDispatch will coerce a parameter passed by reference to a value. However,
this is not the case with an automation method expecting a VARIANT
parameter. The MFC framework cannot coerce a VARIANT parameter because it
does not know what type is expected by the method. This can cause problems
in a method that expects a VARIANT parameter to be passed by value. If the
parameter is passed by reference and the VARIANT is referenced directly,
the value obtained from the variant will be incorrect. Hence, an automation
method that expects a VARIANT to be passed by value should check whether it
was passed a reference and coerce the VARIANT if necessary. This article
illustrates how you could implement this.
Modification Type: | Major | Last Reviewed: | 12/2/2003 |
---|
Keywords: | kbAutomation kbcode kbinfo KB142223 |
---|
|