Article View: borland.public.cppbuilder.nativeapi
Article #14752Re: active thread list
From: Boguslaw Fries
Date: Fri, 01 Aug 2003 09:23
Date: Fri, 01 Aug 2003 09:23
60 lines
2700 bytes
2700 bytes
Of course yes. This is the best way.
But I have to try another one :
Please analyse my function and consider I have Windows 2000 and Borland
Builder C++ 3.0
bool TForm1::ThreadList( void )
{
THREADENTRY32 threadEntry;
HANDLE hSnapShot;
HANDLE hResult;
unsigned long myProcessID;
char s_raport[ 256 ];
myProcessID = GetCurrentProcessId( );
::ZeroMemory( & threadEntry, sizeof( THREADENTRY32 ) );
threadEntry.dwSize = sizeof( THREADENTRY32 );
hSnapShot = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 );
if( hSnapShot == INVALID_HANDLE_VALUE )
{
return false;
}
if( !Thread32First( hSnapShot, &threadEntry ))
{
CloseHandle( hSnapShot );
return false;
}
do
{
if( threadEntry.th32OwnerProcessID == myProcessID )
{
// this is my error as I think, but why OpenThread
// as written in
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/openthread.asp
// does not exists????
// here simply the running thread are not killed :(
hResult = OpenProcess( SYNCHRONIZE | PROCESS_TERMINATE, true,
threadEntry.th32ThreadID ); // <--------------------------
PostMessage( hResult, WM_CLOSE, 0, 0 );
if( WaitForSingleObject( hResult, 5000 ) != WAIT_OBJECT_0 )
{
TerminateProcess( hResult, 0 );
}
CloseHandle( hResult );
}
}
while( Thread32Next( hSnapShot, &threadEntry ));
CloseHandle( hSnapShot );
return true;
}
//--------------------------------------------------------------------------
-
Best regards
Boguslaw Fries
Technical Details
Message-ID:
<3f2a318c$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-05!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!in.100proofnews.com!in.100proofnews.com!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3f2a0a30$1@newsgroups.borland.com> <3f2a0afb$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,30ec7a3d72e3790e X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-08-01 02:32:17 PST From: "Boguslaw Fries" <B.Fries@luca-online.de> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f2a0a30$1@newsgroups.borland.com> <3f2a0afb$1@newsgroups.borland.com> Subject: Re: active thread list Date: Fri, 1 Aug 2003 11:23:17 +0200 Lines: 62 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 217.225.45.188 Message-ID: <3f2a318c$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1059729804 217.225.45.188 (1 Aug 2003 02:23:24 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-05!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!in.100proofnews.com!in.100proofnews.com!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail