BUG: VBA Requires [out, retval] Parameters to be Pointers (244065)



The information in this article applies to:

  • Microsoft Visual Basic for Applications (VBA) Software Development Kit (SDK) 5.0
  • Microsoft Visual Basic for Applications (VBA) Software Development Kit (SDK) 6.0
  • Microsoft Visual Basic for Applications (VBA) Software Development Kit (SDK) 6.1

This article was previously published under Q244065

SYMPTOMS

If a method exposed to VBA through either a host application's object model or a control containing an [out, retval] parameter that is not a pointer, VBA might crash when using the Object Browser or IntelliSense. For example, if the type library of an object exposed to VBA contains the following type definition and method definition, VBA may crash:
   typedef
   [
      uuid(4D303331-FBCF-11D2-94E9-006008726F01),
      helpstring("Custom Typedefinition tShort")
   ] short*  tShort;

   HRESULT Football([in, out]BSTR ErrText, [out, retval]tShort ReturnVal);
				

CAUSE

This problem occurs because VBA expects parameters marked [out, retval] to be pointers (that is, of type VT_PTR). When this condition is violated, an error occurs.

RESOLUTION

To correct this problem, all parameters in a type library marked [out, retval] should be made pointers. To revisit the previous example, changing the second parameter of the method from tShort to short* alleviates the crash:
   HRESULT Football([in, out]BSTR ErrText, [out, retval]short* ReturnVal);
				

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

Modification Type:MajorLast Reviewed:10/28/1999
Keywords:kbbug KB244065