BUG: "Type Mismatch" Error When You Call an eVC DLL That Returns Variants (215382)



The information in this article applies to:

  • Microsoft eMbedded Visual Basic 3.0

This article was previously published under Q215382

SYMPTOMS

When you try to call an eMbedded Visual C++ (eVC) dynamic-link library (DLL) that returns a variant, you receive a "Type Mismatch" error.

CAUSE

Microsoft Visual Basic expects return values from functions to be passed by value. However, there is no device-independent way to pass large structures, such as variants, by value.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

Build the eVC Component

  1. Start eMbedded Visual C++.
  2. From the File menu, click New.
  3. On the Projects tab, click WCE Dynamic-Link Library.
  4. In the Project name text box, type a project name (such as ReturnVariant).
  5. In the CPUs list box, click the appropriate platform for your Microsoft Windows CE device, and then click OK.
  6. In the WCE Dynamic-Link Library dialog box, click An empty Windows CE DLL project, and then click Finish.
  7. Click OK to create the project.
  8. From the File menu, click New.
  9. On the Files tab, click C++ Source File.
  10. In the File name text box, type a file name (such as ReturnVariant.cpp), and then click OK.
  11. From the File menu, click New.
  12. On the Files tab, click Text File.
  13. In the File name text box, type a file name (such as ReturnVariant.def), and then click OK.
  14. From the Windows menu, open the ReturnVariant.cpp file, and paste the following code:
    #include<windows.h>;
    
    VARIANTARG __stdcall ReturnVar(VARIANTARG &v1)   
    {
       return v1;	 
    }
    					
  15. Open the ReturnVariant.def file, and paste the following code:
       EXPORTS
       ReturnVar
    					
  16. From the WCE Configuration toolbar, select the appropriate device and build information.
  17. Ensure that the Windows CE device is connected to the desktop development computer.
  18. From the Build menu, click Rebuild All. The DLL is compiled and downloaded to the device.
  19. From the File menu, click Save Workspace, and then click Exit.

Build the eVB Component

  1. Start a new Windows CE project in eMbedded Visual Basic based on your target device platform.
  2. Add a CommandButton control to Form1.
  3. Paste the following code into Form1:
       Option Explicit
       Public Declare Function ReturnVar Lib "ReturnVariant" _
           (ByRef v1 As Variant) As Variant
    
       Private Sub Command1_Click()
          Dim x As Variant
          Dim y As Variant
          x = ReturnVar(y)
       End Sub
    					
  4. Ensure that the device is connected to the desktop development computer and that you are running the project on the default device.
  5. Run the project.
  6. On the device, click Command1. The "Type Mismatch" error occurs.

Modification Type:MajorLast Reviewed:9/4/2002
Keywords:kbAPI kbbug kbDSupport kbToolkit KB215382