what is low-order word?

This is a discussion on what is low-order word? within the Windows Programming forums, part of the Platform Specific Boards category; like what does LOWORD(wparam) do? a conversion?...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    3

    what is low-order word?

    like what does LOWORD(wparam) do?
    a conversion?

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,171
    A word is 2 bytes. LOWORD() is basically just doing a bitmask. Let's say you had the hex number 0x3F754873. LOWORD(0x3F754873) would just give you 0x4873. Encoding more than one value into a single variable is an old programming technique.

    It's basically this:
    #define LOWORD(x) ((x) & 0xFFFF)

    HIWORD() would be:
    #define HIWORD(x) (((x) >> 16) & 0xFFFF)
    Last edited by itsme86; 08-02-2006 at 12:41 PM.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    what a coincidence, I was just doing some hunting around on this exact same topic. Here''s some other useful things I found in windef.h:
    Code:
    typedef unsigned short WORD;
    typedef unsigned long DWORD;
    I went through the .h files because finding them on MSDN is, to say the least, aggrivating.
    [rant]
    It amazes me how the simplest, most basic widgets of the windows API can NOT even be found easily on MSDN. Typing in DWORD, WORD, HWND, LONG_PTR, or any of the basic api structures into the search yeilds nothing even remotely useful and I'm not even sure if an MSDN entry exists for these things at all....
    I'm still not sure what exactly HWND contains or LONG_PTR, but after a call to sizeof with each, I'm guessing their both of type unsigned long (4 bytes).
    Does anyone know how/where to get a full, in-depth, concise listing of all windows API structures, constants, functions etc, in a manner in which you type the name, and it will bring up a list of functions, consts, etc, that directly contain the search string? (like javadocs style, no-cockamamie-tangent-searches, where it lists only API items, I.E. if I type in "DWORD" it will show first any API items equal to that exact string, and then those containing the string, instead of listing 5 billion useless entries for Microsoft Word a la MSDN style...)
    [/rant]

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,171
    Well LONG_PTR is pretty self-explanatory, no?

    typedef long* LONG_PTR;
    If you understand what you're doing, you're not learning anything.

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by @nthony
    Here''s some other useful things I found in windef.h:
    Code:
    typedef unsigned short WORD;
    typedef unsigned long DWORD;
    I went through the .h files because finding them on MSDN is, to say the least, aggrivating.
    [rant]
    It amazes me how the simplest, most basic widgets of the windows API can NOT even be found easily on MSDN. Typing in DWORD, WORD, HWND, LONG_PTR, or any of the basic api structures into the search yeilds nothing even remotely useful and I'm not even sure if an MSDN entry exists for these things at all....
    I'm still not sure what exactly HWND contains or LONG_PTR, but after a call to sizeof with each, I'm guessing their both of type unsigned long (4 bytes).
    Does anyone know how/where to get a full, in-depth, concise listing of all windows API structures, constants, functions etc, in a manner in which you type the name, and it will bring up a list of functions, consts, etc, that directly contain the search string?
    [/rant]
    [counter-rant]It's not polite to look up the lady's skirt. (You're not supposed to care what the implementation uses to implement what it needs to do.)

    Use WORD when you need a WORD; use DWORD when you need a DWORD. Today such things may be defined with what you saw under the skirt -- tomorrow they may be different. But if you use a WORD when you should use a WORD, even if what is under the skirt has changed to be correct, then you don't have to care.

    What if it one day changed to this:
    Code:
    typedef uint16_t WORD;
    typedef uint32_t DWORD;
    Or this:
    Code:
    typedef unsigned char WORD;
    typedef unsigned int DWORD;
    [counter-rant]

    Given my counter-rant, it would be my impression that the aggrevation is intentional for just this reason.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    There is a short explanation of most of the types at MSDN: Windows Data Types. As Dave said, you should not rely on their definition remaining the same.

    Quote Originally Posted by itsme86
    Well LONG_PTR is pretty self-explanatory, no?

    typedef long* LONG_PTR;
    That would be a LPLONG or just a PLONG (neither of which should be used). A LONG_PTR is an integer type which is large enough to fit either a long or a pointer. The other *_PTR types follow the same pattern.
    Quote Originally Posted by MSDN
    Signed long type for pointer precision. Use when casting a pointer to a long to perform pointer arithmetic.

    This type is declared in BaseTsd.h as follows:
    Code:
    #if defined(_WIN64)
     typedef __int64 LONG_PTR; 
    #else
     typedef long LONG_PTR;
    #endif

  7. #7
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,171
    Quote Originally Posted by itsme86
    Well LONG_PTR is pretty self-explanatory, no?

    typedef long* LONG_PTR;
    Apparently it's not. Go ambiguous names!
    If you understand what you're doing, you're not learning anything.

  8. #8
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    thanks for that link! finally, I can be sure what a LONG_PTR and a HANDLE is (though not quite since I don't know what FVOID is...)

    It's not that I'm trying to be a Peeping Tom or anything, but let's face it nobody likes a tease: API functions will constantly throw about the phrases "assign an application-defined value to the lParam" or "make a value into a DWORD", without ever explicitly telling you what this is or can be. Quite frankly if I could simply make *anything* a DWORD or a WORD then I wouldn't much care, but the reason why I need to know exactly what those are is so that I know what I can legally assign to them. Of course I found this out the hard way some time back when I tried to pass an entire structure through an lParam....
    black-boxing code is nice, but black-boxing helpful documentation... not so nice

  9. #9
    Registered User
    Join Date
    Aug 2006
    Posts
    3
    thank you guys for helping me

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hangman game and strcmp
    By crazygopedder in forum C Programming
    Replies: 12
    Last Post: 11-23-2008, 06:13 PM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 04:06 PM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 06:49 PM
  4. Passing structures to a function
    By earth_angel in forum C++ Programming
    Replies: 5
    Last Post: 07-13-2005, 07:13 AM
  5. length of string etc.
    By Peachy in forum C Programming
    Replies: 5
    Last Post: 09-27-2001, 01:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21