Article View: borland.public.cppbuilder.nativeapi
Article #5647Re: SendMessage() repetition error
From: Daniel Stevenson
Date: Fri, 29 Jul 2005 07:55
Date: Fri, 29 Jul 2005 07:55
64 lines
2856 bytes
2856 bytes
Thanks Remy,
I wasn't expecing a response to this after I found the cause of the initial
problem (hence my long delay in seeing this message and responding) but I
appreciate your feedback, It definately looks a lot simpler and easier than
my existing code.. I will give it a go.
Thanks
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:42c4a2f3$1@newsgroups.borland.com...
>
> "Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
> news:42c49e3e$1@newsgroups.borland.com...
>
> > An easier, and more reliable, way is to use WaitForSingleObject()
instead.
> > CreateProcess() returns the HANDLE for the newly spawned process. You
> > can pass that HANDLE to WaitForSingleObject(), which will not return
until
> > the process has terminated.
>
> For example:
>
> bool __fastcall RunProgram(const AnsiString &FileName, const
AnsiString
> &Params, bool WaitUntilExit = true)
> {
> AnsiString CmdLine;
> if( Params.IsEmpty() )
> CmdLine = FileName;
> else
> CmdLine = (AnsiQuotedStr(FileName) + " " + Params);
>
> STARTUPINFO si = {sizeof(STARTUPINFO), 0};
> PROCESS_INFORMATION pi = {0};
>
> // fill in si as needed...
>
> if( CreateProcess(FileName.c_str(), CmdLine.c_str(), NULL, NULL,
> FALSE, 0, NULL, NULL, &si, &pi) )
> {
> if( WaitUntilExit )
> WaitForSingleObject(pi.hProcess, INFINITE);
>
> CloseHandle(pi.hThread);
> CloseHandle(pi.hProcess);
>
> return true;
> }
>
> return false;
> }
>
>
> {
> if( RunProgram("c:\\path\\Bubba.exe", "first set of parameters") )
> RunProgram("c:\\path\\Bubba.exe", "second set of parameters");
> }
>
>
> Gambit
>
>
Technical Details
Message-ID:
<42e9e0de$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!newsread.com!newsprint.newsread.com!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.spamkiller.net!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<42c49259@newsgroups.borland.com> <42c49e3e$1@newsgroups.borland.com> <42c4a2f3$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,696995b85f90e7d7 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Daniel Stevenson" <daniel@ocreage.com.au> Newsgroups: borland.public.cppbuilder.nativeapi References: <42c49259@newsgroups.borland.com> <42c49e3e$1@newsgroups.borland.com> <42c4a2f3$1@newsgroups.borland.com> Subject: Re: SendMessage() repetition error Date: Fri, 29 Jul 2005 17:55:11 +1000 Lines: 66 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: 202.174.233.53 Message-ID: <42e9e0de$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1122623710 202.174.233.53 (29 Jul 2005 00:55:10 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!newsread.com!newsprint.newsread.com!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.spamkiller.net!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mail