Three SDK functions: winexec, ShellExecute, and CreateProcess

Source: Internet
Author: User

Three SDK functions:Winexec,ShellExecute,CreateProcess
You can call other programs. Among them, winexec is the simplest, ShellExecute is more flexible than winexec, and CreateProcess is the most complex.
Two winexec parameters: the first one specifies the path, and the last one specifies the display mode.
ShellExecute can specify a working directory, and you can also find file associations to directly open applications that do not need to be loaded with the file association. ShellExecute can also open webpages and start relevant email Association sending emails.
CreateProcess has a total of ten parameters, but most of them can be replaced by null. It can specify the process's security attributes, Inheritance Information, class priority, and so on. If we want to get enough information about the new process and control the detailed attributes of the new process, we need to use the CreateProcess function to achieve this purpose.

Syntax of the three SDK functions (winexec, shellexec, and crateprocess:

Winexec

This function is the simplest and has only two parameters. The prototype is as follows:

Uint winexec (

Maid, // command path

Uint ucmdshow // Display Mode

;

The usage is as follows:

Winexec ("notepad.exe", sw_show); // open notepad
Winexec ("D: // program files // test // test.exe", sw_showmaximized); // open test.exe in simplified format.
Note that if you use the sw_showmaxmized method to load a program without the maximum button, such as neterm and calc, the normal form will not appear, but it has been added to the task list.

ShellExecute

The prototype is as follows:

Hinstance ShellExecute (

Hwnd, // parent window handle

Lpctstr lpoperation, // operation, opening method "edit", "lead E", "open", "find", "print", "null"

Lptstr lpfile, // file name, which can be added to the path above

Lptstr lpparameters, // Parameter

Lptstr lpdirectory, // Default Folder

Int nshowcmd // Display Mode

);

The usage is as follows:

ShellExecute (null, "open", "C: // test.txt", null, null, sw_shownormal); // open the C:/test.txt File
ShellExecute (null, "open", "http://www.google.com",/null, null, sw_shownormal); // open the webpage www.google.com
ShellExecute (null, "Explore", "d: // C ++", null, null, sw_shownormal); // open the Directory D:/C ++
ShellExecute (null, "print", "C: // test.txt", null, null, sw_hide); // print the file C:/test.txt
ShellExecute does not support targeted output.

CreateProcess

The prototype is as follows:

Bool CreateProcess (

Lptstr lpapplicationname, // name of the execution Program

Lptstr lpcommandline, // Parameter Line

// The following two parameters describe the security attributes of the created process and thread. If it is null, the default security attribute is used.

Lpsecurity_attributes lpprocessattributes, // process security attributes

Lpsecurity_attributes lpthreadattributes, // thread security attributes

Bool binherithandles, // inheritance flag

DWORD dwcreationflags, // create a flag

Lpvoid lpenvironment, // environment variable

Maid directory, // The initial directory where the process is running

Lpstartupinfo, // used to set various attributes when creating a sub-process

Lpprocess_information lpprocessinformation // used to receive relevant information after a process is created.

);

The usage is as follows:
Process_information PI;
Startupinfo Si;
Memset (& Si, 0, sizeof (SI ));
Si. cb = sizeof (SI );
Si. wshowwindow = sw_show;
Si. dwflags = startf_useshowwindow;
Bool fret = CreateProcess ("D: // putty.exe", null, null, false, null, & Si, & PI );

It can be seen that through the above several different methods, you can achieve the purpose of opening other applications in the application, some of which may be troublesome, therefore, we need to select the method that best suits us for different purposes to achieve our own goals!

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.