المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How to use CreateProcess win 32 api function



C++ Programming
01-01-2010, 09:30 PM
Hello Everybody,
I am new to the windows 32 api and i am trying to use the win 3 api function CreateProcess.
I am simply trying to use this function to open the msn messanger process on my windows 7 pc, but i keep on getting a 0 exit code(failure). this is my code:
#include
#include
#include

void _tmain( )
{
STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );


// Start the child process.
if( !CreateProcess( "c:\Program Files\Windows Live\Messenger\msnmsgr.exe", // module name (use command line)
NULL, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // 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
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return;
}

// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );

// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
the path c:\Program Files\Windows Live\Messenger\msnmsgr.exe is my msn messanger directory, but somehow i can get it to work.

Can someone please help me?

Thanks,
Nir Winter