Article View: borland.public.cppbuilder.nativeapi
Article #1382Re: CreateProcess() in Automation server freezes caller
From: Ed Mulroy [TeamB]
Date: Tue, 11 Sep 2007 13:24
Date: Tue, 11 Sep 2007 13:24
116 lines
4747 bytes
4747 bytes
This is only a guess but you might try creating a thread in which you do the
CreateProcess. I expect the result to be Windows apportioning time slices
between threads and therefore allowing the main thread mouse and keyboard
messages to flow.
. Ed
> Wiebe Vos wrote in message
> news:46e69558$1@newsgroups.borland.com...
>
> (BCB6+SP4)
> I'm succesfully launching a thirdparty program via CreateProcess()
> in a COM automation server. The latter is called from our main
> application (which is also a COM automation server so both programs
> can exchange information).
> The problem I face is that, during the execution of the thirdparty
> program, the
> main application is completely blocked. No mouse- and keyboardactions are
> possible. (Other application are not affected...).
>
> How can I avoid this?
>
> Thanks in advance,
> Wiebe
>
> The code launching the thirdparty program:
> //---------------------------------------------------------------------------
> // ret=false is Succesfull
> // DoDownload ( char *path, char *command, bool wait=true )
> //------------
> bool FBaseDownloader::DoDownload ( char *path, char *command, bool wait )
> {
> bool ret=true, exit=false;
> AnsiString s;
> STARTUPINFO startUpInfo={sizeof(STARTUPINFO), 0};
> PROCESS_INFORMATION processInfo={0};
> while ( exit EQ false )
> {
> exit = true;
> Log ( "Start Download" );
> if ( FileExists ( path ) EQ false )
> {
> Beep();
> s = (AnsiString)"FOUT: Downloader: " + path + " niet aanwezig...";
> Log(s);
> ShowMessage(s);
> break;
> }
> if ( CreateProcess (
> path,
> command,
> NULL,
> NULL,
> false,
> CREATE_DEFAULT_ERROR_MODE,
> NULL,
> VendorDir,
> &startUpInfo,
> &processInfo ) EQ true )
> {
> // Disabled-------->> MsgWaitForMultipleObjects() + Sleep(0) does not cure
> the problem!
> // TMsg msg;
> // DWORD wRet;
> // int test=WAIT_OBJECT_0;
> // do
> // {
> // Sleep(0);
> // wRet = MsgWaitForMultipleObjects
> // (
> // 1, // 1 handle to wait on
> // &processInfo.hProcess, // the handle
> // false, // wake on any event
> // INFINITE, // wait without timeout
> // QS_PAINT | // wake on paint messages
> // QS_SENDMESSAGE // or messages from other threads
> // );
> // if ( wRet EQ WAIT_FAILED )
> // break; // can do little here
> // if ( wRet EQ (WAIT_OBJECT_0 + 1) )
> // {
> // while ( PeekMessage( &msg, 0, WM_PAINT, WM_PAINT,
> PM_REMOVE ) )
> // DispatchMessage ( &msg );
> // }
> // }
> // while ( wRet NEQ WAIT_OBJECT_0 );
> // ------------------------------------------------------<<
> WaitForSingleObject ( processInfo.hProcess, wait
> ? 60*1000
> : 0 );
> CloseHandle( processInfo.hProcess );
> CloseHandle( processInfo.hThread );
> ret = false;
> }
> else
> {
> LPVOID lpMsgBuf;
> FormatMessage(
> FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
> NULL,
> GetLastError(),
> MAKELANGID(LANG_DUTCH, SUBLANG_DUTCH), // Default language
> (LPTSTR) &lpMsgBuf,
> 0,
> NULL );
> s = (AnsiString)"FOUT: Download:" + path + "\n" + (char*)lpMsgBuf;
> Log(s);
> Beep();
> ShowMessage(s);
> LocalFree( lpMsgBuf );
> }
> Log ( "End Download" );
> }
> return ret;
> }
Technical Details
Message-ID:
<46e69728$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<46e69558$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,ab74d8f845bd4978,start X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket> Newsgroups: borland.public.cppbuilder.nativeapi References: <46e69558$1@newsgroups.borland.com> Subject: Re: CreateProcess() in Automation server freezes caller Date: Tue, 11 Sep 2007 09:24:52 -0400 Lines: 118 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138 X-RFC2646: Format=Flowed; Response NNTP-Posting-Host: 66.57.114.44 Message-ID: <46e69728$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1189517096 66.57.114.44 (11 Sep 2007 06:24:56 -0700) X-Authenticated-User: edmulroy Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail