Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

GetCurrentThread fails!!?

Posted on 1997-10-28
4
Medium Priority
?
474 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
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…

876 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