Well, you're new to programming, but copy paste doesn't hurt anybody... so if you're interested.
It could be better like this (quoted from the FAQ) :
Code:
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
char szPath[] = PUT_YOUR_EXE_NAME_HERE;
PROCESS_INFORMATION pi; //Gives info on the thread and..
//..process for the new process
STARTUPINFO si; //Defines how to start the program
ZeroMemory(&si,sizeof(si)); //Zero the STARTUPINFO struct
si.cb = sizeof(si); //Must set size of structure
BOOL bRet = CreateProcess(
szPath, //Path to executable file
NULL, //Command string - not needed here
NULL, //Process handle not inherited
NULL, //Thread handle not inherited
FALSE, //No inheritance of handles
0, //No special flags
NULL, //Same environment block as this prog
NULL, //Current directory - no separate path
&si, //Pointer to STARTUPINFO
π); //Pointer to PROCESS_INFORMATION
if(bRet == FALSE)
{
MessageBox(HWND_DESKTOP,"Unable to start program","",MB_OK);
return 1;
}
CloseHandle(pi.hProcess); //Close handle to process
CloseHandle(pi.hThread); //Close handle to thread
return 0;
}
Some things you should know.
If you want to use this example, you have to compile and link your code as a Win32 application. Don't worry, you don't have to pay any fees to MS.
Simply open your IDE, choose a new Win32 project, or Win32 GUI application.. whatever. Just don't choose something that states library or console. Then add your source files to the project, or create new files, and copy/paste. Then compile, link and your new brand application doesn't have any console or graphical window, althouh you can easilly see the process in the Task Manager.
The way this code is written, your application is stated and this process ends.
If your compiler, or IDE don't have win32 libs, or you're not using windows, then.. just use the old system(...) stuff, or read throughly the FAQ entry...