Article View: borland.public.cppbuilder.nativeapi
Article #2835Re: Launching notepad etc
From: Dennis Jones
Date: Wed, 03 Jan 2007 18:44
Date: Wed, 03 Jan 2007 18:44
81 lines
3477 bytes
3477 bytes
"Colin B Maharaj" <noreply@myhost.com> wrote in message
news:459a3b8f$1@newsgroups.borland.com...
> If I stop my application (in the BCB IDE) my
> application does not close unless all called processes
> are stopped.
If it's of any use to you, here is a function I wrote to handle various ways
of invoking external processes:
//---------------------------------------------------------------------------
static bool StartProcess( LPCSTR lpszImageName,
LPCSTR lpszCommandLine,
bool bWaitFinish=true,
PHANDLE phProcess=NULL,
DWORD *pProcessId=NULL,
PHANDLE phThread=NULL,
DWORD *pThreadId=NULL,
DWORD *pExitCode=NULL )
{
DWORD dwExitCode = 0;
/* Structures necessary for open/close process */
PROCESS_INFORMATION ProcInfo;
STARTUPINFO StartInfo;
memset( &StartInfo, 0, sizeof(STARTUPINFO) );
StartInfo.cb = sizeof(STARTUPINFO);
if (!CreateProcess( (LPSTR)lpszImageName,
(LPSTR)lpszCommandLine,
NULL,
NULL,
TRUE,
DETACHED_PROCESS|NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&StartInfo,
&ProcInfo ))
{
return false;
}
else
{
if ( phProcess != NULL ) *phProcess = ProcInfo.hProcess;
if ( phThread != NULL ) *phThread = ProcInfo.hThread;
if ( pProcessId != NULL ) *pProcessId = ProcInfo.dwProcessId;
if ( pThreadId != NULL ) *pThreadId = ProcInfo.dwThreadId;
if ( bWaitFinish ) // if we want to wait for this process to complete
before returning
{
if ( WaitForSingleObject( ProcInfo.hProcess, INFINITE) !=
WAIT_FAILED )
{
GetExitCodeProcess( ProcInfo.hProcess, &dwExitCode );
}
CloseHandle( ProcInfo.hProcess );
ProcInfo.hProcess = NULL;
CloseHandle( ProcInfo.hThread );
ProcInfo.hThread = NULL;
}
else
{
if ( phProcess == NULL )
{
CloseHandle( ProcInfo.hProcess );
ProcInfo.hProcess = NULL;
}
if ( phThread == NULL )
{
CloseHandle( ProcInfo.hThread );
ProcInfo.hThread = NULL;
}
}
}
if ( pExitCode != NULL ) *pExitCode = dwExitCode;
return true;
}
//---------------------------------------------------------------------------
- Dennis
Technical Details
Message-ID:
<459bf95c$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.germany.com!newsfeed.cw.net!cw.net!news-FFM2.ecrc.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<459a3b8f$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,fec586f4dcaf98b5 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Dennis Jones" <nospam@nospam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <459a3b8f$1@newsgroups.borland.com> Subject: Re: Launching notepad etc Date: Wed, 3 Jan 2007 10:44:24 -0800 Lines: 83 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3028 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-RFC2646: Format=Flowed; Response NNTP-Posting-Host: 71.245.109.58 Message-ID: <459bf95c$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1167849820 71.245.109.58 (3 Jan 2007 10:43:40 -0800) Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.germany.com!newsfeed.cw.net!cw.net!news-FFM2.ecrc.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail