Hi
How can I stop and run an application programatically
Thanks
Kimo

Re: Stop and run an application? by Denis

Denis
Sun May 09 09:40:59 CDT 2004

Hi Kimo,
You can use the "CreateProcess" function to create the application process
and terminate this process using TerminateProcess.

Since TerminateProcess should be used only in extreme circumstances because
it a kind of "hard kill" of the process and killing can lead to compromising
of the state of global data maintained by DLLs and lost of application data,
you will want to try to shut down the application first by sending the
WM_CLOSE message to it. You can do it by finding the Window Handle of the
application first and posting the WM_CLOSE to it:
HWND hwnd = FindWindow(pszWindowClass, pszTitle); // pszTitle is typically
""
if (hwnd) PostMessage(hwnd, WM_CLOSE, 0, 0);

Of course you need to know the string name of the window class of the
application you want to notify (pszWindowClass). This class name can be
obtained using for example Windows CE Remote Spy++ tool (EVC->Tools->Remote
Spy++). Start Spy and go to View->FindWindow then choose the window on the
emulator's screen.

Regards,
Denis Haenikel



"Kimo" <anonymous@discussions.microsoft.com> schrieb im Newsbeitrag
news:5DB2997E-0B96-43D6-8D81-A62166FD9B31@microsoft.com...
> Hi,
> How can I stop and run an application programatically?
> Thanks,
> Kimo



Re: Stop and run an application? by Denis

Denis
Sun May 09 10:41:35 CDT 2004

Hi again,
Another approach to find the window of the process if you don't know the
window class name but have created the process from your application:

1. After creating of process you have the processId.
2. Then you can iterate all windows in the system and retriving the
processId of the owning process and send
WM_CLOSE to process with the same Id as you obtained during creation of
process.

The code would look like following:
typedef struct {
DWORD dwProcessId;
HWND hWnd;
}my_procinfo_type;

BOOL CALLBACK EnumWindowsProc(HWND hWnd, DWORD lParam)
{
DWORD dwProcessId = 0;
my_procinfo_type *pi = (my_procinfo_type *)lParam;

if (GetWindowThreadProcessId(hWnd, &dwProcessId))
{
if (pi->dwProcessId == dwProcessId)
{
pi->hWnd = hWnd;
return FALSE;
}
}
return TRUE; // continue
}

void MyTerminateProcess(DWORD dwProcessId ) // dwProcessId is obtained from
CreateProcess
{
my_procinfo_type pi;

pi.hWnd = NULL;
pi.dwProcessId = dwProcessId;
EnumWindows((WNDENUMPROC)EnumWindowsProc, (LPARAM)&pi);

if (pi.hWnd)
PostMessage(pi.hWnd, WM_CLOSE, 0,0);
...
// wait 5 second for process
// then call TerminateProcess.
....
}

Regards,
Denis

"Kimo" <anonymous@discussions.microsoft.com> schrieb im Newsbeitrag
news:5DB2997E-0B96-43D6-8D81-A62166FD9B31@microsoft.com...
> Hi,
> How can I stop and run an application programatically?
> Thanks,
> Kimo



RE: Stop and run an application? by ElecNews

ElecNews
Sun May 09 21:51:07 CDT 2004

To join problem.
The "CreateProcess" function to useing with eVC++ ?