Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Blocking process call

0 views
Skip to first unread message

Dario Salvi

unread,
Sep 18, 2006, 5:49:21 AM9/18/06
to
Hi,


I am developing an application for PocketPC 2003 and Windows Mobile5 written
in C++.

I need to start a process (the wceload exactly) and I would like to block
the calling application until the process has ended.

I am using the CreateProcess function.

Any suggestion?

Thanks.

D.


Michael J. Salamone

unread,
Sep 18, 2006, 11:13:32 AM9/18/06
to
You can wait on the process handle returned from CreateProcess.
WaitForSingleObject(PROCESS_INFO.hProcess, INFINITE). You'll come out of
the wait when the process terminates.

--
Michael Salamone [eMVP]
Entrek Software, Inc.
www.entrek.com


"Dario Salvi" <dsa...@lst.tfo.upm.es> wrote in message
news:450e...@news.upm.es...

Dario Salvi

unread,
Sep 19, 2006, 11:23:19 AM9/19/06
to
> You can wait on the process handle returned from CreateProcess.
> WaitForSingleObject(PROCESS_INFO.hProcess, INFINITE). You'll come out of
> the wait when the process terminates.


it worked !

great !


Some code:
HANDLE findfile = FindFirstFile(FileName,&ffile);

LPPROCESS_INFORMATION procInf;

procInf = new PROCESS_INFORMATION;

CreateProcess( L"\\Windows\\wceload.exe", L" /noui /nodelete
\\\%s\\Installations\\%s\", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
procInf))


WaitForSingleObject((*procInf).hProcess, INFINITE);


Michael J. Salamone

unread,
Sep 20, 2006, 7:07:04 AM9/20/06
to
Uh, no reason to allocate PROCESS_INFORMATION from the heap - just allocate
it on the stack.

If you do allocate from the heap, don't forget to check that you actually
got some memory - and to free it! Check the return from CreateProcess, too.

And, make sure you close the hProcess and hThread handles returned in
PROCESS_INFORMATION.

Some better code:

HANDLE findfile = FindFirstFile(FileName,&ffile);
PROCESS_INFORMATION procInf;

if (CreateProcess(L"\\Windows\\wceload.exe", L" /noui /nodelete

\\\%s\\Installations\\%s\", NULL, NULL, NULL, NULL, NULL, NULL, NULL,

&procInf))
{
WaitForSingleObject(procInf.hProcess, INFINITE);

CloseHandle(procInf.hProcess);
CloseHandle(procInfo.hThread);
}

Check return from FindFirstFile, too! And close with FindClose.

--
Michael Salamone [eMVP]
Entrek Software, Inc.
www.entrek.com


"Dario Salvi" <dsa...@lst.tfo.upm.es> wrote in message

news:4510...@news.upm.es...

0 new messages