Windows core programming process (2)

Source: Internet
Author: User
1. each executable file or DLL file loaded into the process address space is generated with a unique instance handle, which is the hinstexe parameter. some parameters belong to the hmodule type. Note: These two types are identical objects. The reason is that in a 16-bit windows, hmodule and hinstance are used to identify different things. In the link of the VC environment, category selects ouput to have a base, which identifies the base address of the executable file image. the default base address used by the VC link program is 0x00400000, which is the lowest address. If you specify the base address, make sure it is at 0x00400000 or greater than this address. You can use the hmodule getmodulehandle (pctstr pszmodule) function to obtain the value of this address. The pszmodule is the name of the executable file or DLL file. The returned result is the base address of the process. If this parameter is set to null, the base address of the executable file is returned. Note: the differences between the base address of the executable file image and the base address of the executable file are as follows. two important features of the getmodulehandle function 1. if the calling process does not use Common Dialog Box functions, call getmodulehandle and pass it: comdlg32, then null is returned, although comdlg32.dll may be loaded to the address space of other processes. 2. if getmodulehandle (null) is called in DLL, the returned base address is also the executable file, not the base address of the DLL file. 2. to obtain a pointer to the complete command line of a process, you can use the getcommandline function getcommandline (). The function returns a pointer to the cache containing the complete command line, is a complete path name. next, we will introduce the commandlinetoargv function, which splits a string into its respective tags, such as argc. It returns an array pwstr commandlinetoargv (pwstr pszcmdline, int * pnumargs) of a string pointer );

Pnumargs is an integer address and is set to the number of parameters in the command line. commanelinetoargv allocates memory internally. The application does not release the memory. It is released by the OS when the process is terminated. If the sub-user releases the memory, the heapfree function is applied. process environment variables each process has an environment block related to it. an environment block is a memory block allocated in the address space of a process. each environment block contains a set of strings. for example, varname1 = varvalue1/0varname2 = varvalue2/0 ............................... /0 Note: for example, XYZ = windowsabc = windows, although XYZ and ABC have the same value, they are different. XYZ = homexyz = work is also different. The space in the middle distinguishes them from the Win98 environment variables written in autoexec. in bat, the environment variable name in Win2000 is written in HKEY_LOCAL_MACHINE/system/CurrentControlSet/control/sessionmanager/environment. The value of environment variable name in HKEY_CURRENT_USER/environment can be modified only when it has an administrator identity. Use DWORD getenvironmentvariable (pctstr pszname, ptstr pszvalue, DWORD cchvalue); to determine whether an environment variable exists and its value. The first parameter is the name, the second parameter is the cache that stores the variable value, and the third parameter is the cache size (expressed by the number of characters ). Bool setenvironmentvariable (pctstr pszname, pctstr pszvalue) is used to modify and add or delete a variable. If a variable such as pszname does not exist, add a new variable and change it to pszvalue if it exists. If pszvalue is null, delete this variable. 4. the threads in the process can be executed on any CPU of the master computer. However, the thread of a process may be forced to run on a subset of the available CPU, which is called the affinity of the process. 5. the Error Mode uint seterrormode (uint fuerrormode) of the process. You must add a parameter in CreateProcess to specify this mode, how to handle a sub-process error: current drive and directory of the process if createfile is called to open a file (No path is set), the system will find the file in the current drive and directory. You can use DWORD getcurrentdirectory (DWORD cchcurdir, ptstr pszcurdir) to get bool setcurrentdirectory (pctstr pszcurdir); you can specify the path. 6. The current directory of the process the system keeps track of the current drive and directory of the process, but does not keep track of the current directory of each drive. This support is provided through the process environment string. For example, a process has two environment variables. = C:/utility/bin = D:/program files indicates that the current directory of the process that drives C is/utility/bin, D is/program files; if you call a function and pass the full name of a drive, but not the current drive, the system will view the process's environmental block, find the variables related to the specified drive name. If yes, the system uses the variable value as the current drive. If it does not exist, the system assumes that the current directory of the specified drive is its root directory. For example, if the current directory of the process is C:/utility/bin, but createfile is called to open D: readme.txt, the system will check the environment variable = D. if = D exists, the system opens the readme.txt file from the D:/program filedirectory. If mongoddoes not exist, the system will open readme.txt from the root directory of driver d. To be continued ...............

 

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.