Article View: borland.public.cppbuilder.nativeapi
Article #1383CreateProcess() in Automation server freezes caller
From: Wiebe Vos
Date: Tue, 11 Sep 2007 13:17
Date: Tue, 11 Sep 2007 13:17
107 lines
4155 bytes
4155 bytes
Hi,
(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:
<46e69558$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-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,ab74d8f845bd4978 X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Wiebe Vos" <wiebe@foxware.nl> Newsgroups: borland.public.cppbuilder.nativeapi Subject: CreateProcess() in Automation server freezes caller Date: Tue, 11 Sep 2007 15:17:09 +0200 Lines: 109 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; Original NNTP-Posting-Host: 62.131.171.202 Message-ID: <46e69558$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1189516632 62.131.171.202 (11 Sep 2007 06:17:12 -0700) 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