CreateProcess issue
-
I am using the following code in order to start an MFC Win application from another MFC win application that is currently running: int CTransfer::StartNewProcess(CString szNewProcess) { STARTUPINFO si; PROCESS_INFORMATION pi; char szProcess[128]; szNewProcess += ".exe"; strcpy(szProcess , (LPCTSTR)szNewProcess); ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); // Start the child process. if( !CreateProcess( NULL, // No module name (use command line). szProcess, // Command line. NULL, // Process handle not inheritable. NULL, // Thread handle not inheritable. TRUE, // Set handle inheritance to FALSE. NORMAL_PRIORITY_CLASS, // No creation flags. NULL, // Use parent's environment block. NULL, // Use parent's starting directory. &si, // Pointer to STARTUPINFO structure. &pi ) // Pointer to PROCESS_INFORMATION structure. ) { return 1; } // Wait until child process exits. WaitForSingleObject( pi.hProcess, INFINITE ); // Close process and thread handles. CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); return 0; } The idea is that while the called window (modal) will be open the caller/creator will wait inactive until the user exits. This code will work with no issue under Win2000 and VS 2003. When I converted the projects to VS 2005 and I run them under Win 2003 I have the following strange bahaviour. The new window will show up but after a few seconds the caller will start processing/doing something because the mouse cursor will change to an hourglass. In addition to that in the Task Manager I can see two instances of the caller. So when I do Goto Process for each one of them, one will point to the caller.exe and the second one will point to the explorer.exe. I even created two new projects, because I thought that the conversion of the projects from 2003 to 2005 had the problem, but the bahviour is the same. If you have any idea / suggestion please let me know. Thank you in advance for your time. Spiros Prantalos Miami the place to be!!
-
I am using the following code in order to start an MFC Win application from another MFC win application that is currently running: int CTransfer::StartNewProcess(CString szNewProcess) { STARTUPINFO si; PROCESS_INFORMATION pi; char szProcess[128]; szNewProcess += ".exe"; strcpy(szProcess , (LPCTSTR)szNewProcess); ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); // Start the child process. if( !CreateProcess( NULL, // No module name (use command line). szProcess, // Command line. NULL, // Process handle not inheritable. NULL, // Thread handle not inheritable. TRUE, // Set handle inheritance to FALSE. NORMAL_PRIORITY_CLASS, // No creation flags. NULL, // Use parent's environment block. NULL, // Use parent's starting directory. &si, // Pointer to STARTUPINFO structure. &pi ) // Pointer to PROCESS_INFORMATION structure. ) { return 1; } // Wait until child process exits. WaitForSingleObject( pi.hProcess, INFINITE ); // Close process and thread handles. CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); return 0; } The idea is that while the called window (modal) will be open the caller/creator will wait inactive until the user exits. This code will work with no issue under Win2000 and VS 2003. When I converted the projects to VS 2005 and I run them under Win 2003 I have the following strange bahaviour. The new window will show up but after a few seconds the caller will start processing/doing something because the mouse cursor will change to an hourglass. In addition to that in the Task Manager I can see two instances of the caller. So when I do Goto Process for each one of them, one will point to the caller.exe and the second one will point to the explorer.exe. I even created two new projects, because I thought that the conversion of the projects from 2003 to 2005 had the problem, but the bahviour is the same. If you have any idea / suggestion please let me know. Thank you in advance for your time. Spiros Prantalos Miami the place to be!!
Why are you using
szProcess
andstrcpy()
? They are completely unnecessary. Just passszNewProcess
directly toCreateProcess()
.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
-
I am using the following code in order to start an MFC Win application from another MFC win application that is currently running: int CTransfer::StartNewProcess(CString szNewProcess) { STARTUPINFO si; PROCESS_INFORMATION pi; char szProcess[128]; szNewProcess += ".exe"; strcpy(szProcess , (LPCTSTR)szNewProcess); ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); // Start the child process. if( !CreateProcess( NULL, // No module name (use command line). szProcess, // Command line. NULL, // Process handle not inheritable. NULL, // Thread handle not inheritable. TRUE, // Set handle inheritance to FALSE. NORMAL_PRIORITY_CLASS, // No creation flags. NULL, // Use parent's environment block. NULL, // Use parent's starting directory. &si, // Pointer to STARTUPINFO structure. &pi ) // Pointer to PROCESS_INFORMATION structure. ) { return 1; } // Wait until child process exits. WaitForSingleObject( pi.hProcess, INFINITE ); // Close process and thread handles. CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); return 0; } The idea is that while the called window (modal) will be open the caller/creator will wait inactive until the user exits. This code will work with no issue under Win2000 and VS 2003. When I converted the projects to VS 2005 and I run them under Win 2003 I have the following strange bahaviour. The new window will show up but after a few seconds the caller will start processing/doing something because the mouse cursor will change to an hourglass. In addition to that in the Task Manager I can see two instances of the caller. So when I do Goto Process for each one of them, one will point to the caller.exe and the second one will point to the explorer.exe. I even created two new projects, because I thought that the conversion of the projects from 2003 to 2005 had the problem, but the bahviour is the same. If you have any idea / suggestion please let me know. Thank you in advance for your time. Spiros Prantalos Miami the place to be!!
You are getting a "ghost" of the app. The system will create a dummy window that mimics the original when the original stops processing. Not sure why they did this, but thats the second window you're seeing. It won't actually do anything. Your best bet is to reengineer it so that you don't block in the original app while waiting for the second to close. Maybe disable the application window and start a thread that waits for the second app to finish, then enable everything again.