BUG: CDK: VBSetVariantValue GPF with Null Pointer

Last reviewed: July 26, 1996
Article ID: Q154033
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 16-bit edition of Visual Basic 4.0 stops with a General Protect Fault in module VB.EXE at 002F:350B.

CAUSE

Passing a NULL pointer to the lpData argument of VBSetVariantValue() in the VBAPI library will cause this General Protection Fault. Normally, you would not pass a NULL pointer to lpData, but the VBCreateTempHlstr() function is documented as returning a NULL if you create a TempHLSTR on an empty (zero- length) string. Because you can call VBSetVariantValue() using a TempHLSTR to assign a string to a variant, this function should work with a NULL pointer in the lpData argument, but it doesn't.

MORE INFORMATION

Visual Basic 3.0 is not affected by this problem, as the VBCreateTempHlstr() function will not return a NULL, even for empty strings. This is the only situation that is documented as acceptable to pass NULL as the lpData argument.

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

WORKAROUND

There are several workarounds available to you. Choose the one that best fits your needs:

  1. Avoid using a TempHLSTR to set a variant's value. Instead, use a normal HLSTR to set the variant's value instead.

    You must be sure not to call VBDestroyHlstr() on this HLSTR before you return control to Visual Basic. Visual Basic 4.0 simply copies a reference to the HLSTR's data in VBSetVariantValue(). Destroying the HLSTR before Visual Basic regains control from your function prevents it from reading the string data stored by the HLSTR. You may reuse the same HLSTR in your function; that is, you do not have to maintain the data in the HLSTR after your function has returned control to Visual Basic.

    NOTE: TempHLSTR values work best when they return a string from a function call or are used to retrieve property values from custom controls (VBXs). Even though they are documented as being suitable for setting variants, there are only a few TempHLSTR spaces available to Visual Basic programs; you should use them sparingly.

  2. Instead of trying to return an empty string, pass another variant type. For instance, VT_NULL indicates that the variant has no data in it.

    Be aware that this workaround may affect the behavior of Visual Basic programs that have already been compiled using your DLL or custom control. If no Visual Basic programs have been compiled using your DLL or custom control, this should not be a problem.


Additional reference words: 4.00 vb4win vb416 CDK CDG DLL VARIANT VBAPI
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: July 26, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.