Skip to main content
GameDev.net gamedev.net
🔒 Locked

CreateProcess Bombs Out App

Started by jtmerchant Dec 26, 2004 at 1:16 PM 6 replies 600+ views
Original Post
jtmerchant
jtmerchant
This is my test program:
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int iShowCmd)  {
	CreateProcess("C:\\WINDOWS\\system32\\winmine.exe",0,0,0,0,0,0,0,0,0);
	return 1;
}
When I run it, the application closes and gives the "encountered a problem and needs to close. We are sorry for the inconvenience" error. Why does it do this? [Edited by - jtmerchant on December 26, 2004 2:28:42 PM]
iMalc
iMalc
CreateProcess returns without waiting for the new process to finish its initialization. So those string paramaters are disposed when you program exits, but the other program has not yet started - uh oh!

The creating process needs to process windows message for a while and wait for the program to start before it itself exits. You could use WaitForInputIdle before trying to find a window associated with the new process.
jtmerchant
jtmerchant
After experimenting a bit, I have discovered that anything that comes after the call to CreateProcess() doesn't get executed; that means that somewhere in that call is the problem. For example, if I put a call to MessageBox() on the next line like so:
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int iShowCmd)  {	CreateProcess("C:\\WINDOWS\\system32\\winmine.exe",0,0,0,0,0,0,0,0,0);	MessageBox(0,"test","test",MB_OK);	return 1;}

I never see the message box. The program dies before it.
Extrarius
Extrarius
According to MSDN, 0(NULL) is not neccesarily a valid value for the following 3 parameters: dwCreationFlags, lpStartupInfo, and lpProcessInformation

You cannot assume a parameter can be NULL(0) simply beacuse it is a pointer. If MSDN doesn't say the parameter can be NULL (or imply it through statements such as 'if _ is NULL...'), then the API function is not required to work properly when you pass NULL for that parameter.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
jtmerchant
jtmerchant
//Comments are quotes from MSDN link following.int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int iShowCmd)  {	PROCESS_INFORMATION pi;	CreateProcess("C:\\WINDOWS\\system32\\winmine.exe",		0,//"The lpszCmdLine parameter can be NULL."		0,//"Not supported; set to NULL."		0,//"Not supported; set to NULL."		0,//"Not supported; set to FALSE."		CREATE_NEW_CONSOLE,		0,//"Not supported; set to NULL."		0,//"Not supported; set to NULL."		0,//"Not supported; set to NULL."		π);	MessageBox(0,"test","test",MB_OK);	return 1;}

"I never see the message box. The program dies before it."
I'm not sure that was the problem. Then again, I might be looking at an old or really new (and unaffecting) page.
Extrarius
Extrarius
Quote:
Original post by jtmerchant
*** Source Snippet Removed ***
"I never see the message box. The program dies before it."
I'm not sure that was the problem. Then again, I might be looking at an old or really new (and unaffecting) page.
The page you're looking at is for Windows CE (thus the 'wce' everywhere).
The page you want is Create Process (Platform SDK)
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.