I do not know if you have used such a program, they do not have the function of decompression, but call the DOS program PKZIP complete the ZIP package decompression. But when the program runs without a DOS console window appearing and everything that should have been displayed in DOS appears in a text box in that installer. This design is both beautiful and prevents a few sharp-sighted users from closing your DOS window in advance.
Now let's talk about how to implement this feature with anonymous pipe technology.
Pipeline technology has a long history, I believe that many people in the DOS command in the pipeline technology is most familiar. When we type a file, if we want him to page out the reality can enter
C:\>type Autoexec.bat|more
Here "|" is the pipe operator. He outputs the information in type output as the read end, with more input as the write end of the pipeline.
The more pipes used in Windows are also anonymous pipes, which are created through API functions CreatePipe.
BOOL CreatePipe(
PHANDLE hReadPipe, // 指向读端句柄的指针
PHANDLE hWritePipe, // 指向写端句柄的指针
LPSECURITY_ATTRIBUTES lpPipeAttributes, // 指向安全属性结构的指针
DWORD nSize // 管道的容量
);
Note that hreadpipe,hwritepipe is a pointer to a handle, not a handle (I got it wrong the first time I used it). Nsize is typically specified as 0 to allow the system to determine the capacity of the pipe itself. Now look at the security attribute structure, security_attributes.
typedef struct _SECURITY_ATTRIBUTES { // sa
DWORD nLength;
LPVOID lpSecurityDescriptor;
BOOL bInheritHandle;
} SECURITY_ATTRIBUTES;
Nlength is the size of the structure, which is naturally obtained by sizeof. The lpsecuritydescriptor is a security descriptor (a C-style string). bInheritHandle He indicates whether the object described by the security can be inherited by a newly created process. Do not care about their specific meaning, the use of the natural will know.