473,325 Members | 2,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

getting the handle for a thread

I have a bunch of threads created with CreateThread(). When each thread
is exiting, it posts a message saying that it's about to quit. I'd like
to do the CloseHandle() on the thread handle in that message handler.
But, how can I tell which handle is the one for that particular thread
which just finished? Is there a call like GetThreadHandle() I can use
from within the thread to pass back the same handle I got from
CreateThread() to the message-handler?

Thanks,
PaulH
std::vector<HANDLEm_vThreads;

CMyDlg::StartAThread()
{
THREAD_INFO *pTI = new THREAD_INFO
/*...*/
m_vThreads.push_back(AtlCreateThread(MyThread, pTI);
}

static DWORD __stdcall MyThread(THREAD *pTI)
{
std::auto_ptr<THREADpATI(pTI);
/*...*/
PostMessage(pATTI->hWnd, UWM_FINISHED_TEST, 0, 0);
return 0;
};

CMyDlg::OnFinishedThread(/*...*/, WPARAM wParam, LPARAM lParam)
{
CloseHandle(???);
}

Sep 25 '06 #1
2 3020

PaulH wrote:
I have a bunch of threads created with CreateThread(). When each thread
is exiting, it posts a message saying that it's about to quit. I'd like
to do the CloseHandle() on the thread handle in that message handler.
But, how can I tell which handle is the one for that particular thread
which just finished? Is there a call like GetThreadHandle() I can use
from within the thread to pass back the same handle I got from
CreateThread() to the message-handler?
All of the above is platform specific. You need to ask these questions
in a newsgroup that's subject includes the platform or library you are
using for threading.

Sep 25 '06 #2
PaulH wrote:
I have a bunch of threads created with CreateThread(). When each
thread is exiting, it posts a message saying that it's about to quit.
I'd like to do the CloseHandle() on the thread handle in that message
handler. But, how can I tell which handle is the one for that
particular thread which just finished? Is there a call like
GetThreadHandle() I can use from within the thread to pass back the
same handle I got from CreateThread() to the message-handler?
It seems that you're in a wrong newsgroup. None of the functions you
mention exist in standard C++ language, the topic of this newsgroup.
Perhaps you need to visit 'comp.os.ms-windows.programmer.win32' or some
such...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kong Li | last post by:
Follow up to this thread, the latest Oracle 9i release 2 patchset (9.2.0.5) fixed the handle count leak problem. The problem is in Oracle client component. Thanks. Kong ----- From: Kong...
6
by: Leandro Berti via DotNetMonster.com | last post by:
Hi All, I wrote a code to do serial communication with an equipament. When i use the code outside of threaded class it seens work properly, but when i put inside a class and execute a thread in...
2
by: Gary Wessle | last post by:
Hi I need help organizing this program in the right way. I included the code below which compiles and runs and gives the desired effect to a certain point, but I don't know what the next step...
0
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
I read from a serialport using a worker thread. Because the worker thread t does not loop often, I cannot wait to terminate the worker thread using a boolean in the While condition. So I have a...
18
by: Zytan | last post by:
I have multiple threads writing to WebBrowser (using a function that checks InvokedRequired, and if so, invokes itself on the WebBrowser thread) and they are getting deadlocked. They only...
1
by: ranju | last post by:
I am trying to spawn a process (say an exe file) with different user crendentials than that of the current user. 1) Called LogonUserEx() to logon the user and recieve a handle to the token that...
2
weaknessforcats
by: weaknessforcats | last post by:
Handle Classes Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the...
33
by: JamesB | last post by:
I am writing a service that monitors when a particular app is started. Works, but I need to get the user who is currently logged in, and of course Environment.UserName returns the service logon...
1
by: desivirus | last post by:
hi admin.. i followed your tip in "HOW TO LIST PROCESS ID IN WINDOWS" thread..and iam trying to compile this code in cygwin , $gcc -mno-cygwin process.c -o -L"psapi.lib" process.exe psapi.h...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.