Article View: borland.public.cppbuilder.nativeapi
Article #1224Handle from ThreadId, CreateToolhelp32Snapshot, THREADENTRY32
From: Richard Kavanagh
Date: Thu, 11 Oct 2007 11:59
Date: Thu, 11 Oct 2007 11:59
37 lines
2099 bytes
2099 bytes
One of these days I might understand the Microsoft mind; but not at present.
I use the following function to obtain ThreadId's of all running processes.
I then wish to find out their cpu times using GetThreadTimes. However the
'th32ThreadID' field of the THREADENTRY32 structure is not always the same
32 bit value as the thread's handle, although it seems to be for the a
process's main thread. Is there a way to retrieve the handle from this
structure?
Rivhaed.
// global to function
std::vector<THREADENTRY32> vThread;
bool TProcInfo::GetThreadList()
{
vThread.clear();
HANDLE h = ::CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if(h != INVALID_HANDLE_VALUE)
{
THREADENTRY32 te;
te.dwSize = sizeof(te);
if(::Thread32First(h, &te))
{
do
{
if(te.dwSize >= FIELD_OFFSET(THREADENTRY32, th32OwnerProcessID) +
sizeof(te.th32OwnerProcessID))
{
vThread.push_back(te);
}
te.dwSize = sizeof(te);
} while(::Thread32Next(h, &te));
}
::CloseHandle(h);
}
return h != INVALID_HANDLE_VALUE;
}
Technical Details
Message-ID:
<470e1044$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,41b94c13173582a2,start X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "Richard Kavanagh" <dd.foldhill[at]googlemail.com> From: "Richard Kavanagh" <dd.foldhill[at]googlemail.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Handle from ThreadId, CreateToolhelp32Snapshot, THREADENTRY32 Date: Thu, 11 Oct 2007 12:59:58 +0100 Lines: 39 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 NNTP-Posting-Host: 84.92.225.65 Message-ID: <470e1044$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1192104004 84.92.225.65 (11 Oct 2007 05:00:04 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail