Solved

GetCurrentThread fails!!?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and 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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

919 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

20 Experts available now in Live!

Get 1:1 Help Now