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

Article translations Article translations
Article ID: 112651 - View products that this article applies to.
This article was previously published under Q112651
Expand all | Collapse all

On This Page

SUMMARY

Visual Basic does not provide any bitwise functions for pulling apart numeric values. In C, there are macros (HIBYTE, LOBYTE, HIWORD, and LOWORD) to separate parts of long integers into two parts, or separate integers into two parts. This article shows by example how to do the same thing in a Visual Basic program.

MORE INFORMATION

The HIBYTE, LOBYTE, HIWORD, and LOWORD macros are defined in C in the WINDOWS.H file. The HIBYTE and LOBYTE macros are used to retrieve the high-order or low-order byte of the integer passed to them. The HIWORD and LOWORD macros retrieve the high-order or low-order word from a long 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.

Properties

Article ID: 112651 - Last Review: December 9, 2003 - Revision: 2.0
APPLIES TO
  • 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
Keywords: 
KB112651
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.

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com