Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

GetCurrentThread fails!!?

Posted on 1997-10-28
4
Medium Priority
?
462 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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 …
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

688 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