Solved

GetCurrentThread fails!!?

Posted on 1997-10-28
4
441 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

786 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