BUG: CDK: VBSetVariantValue Return Value Changed in 4.0

Last reviewed: February 22, 1996
Article ID: Q142465
The information in this article applies to:
  • Professional and Enterprise Editions of Microsoft Visual Basic, 16-bit only, for Windows, version 4.0

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.

WORKAROUND

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 reference words: 4.00 vb4win vb416 buglist4.00
KBCategory: kbusage kbbuglist
KBSubcategory: TlsCDK


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 22, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.