Solved

GetCurrentThread fails!!?

Posted on 1997-10-28
4
432 Views
Last Modified: 2013-12-03
I systematically get -2 when I call GetCurrentThread.
(The Win32 help states that error -2 is LZERROR_BADOUTHANDLE. What does it really mean, as GetCurrentThread "only" returns a pseudo-handle ??
)

As this function returns "only" a pseudo-handle, I try to use the DuplicateHandle function with this -2 as the sourceHandle (the code below is in Delphi2):
if not DuplicateHandle(GetCurrentProcess,GetCurrentThread,GetCurrentProcess,@duplicatedHandle,THREAD_ALL_ACCESS,false,0) then ...

This latest function works fine, but the duplicatedHandle I get in returns is not usable by thread management functions (in my case, TerminateThread).

How can I make the GetCurrentThread functions working?
0
Comment
Question by:poupou
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
vinniew earned 50 total points
ID: 1407943
The pseudo-handle, if I remember correctly, is only so that you can retrieve information about some thread.  You still can't screw around with it, though (i.e. terminate it).

If you want to get the *real* thread handle, you should look in the performance data of the registry, and iterate through all that (fun.)

Sorry, I don't have source for doing that, but you might find it in the old MSDN's.  MS has taken the example I used to use out of their current MSDN (it was named task something or other).

Hasta,
V

0
 

Author Comment

by:poupou
ID: 1407944
thanks for your help vinniew, but the registry is worth only for processes.
there should be a mean to use correctly this GetCurrentThread function.
Is my problem due to Delphi2? Anyone using C experienced the same result?
0
 
LVL 3

Expert Comment

by:vinniew
ID: 1407945
What I usually do is create a struct with all this information and pass a pointer to the struct to the thread.  What are you trying to do?  Why wouldn't C-runtime _enthread() work?  What environment do you have?  AfxBeginThreadProc returns a thread handle.  You can definitely use that.

Hasta,
V

0
 

Author Comment

by:poupou
ID: 1407946
Yes, that's what I do now:
I pass a structure to the newly created thread (in suspended mode). And I fill one of its field with the handle result of the CreateThread function.
Then I ResumeThread with this handle.
Thanks for your quick answer.

But nevertheless, what about this hells GetCurrentThread function? Has it works only once?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now