A brief introduction to Windows piping Technology

Source: Internet
Author: User

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.

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.