Announcement

Collapse
No announcement yet.

Method handle()

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

  • Method handle()

    Can anyone please give me an example how to read the handle on a thread from withing the thread function

  • #2
    pass the pointer to hThread in
    THREAD FUNCTION

    The variable exists before CREATE THREAD populates it with handle value.

    A pointer to it won't change when populated.

    Cheers,
    Dale

    Comment


    • #3
      I have not tested, but GetCurrentThread seems to do the job.

      https://docs.microsoft.com/en-us/win...tcurrentthread
      The return value is a pseudo handle for the current thread.

      A pseudo handle is a special constant that is interpreted as the current thread handle.
      The calling thread can use this handle to specify itself whenever a thread handle is required.


      Comment


      • #4
        GetCurrentThread Gives a different value to the actual THREAD_HANDLE when this is executed

        THREAD CREATE CONNECTION_HANDLING( SOCKET_FILE_NO ) TO THREAD_HANDLE

        I need to be able to determine THREAD_HANDLE from within the actual thread itself

        Comment


        • #5
          Yes it is a pseudo handle, but the page also says,

          The function (GetCurrentThread) cannot be used by one thread to create a handle that can be used by other threads to refer to the first thread.
          The handle is always interpreted as referring to the thread that is using it.
          A thread can create a "real" handle to itself that can be used by other threads, or inherited by other processes, by specifying the pseudo handle as the source handle in a call to the DuplicateHandle function.

          Comment


          • #6
            I'm a bit lost on this one

            In a test program I created a thread and the handle was 564 and the value returned in the thread using GetCurrentThread was 4294967294

            Comment


            • #7
              Originally posted by Steve Bouffe View Post
              I'm a bit lost on this one

              In a test program I created a thread and the handle was 564 and the value returned in the thread using GetCurrentThread was 4294967294
              Hmmm, interesting value. That's just one less than the max value of a DWORD

              Comment

              Working...
              X