Microsoft KB Archive/177575

= PRB: ActiveX Controls Passing Variant* Back to VFP Cause Error =

Article ID: 177575

Article Last Modified on 2/17/2005

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q177575



SYMPTOMS
When calling a method in an ActiveX control built with Microsoft Foundation Classes (MFC), if there is an out parameter in the method with a type variant, Visual FoxPro returns a type mismatch error.



CAUSE
When you call a method in the ActiveX control and pass it a variable by reference to receive a parameter value back from the ActiveX control, Microsoft Visual FoxPro seems to use a data type of BSTR. If the ActiveX method's parameter is defined as a Variant in the MFC based ActiveX control, this causes MFC to try and coerce the data types to match by using the VariantChangeType function. This function returns the type mismatch error.



RESOLUTION
Controls built with the ActiveX Template Library (ATL) do not have this problem. If you build the control in Microsoft Foundation Classes (MFC), avoid using out parameter data types of variant.



STATUS
This behavior is by design.



Creating the Server
 Create an MFC ActiveX control using the control wizard.  Add a method to the control: void CMyCtrl::MyMethod(VARIANT FAR* m_pVariant) {     }                     Build and register the control.

Creating the Client
 Create a new form.</li> Add an OLE container object.</li> When the dialog box displays, select the "Insert Control" option.</li> Select the control you just built with MFC.</li>  Create a command button on the form and place the following code in the Click event: ****Begin Example Code************ xy=space(0) THISFORM.OleControl1.mymethod(@xy) *****End Example Code************** When the button is clicked, the type mismatch error occurs. </li></ol>

<div class="references_section">