CreateProcess only once.

hi,
In my application I'm using CreateProcess() function in order to invoke the "character map" execution.
By clicking a command from the toolbar, the user opens the characters map.
The problem is that I dont want to allow this operation if the "character map" is already running.

how can I do that ?
Yoav.
yoavoAsked:
Who is Participating?
 
ZoppoConnect With a Mentor Commented:
Hi yoavo,

I agree with VinExpert, but I fear it's not enough for your purpose, because the ( hProcess != NULL ) will even be TRUE if the processe is terminated by a user. But you can use this given handle to find out if the process is still running, i.e.

class CMyApp : ...
{
 HANDLE m_hProcess;
....
}

CMyApp::CMyApp ()
{
 m_hProcess = NULL;
 ...
}

CMyApp::OnOpenCharMap()//message handler for the button
{
 if ( m_hProcess != NULL )
 {
   DWORD exitCode;
   GetExitCodeProcess( m_hProcess, &exitCode );
   if ( exitCode == STILL_ACTIVE )
    return; // charmap is still running
 }
 PROCESS_INFORMATION pi;
 if ( CreateProcess( ..., &pi ) ) // create the process if not running
  m_hProcess = pi.hProcess;
 else
  m_hProcess = NULL;
}

hope that helps,

ZOPPO
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

CreateProcess() uses PROCESS_INFORMATION variable.
In that hProcess member will contain the handle to newly created process U can check for that

if(...hProcess != NULL)
{
     //Open character map
}

For that U may have to make PROCESS_INFORMATION's variable as the member function of that class. Pls see to it that by default and whenever U kill that process or if process not created successfully assign it to NULL.

Try it out.
0
All Courses

From novice to tech pro — start learning today.