PostHeaderIcon Startup Another Process In Program Use WinAPI

This is also simple code, it calls QQ program:


DWORD CreateChildProcess(LPSTR szChildProcessCmd);

int _stdcall WinMain( __in HINSTANCE hInstance,
			__in_opt HINSTANCE hPrevInstance,
			__in_opt LPSTR lpCmdLine,
			__in int nShowCmd )
{
	CreateChildProcess("F:\\soft\\QQ\\Bin\\QQ.exe");
	return 0;
}

DWORD CreateChildProcess( LPSTR szChildProcessCmd )
{
	STARTUPINFO si;
	PROCESS_INFORMATION pi;
	ZeroMemory(&si, sizeof(si));
	si.cb=sizeof(si);
	ZeroMemory(&si,sizeof(si));

	if (!CreateProcess(NULL,
		szChildProcessCmd,
		NULL,
		NULL,
		FALSE,
		0,
		NULL,
		NULL,
		&si,
		&pi))
	{
		printf("Create Process failed (%d).\n",
			GetLastError());
		return 1;
	}
	WaitForSingleObject(pi.hProcess,INFINITE);
	CloseHandle(pi.hProcess);
	CloseHandle(pi.hThread);
	return 0;
13,653 views

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Copyright © 2010 - C++ Technology. All Rights Reserved.

Powered by Jerry | Free Space Provided by connove.com