You are currently offline, waiting for your internet to reconnect

How to Mimic HIWORD, LOWORD, HIBYTE, LOBYTE C Macros in VB

This article was previously published under Q112651
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
SUMMARY
Visual Basic does not provide any bitwise functions for pulling apartnumeric values. In C, there are macros (HIBYTE, LOBYTE, HIWORD, andLOWORD) to separate parts of long integers into two parts, or separateintegers into two parts. This article shows by example how to do thesame thing in a Visual Basic program.
MORE INFORMATION
The HIBYTE, LOBYTE, HIWORD, and LOWORD macros are defined in C in theWINDOWS.H file. The HIBYTE and LOBYTE macros are used to retrieve thehigh-order or low-order byte of the integer passed to them. The HIWORDand LOWORD macros retrieve the high-order or low-order word from along integer value passed to them.

Step-by-Step Example

This example uses Visual Basic to mimic the HIBYTE, LOBYTE, HIWORD,and LOWORD macros

  1. Start a new project in Visual Basic. Form1 is created by default.
  2. Add two command buttons (Command1 and Command2) to Form1.
  3. Add the following code to the Comamnd1_Click event:
       Sub Command1_Click ()      Dim wParam As Integer      Dim LOBYTE As Integer      Dim HIBYTE As Integer      ' Set wParam to a value:      wParam = &H77FF      ' Make call to function:      ret = gethilobyte(wParam, LOBYTE, HIBYTE)      ' Print out return values:      Print LOBYTE, HIBYTE   End Sub						
  4. Add the following code to the Comamnd2_Click event:
       Sub Command2_Click ()      Dim lParam As Long      Dim LOWORD As Long      Dim HIWORD As Long      ' Set lParam to a value:      lParam = &H7777FFFF      ' Make call to function:      ret = gethiloword(lParam, LOWORD, HIWORD)      ' Print out return values:      Print LOWORD, HIWORD   End Sub						
  5. Add the following code to the general declarations section of Form1:
       ' Enter the following Function statement as one, single line:   Function gethilobyte(wparam as integer, LOBYTE as integer,      HIBYTE as integer)      ' This is the LOBYTE of the wParam:      LOBYTE = wParam And  &HFF&      ' This is the HIBYTE of the wParam:      HIBYTE = wParam  \  &H100  And  &HFF&      gethilobyte = 1   End Function						
  6. Add the following code to the general declarations section of Form1:
       Function gethiloword(lparam as long, LOWORD as long, HIWORD as long)      ' This is the LOWORD of the lParam:      LOWORD = lParam And  &HFFFF&      ' LOWORD now equals 65,535 or &HFFFF      ' This is the HIWORD of the lParam:      HIWORD = lParam  \  &H10000  And  &HFFFF&      ' HIWORD now equals 30,583 or &H7777      gethiloword = 1   End Function						
  7. Run the program. Click the Command1 button to pull apart an integer value into its high-order and low-order bytes. Click the Command2 button to pull apart a long integer into its high-order and low-order words.
2.00 3.00
Properties

Article ID: 112651 - Last Review: 12/09/2003 14:34:34 - Revision: 2.0

  • Microsoft Visual Basic 2.0 Standard Edition
  • Microsoft Visual Basic 3.0 Professional Edition
  • Microsoft Visual Basic 2.0 Professional Edition
  • Microsoft Visual Basic 3.0 Professional Edition
  • KB112651
Feedback