MFC Record CreateProcess launch external game main program

Source: Internet
Author: User

CreateProcess is the WINDOWSAPI function to create a new process that can run the specified executable file!

Function prototypes

BOOL CreateProcess (LPCTSTR lpapplicationname,//parameter 1. The name of the application, an absolute path, or a relative path, nullable, or null if lpCommandLine is executedLPTSTR Lpcommandline,<span style="White-space:pre"> </span>//parameter 2. command-line arguments, nullable, typically for application arguments, or null for functions that use the Lpapplicationname string to run the command lineLpsecurity_attributes Lpprocessattributes,//parameter 3. The properties of the process, which points to a security_attributes structure, determines whether the returned handle is inherited by the quilt process, and is generally nullLpsecurity_attributes Lpthreadattributes,//parameter 4. Thread properties, same as parameter 3. However, this parameter determines whether the thread is inherited and is generally nullBOOL bInheritHandles,//parameter 5. Whether to inherit the properties of the parent process, true\false, which is generally FALSE, if true, each inheritable open handle in the process is inherited, and the inherited person has the same value and access rightsDWORD dwCreationFlags,//parameter 6. Flag bit information, too many parameters, see MSDN, or Baidu Encyclopedia, the general default is 0LPVOID Lpenvironment,//parameter 7. Environment variable, the environment block that points to the new process, generally null, or null the environment in which the new process uses the calling processLPCTSTR Lpcurrentdirectory,//parameter 8. The current directory of the program, for specifying the working path of the child process, or the directory to which the application sits if it is a startup EXE programLpstartupinfo Lpstartupinfo,//parameter 9. Information passed to the new process, pointing to the starupinfo structure of how the new Process main window is displayedLpprocess_informationlpprocessinformation//parameter 10. The information returned by the process, the process_information structure used to receive the new process identification information);

The above is the function prototype, the following example calls

<span style="White-space:pre"> </span>startupinfo si;    Process_information Pi; ZeroMemory (&si,sizeof(SI)); SI.CB=sizeof(SI);    CString chpath,strtmp; TCHAR cmdline[260]; TCHAR filename[260]; TCHAR directory[260]; Chpath="c:\\game\\update\\"; _stprintf (FileName, _t ("%sgame.exe"), Chpath);    _stprintf (Directory, _t (Chpath)); _stprintf (CmdLine, _t ("-debug")); if(! CreateProcess (FileName, cmdline, NULL, NULL, FALSE,0, NULL, Directory, &si, &pi)) {Strtmp.format ("failed to start the game, code:%d", GetLastError ());        AfxMessageBox (strtmp); return; }    //wait for process to closeWaitForSingleObject (pi.hprocess, INFINITE); //closing process and thread handlesCloseHandle (pi.hprocess); CloseHandle (pi.hthread);
At the beginning of the test, using the program to get the path in the configuration file, always error, the general error code is 2, 5, 267, etc., it is easy to ignore the place is: lpapplicationname execution of the EXE program path and program, lpCommandLine to start the program Lpcurrentdirectory the current directory of the program being launched

MFC Record CreateProcess launch external game main program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.