CreateProcess...
David Little -- dlittle@communique.net
Wednesday, September 11, 1996
Environment: VC++ 4.2, Win 95
One of my customers called and said that a program I wrote was "leaving
a white spot everywhere I move it." I took this to mean that it wasn't
properly painting, but it works fine. He thinks that I am using
CreateProcess wrong, so somebody tell me:
void CMainFrame::OnRunNotepad()
{
STARTUPINFO StartupInfo = {0};
PROCESS_INFORMATION ProcessInfo;
StartupInfo.cb = sizeof(STARTUPINFO);
// blah, blah, blah.....
CString szCommandLine;
szCommandLine = "QUICKWINAPP.EXE";
if (CreateProcess(NULL, szCommandLine, NULL, NULL, FALSE,
0, NULL, NULL, &StartupInfo, &ProcessInfo))
{
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
SetCurrentDirectory(savePath);
ShowWindow(SW_RESTORE);
EnableWindow(TRUE);
AfxMessageBox("I finished");
}
else
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0,
NULL );
// Display the string.
::MessageBox( NULL,
(LPTSTR)lpMsgBuf,
"Create Process",
MB_OK|MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );
ShowWindow(SW_RESTORE);
EnableWindow(TRUE);
// blah, blah, blah
}
See any problems? If you do, let me know...
Thanks!
David
Barry Tannenbaum -- barry@dddv.com
Thursday, September 12, 1996
[Mini-digest: 2 responses]
At 12:02 PM 9/11/96 -0500, you wrote:
>Environment: VC++ 4.2, Win 95
>
>One of my customers called and said that a program I wrote was "leaving
>a white spot everywhere I move it." I took this to mean that it wasn't
>properly painting, but it works fine. He thinks that I am using
>CreateProcess wrong, so somebody tell me:
>
>void CMainFrame::OnRunNotepad()
>{
> STARTUPINFO StartupInfo = {0};
> PROCESS_INFORMATION ProcessInfo;
> StartupInfo.cb = sizeof(STARTUPINFO);
>
> // blah, blah, blah.....
> CString szCommandLine;
> szCommandLine = "QUICKWINAPP.EXE";
>
> if (CreateProcess(NULL, szCommandLine, NULL, NULL, FALSE,
> 0, NULL, NULL, &StartupInfo, &ProcessInfo))
> {
> WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
> SetCurrentDirectory(savePath);
> ShowWindow(SW_RESTORE);
> EnableWindow(TRUE);
> AfxMessageBox("I finished");
> }
> else
> {
> LPVOID lpMsgBuf;
>
> FormatMessage(
> FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
> NULL,
> GetLastError(),
> MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
> (LPTSTR) &lpMsgBuf,
> 0,
> NULL );
>
> // Display the string.
> ::MessageBox( NULL,
> (LPTSTR)lpMsgBuf,
> "Create Process",
> MB_OK|MB_ICONINFORMATION );
>
> // Free the buffer.
> LocalFree( lpMsgBuf );
> ShowWindow(SW_RESTORE);
> EnableWindow(TRUE);
>
> // blah, blah, blah
> }
You're leaking handles for the process and the thread. Add this just after
the call to WaitForSingleObject:
::CloseHandle (ProcessInfo.hProcess);
::CloseHandle (ProcessInfo.hThread);
- Barry
--------------------------------------------------------------------------------
3DV Technology, Inc Phone: (603) 595-2200 X228
410 Amherst St., Suite 150 Fax: (603) 595-2228
Nashua, NH 03063 Net: barry@dddv.com
-----From: Scott Andrew
The calling application is idle until the applicaion you spawn closes. One
thing that you can do
is stick it in a while loop and call sleep in the loop this should work.
Scott Andrew
| Вернуться в корень Архива
|