Use ByVal to Pass a Control as an Argument to a DLL or VBX

Last reviewed: October 30, 1995
Article ID: Q129827
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0

In previous versions of Visual Basic, when you passed a control to a DLL or VBX, your function declaration looked like this:

   Declare Function fDoNothing Lib "MyFun.vbx" (ctlX as Control) As Integer

Now, in Microsoft Visual Basic version 4.0, the keyword ByVal must be used when passing the same control, so now your function declaration must look like this:

   Declare Function fDoNothing Lib "MyFun.vbx" (ByVal ctlX as Control)_
      As Integer

The Visual Basic API was changed. Now, functions expecting a control as a parameter require a handle to the control, an HCTL. Omitting ByVal within the parameter list causes a pointer to the HCTL to be passed instead of the HCTL itself. To ensure an HCTL is passed, use the ByVal keyword. This behavior is by design.


Additional reference words: 4.00 vb4win vb4all
KBCategory: kbprg
KBSubcategory: TlsCDK APrgOther


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: October 30, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.