How to Pass One-Byte Parameters from VB to DLL Routines

Last reviewed: June 21, 1995
Article ID: Q71106
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, versions 2.0 and 3.0
- Microsoft Visual Basic programming system for Windows, version 1.0

SUMMARY

Calling some routines in dynamic link libraries (DLLs) requires BYTE parameters in the argument list. Visual Basic for Windows possesses no BYTE data type as defined in other languages such as C, which can create DLLs. To pass a BYTE value correctly to an external FUNCTION (in a DLL), which requires a BYTE data type, you must pass an integer data type for the BYTE parameter.

MORE INFORMATION

Visual BASIC for Windows has the ability to call external code in the form of dynamic link libraries (DLLs). Some of these libraries require BYTE parameters in the argument list. An example of this is located in the KEYBOARD.DRV FUNCTION as defined below:

    FUNCTION GetTempFileName (BYTE  cDrive,
                              LPSTR lpPrefix,
                              WORD  wUnique,
                              LPSTR lpTempFileName)

GetTempFileName is documented on page 4-217 of the "Microsoft Windows 3.0 Software Development Kit, Reference - Volume 1." In Visual Basic for Windows, declare the FUNCTION on one line in the main module of your code:

   DECLARE FUNCTION GetTempFileName LIB "keyboard.drv"
                   (BYVAL A%,  BYVAL B$, BYVAL C%, BYVAL D$)

Because the architecture of the 80x86 stack is segmented into word boundaries, the smallest type pushed onto the stack will be a word. Therefore, both the BYTE and the integer will be pushed onto the stack in the same manner, and require the same amount of memory. This is the reason you can use an integer data type for a BYTE data type in these types of procedure calls.


Additional reference words: 1.00 2.00 3.00
KBCategory: kbprg
KBSubcategory: 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: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.