By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,171 Members | 1,020 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,171 IT Pros & Developers. It's quick & easy.

getting the handle for a thread

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a

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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.