Announcement

Collapse
No announcement yet.

GetMessage

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • GetMessage

    I did a quick search and found most source code does not check for an error condition when calling GetMessage.

    http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

    Any particular reason for the omission?

    James

  • #2
    Probably because about the only ways to get a failure are ...
    1. Invalid hWnd
    2. Bad PTR to MSG structure

    .. neither of which are likely to occur, assuming the programmer is still breathing when he writes the code.

    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      I can't think of any good reason not to follow the Microsoft recommendation. The function returning zero, nonzero, and -1 reminds me of my friends telling me to use my "other left". A function defined as BOOL really is a curious choice to use for a triple valued function return.

      Chuck

      Comment


      • #4
        Funny that you bring it up because earlier tonight I was revisiting the same things.....all (most if not all examples) tend to use
        Code:
        While GetMessage(WindowsMsg, %NULL, 0, 0)
        
        WEND
        or
        Code:
        While GetMessage(WindowsMsg, %NULL, 0, 0) <> 0
        
        WEND
        But then I found that in debugger I got a confusing thing of the debugger would stop at the WEND if there was no message.

        To me that looked like a flaw (sure no message? but why stop looping to look for a message????

        Now the docs at MSDN say
        If the function retrieves a message other than WM_QUIT, the return value is nonzero.
        If the function retrieves the WM_QUIT message, the return value is zero.
        If there is an error, the return value is -1. For example, the function fails if hWnd is an invalid window handle or lpMsg is an invalid pointer. To get extended error information, call GetLastError.
        which to me reads as
        If the function retrieves a message other than WM_QUIT, the return value is nonzero.
        = Non Zero = TRUE (Boolean or otherwise)
        If there is an error, the return value is -1. For example, the function fails if hWnd is an invalid window handle or lpMsg is an invalid pointer. To get extended error information, call GetLastError.
        = Non Zero = TRUE (Boolean or otherwise) BUT in this case is an error, so if the While does not check for an error it is wrong

        confusing part is when
        If the function retrieves the WM_QUIT message, the return value is zero.
        = ZERO = %FALSE = Somewhere in further checks (if you bother to check the msg.MESSAGE will = %WM_QUIT)

        I am as guilty as others for not checking (since when did I find an error in the message? Or was it a quit???) But lately when I get time I am trying to correct my errors of the past (either from not knowing, or misreading docs, or taking samples at face value) and wonder why examples should not involve a FULLLLLLllll check of not only what the return value is, but does the return value also have a "Sure it's TRUE....but in your case you did not bother to check WHYYYYyyy its TRUE???? )
        Engineer's Motto: If it aint broke take it apart and fix it

        "If at 1st you don't succeed... call it version 1.0"

        "Half of Programming is coding"....."The other 90% is DEBUGGING"

        "Document my code????" .... "WHYYY??? do you think they call it CODE? "

        Comment


        • #5
          Cliff, no one software vendor has a monopoly on poor documentation.

          For the most part we can all pretty much figure out what it means, since documenters generally don't even try to use words with more than eight letters or two syllables, since they don't know any.
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment

          Working...
          X