BUG: CDK: VBSetVariantValue Return Value Changed in 4.0 (142465)



The information in this article applies to:

  • Microsoft Visual Basic Professional Edition, 16-bit, for Windows 4.0
  • Microsoft Visual Basic Enterprise Edition, 16-bit, for Windows 4.0

This article was previously published under Q142465

SYMPTOMS

The return value of the VBSetVariantValue function in the VBAPI library has changed in the 16-bit version of Microsoft Visual Basic version 4.0. This change in behavior affects 16-bit DLLs and custom controls (VBXs) that previously worked with Microsoft Visual Basic version 3.0.

MORE INFORMATION

The documentation for the VBSetVariantValue function in the Control Development Guide in the Professional Edition of Microsoft Visual Basic states that when this function is used with the documented VB_<type> types, a -1 value is returned for errors, and 0 is returned for success. This statement is no longer true for DLLs and custom controls (VBXs) used with Visual Basic 4.0. The VBSetVariantValue function returns -1 for errors, 0 or greater for success.

STATUS

Microsoft has confirmed this to be a issue in the 16-bit version of Visual Basic for Windows version 4.0. We are researching this issue and will post new information here in the Microsoft Knowledge Base as it becomes available.

RESOLUTION

To indicate success, change the DLL or VBX source code to handle return values of 0 or greater, instead of equivalence to 0. For example, if you have code that resembles the following:
   #include <vbapi.h>

   #define SUCCESS 0
   #define FAIL -1

   int VBAPI SetMyVariant (LPVAR pVariant)
   {
      short NewValue = 0x1234;
      ERR nResult;
      nResult = VBSetVariantValue (pVariant, VT_I2, (LPVOID) &NewValue);
      if (0 == nResult)
         return SUCCESS;
      else
         return FAIL;
   }
				
A DLL or VBX that contains this function correctly returns SUCCESS when used from a Visual Basic version 3.0 program. When the same DLL or VBX is used from a Visual Basic version 4.0 program, it incorrectly returns FAIL.

You can avoid this problem by changing the line:
   if (0 == nResult)
				
to
   if (0 <= nResult)
				
-OR-

you can test for a failure only. For example:
   if (-1 == nResult)
      return FAIL;
   else
      return SUCCESS;
				

Modification Type:MinorLast Reviewed:1/8/2003
Keywords:kbbug KB142465