Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2007

Tip: Looking for answers? Try searching our database.

GetCurrentThread not returning correct handle

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
otengo@gmail.com - 07 Jun 2007 17:54 GMT
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
David Lowndes - 07 Jun 2007 18:50 GMT
>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
Carl Daniel [VC++ MVP] - 07 Jun 2007 18:54 GMT
> 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
Doug Harrison [MVP] - 07 Jun 2007 19:39 GMT
>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

Signature

Doug Harrison
Visual C++ MVP

otengo@gmail.com - 10 Jun 2007 13:26 GMT
On Jun 7, 9:54 pm, ote...@gmail.com wrote:
> Hi all,
> I tried using GetCurrentThread to get the Handle of the current thread
[quoted text clipped - 5 lines]
>
> ..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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.