BUG: CDK: VBSetVariantValue Return Value Changed in 4.0

ID: Q142465

The information in this article applies to:

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;

Additional query words: kbVBp400bug kbVBp kbdsd kbDSupport kbUsage
Version           : 4.00
Platform          : NT WINDOWS
Issue type        : kbbug

Last Reviewed: August 7, 1998