Microsoft KB Archive/154033

= BUG: CDK: VBSetVariantValue GPF with Null Pointer =

Article ID: 154033

Article Last Modified on 1/9/2003

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition

-



This article was previously published under Q154033



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.
 * 1) 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 query words: 4.00 vb4win vb416 CDK CDG DLL VARIANT VBAPI

Keywords: kbbug KB154033

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.