471,577 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,577 software developers and data experts.

GetCurrentThread not returning correct handle

Hi all,
I tried using GetCurrentThread to get the Handle of the current thread
but it keeps returning 0xfffffffe for all the threads that I access it
in. This is not the correct handle. Am I missing any prerequisite
calls or something else?

Regards,

...ab

Jun 7 '07 #1
4 8654
>I tried using GetCurrentThread to get the Handle of the current thread
>but it keeps returning 0xfffffffe for all the threads that I access it
in. This is not the correct handle. Am I missing any prerequisite
calls or something else?
GetCurrentThread returns a pseudo handle - "a special constant that is
interpreted as the current thread handle".

What's your problem with it?

Dave
Jun 7 '07 #2
<ot****@gmail.comwrote in message
news:11**********************@g4g2000hsf.googlegro ups.com...
Hi all,
I tried using GetCurrentThread to get the Handle of the current thread
but it keeps returning 0xfffffffe for all the threads that I access it
in. This is not the correct handle. Am I missing any prerequisite
calls or something else?
Adding to David's reply, you can get a real handle for the current thread by
using DuplicateHandle, passing GetCurrentThread() as the source handle
value. You are then responsible for (eventually) closing the handle
returned by DuplicateHandle.

If you created the current thread yourself, the handle is returned by
CreateThread or _beginthreadex. If you didn't create the thread, then
GetCurrentThread/DuplicateHandle is the way to go.

-cd
Jun 7 '07 #3
On Thu, 07 Jun 2007 09:54:24 -0700, ot****@gmail.com wrote:
>Hi all,
I tried using GetCurrentThread to get the Handle of the current thread
but it keeps returning 0xfffffffe for all the threads that I access it
in. This is not the correct handle. Am I missing any prerequisite
calls or something else?
The documentation explains everything:

GetCurrentThread
http://msdn2.microsoft.com/en-us/library/ms683182.aspx

--
Doug Harrison
Visual C++ MVP
Jun 7 '07 #4
On Jun 7, 9:54 pm, ote...@gmail.com wrote:
Hi all,
I tried using GetCurrentThread to get the Handle of the current thread
but it keeps returning 0xfffffffe for all the threads that I access it
in. This is not the correct handle. Am I missing any prerequisite
calls or something else?

Regards,

..ab
(oops, whenever i post from the google groups i always forget to come
back looking for a reply ... too bad my outlook express is not working
due to some firewall issues.)

Thanks for the reply guys. I understand now finally what u guys have
told me. I actually wanted the handles cuz I wanted to pass them in
the waitformultipleobjects function. MSDN sometimes talks in a way
that my kind of less-knowledged people dont seem to get it and all
thats needed is a little bit extra info in easy to understand english
sentences (where you guys come in) :).

Thanks all.

...ab

Jun 10 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by agarrettb | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Vinnie | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.