Announcement

Collapse
No announcement yet.

WaitForSingleObject

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

  • WaitForSingleObject

    Hello,

    I use WaitForSingleObject to control a looped thread.
    Under some circumstances WaitForSingleObject returns the value -1.
    What is this value for?

    Thanks
    Joerg
    Joerg Koehler

  • #2
    The problems sit in front of the computer :-)
    If I declare the return value as DWORD, the return value of -1
    becomes %WAIT_FAILED....

    Thx
    Joerg
    Joerg Koehler

    Comment


    • #3
      From the SDK docs: "'If the function fails, the return value is WAIT_FAILED. To get extended error information, call GetLastError".

      From WIN32API.INC: %WAIT_FAILED = &HFFFFFFFF??? ( ie -1& )
      Rgds, Dave

      Comment


      • #4
        Avoid Long/DWORD problems like this with...

        Code:
         LOCAL iret   AS  LONG or DWORD 
        
           iRet  = WaitForSingleObject (hObj, TimeOutVal) 
           SELECT CASE AS LONG iret 
               CASE %WAIT_OBJECT_0 
               CASE %WAIT_TIMEOUT
               CASE %WAIT_FAILED
        SELECT CASE AS LONG does 32-bit comparisons; SELECT CASE does signed comparisons (PB/WIn 7+ only. Prior versions always did 32-bit compares).

        FWIW, "SELECT CASE AS LONG" also executes more quickly than "SELECT CASE", not that it would be terribly significant in this case.




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

        Comment


        • #5
          Thanks guys!

          @Micheal
          Haven't heard about SELECT CASE AS LONG before.
          I'll respect this in the future.

          Joerg
          Joerg Koehler

          Comment


          • #6
            "AS LONG" is the ONLY way to go in message-processing loops; this becomes really significant when working with any of the Microsoft Common Controls (listview, treeview, header, etc), as almost all the 'notification codes' passed in the NMHDR.code value in lparam of the WM_NOTIFY message are "negative" when viewed as signed.

            I see that in PB/Win 9x there is also now a function to deal with signed comparisons: the BITSE function.

            No Pb/Win 9x or CC/5x?

            Code:
            MACRO eq32 (a, b) =  BITS???(a) = BITS???(b) 
            ...
                IF eq32 (X, Y) THEN ...
            (Macro courtesy Tom Hanlin, a long time ago, right here).

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

            Comment


            • #7
              Duh.

              I guess renaming that MACRO BITSE might make some sense, wouldn't it?

              Would sure make upgrading to CC/5 or Win/9 a bit easier.
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment

              Working...
              X