Windows core programming Chapter 4 Process

Source: Internet
Author: User

Obtain the current directory:
DWORD getfullpathname (pctstr pszfile, DWORD cchpath, ptstr pszpath, ptstr * ppszfilepart );

 

Obtain the current directory of drive C
Tchar szcurdir [max_path];
Getfullpathname ("C", max_path, szcurdir, null );

Obtain the system version:
Bool getversion (posversioninfo pversioninformation );

Create a process function:
Bool CreateProcess
{
Pctstr pszapplicationname; // name of the executable file used by the new process
Ptstr pszcommandline; // command line string passed to the new process
Psecurity_attributes psaprocess; // creates a process's Security Attribute. The default value is null.
Psecurity_attributes psathread; // Security Attribute of the Creation thread. The default value is null.
Bool binterithandle; // whether it can be inherited
DWORD fdwcreate; // how to create a process
Pvoid pvenvironment; // specifies the memory block that contains the environment string to be used by the new process.
Pctstr pszcurdir; // specifies the parent process directory. If the value is null, the default directory is used.ProgramRunning directory
Pstartupinfo psistartinfo; // point to the startupinfo structure, stack, preferably first
Startupinfo Si = {sizeof (SI )};
Getstartupinfo (& Si); (initialization); otherwise, useless information will be passed to CreateProcess, resulting in uncertainty.
Pprocess_infomation ppiprocinfo // process_information structure, which records the thread ID and sub-process ID of the process.
};

Returns true if the process is successfully created. // if no DLL is found for the created process, true is returned;

Pszcommandline is recommended not to input constants. VC will put the passed strings into the read-only memory, for example:
CreateProcess (null, _ T ("Notepad"), null, null, false, 0, null, null, & Si, & PI );
Will run the error (after self-testing, GCC will not run the error, vs2005 will, the book said that early VC will not be wrong)

Preferably:
Tchar szcommandline [] = _ T ("Notepad ");
CreateProcess (null, szcommandline, null, null, false, 0, null, null, & Si, & PI );
The Notepad program will be opened.

Tchar szpath [] = "WordPad readme. txt ";
CreateProcess ("C: \ windows \ system32 \ notepad. EXE", szpath, null, null, false, 0, null, null, & Si, & PI );
Open the Notepad program and input the szpaht command.

Fdwcreate specifies how to create a new process. You can also set the priority.
Ebug_process: When a sub-process has something to do, it must tell the parent process

Debug_only_this_process: similar to ebug_process, but only tells the specific time when a sub-process is created.

Create_suincluded: The child process is created and the parent process is suspended.

Detached_process: Organizes access to the console of the parent process based on the GUI process, and sends the output to the new console window.

Create_new_console: Create a new process and create a console for the new process. It cannot be used with deta_process at the same time; otherwise, an error is generated.

Create_no_window: do not create a console window for a new process

Create_new_process_group: after multiple processes are created, if you press Ctrl + C, all process users are notified to press Ctrl + C;

Create_default_error_mode: the new process does not inherit the incorrect usage mode of the parent process.

Create_separate_wow_vdm: when Windows 2000 runs 16 bits, create a separate dos Virtual Machine

Create_shared_wow_vdm: when running a 16-bit program in Windows 2000, all 16-bit programs run on a separate dos virtual machine, but the Registry sharing can be changed, unless create_shparate_wow_vdm is set.

Create_forcedos: forces the system to run MOS-DOS applications embedded with 16-bit OS/2 applications

Create_breakaway_from_job: Use jinheng in the job to generate a new process associated with the job

Terminate a running process:
1. Main thread function return (the best method)
2. The thread in the process calls exitprocess (preferably not );
3. threads in another process (preferably not );
4. All threads manually terminate

Bool terminateprocess (handle hprocess, uint fuexitcode );
Difference from eixtprocess: any thread can call terminateprocess

Obtain the exited process that has been withdrawn.Code
Bool getexitcodeprocess (handle hprocess, pdword pdwexitcode );

Closehandle (handle hprocess); It is important to close unused handles.

DWORD waitforsingleobject (handle hobject, DWORD dwtimeout );
Wait for hobject to stop running

Pvoid getmodulepreferredbaseaddr (DWORD dwprocessid, pvoid pvmoduleremote );
Accept the address of a process ID and Process Module

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.