多线程通信——匿名管道

匿名管道方式只能实现父进程和子进程之间的通信。
匿名管道方式实现流程:
1、创建一个匿名管道,若创建成功则打开子进程
2、实现父进程的读取数据和写入数据功能
3、实现子进程的读取数据和写入数据功能 

1、创建匿名管道:CreatePipe()
BOOL WINAPI CreatePipe( _Out_     PHANDLE hReadPipe, _Out_     PHANDLE hWritePipe, _In_opt_  LPSECURITY_ATTRIBUTES lpPipeAttributes, _In_      DWORD nSize ); 

Parameters

hReadPipe  [out]

A pointer to a variable that receives the read handle for the pipe.

hWritePipe  [out]

A pointer to a variable that receives the write handle for the pipe.

lpPipeAttributes  [in, optional]

A pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If lpPipeAttributes is NULL, the handle cannot be inherited.

The lpSecurityDescriptor member of the structure specifies a security descriptor for the new pipe. If lpPipeAttributes is NULL, the pipe gets a default security descriptor. The ACLs in the default security descriptor for a pipe come from the primary or impersonation token of the creator.

nSize  [in]

The size of the buffer for the pipe, in bytes. The size is only a suggestion; the system uses the value to calculate an appropriate buffering mechanism. If this parameter is zero, the system uses the default buffer size.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero.


1.1 SECURITY_ATTRIBUTES 

typedef struct _SECURITY_ATTRIBUTES { DWORD  nLength; LPVOID lpSecurityDescriptor; BOOL   bInheritHandle; } SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES; 

Members

nLength

The size, in bytes, of this structure. Set this value to the size of the SECURITY_ATTRIBUTES structure.

lpSecurityDescriptor

A pointer to a SECURITY_DESCRIPTOR structure that controls access to the object. If the value of this member is NULL, the object is assigned the default security descriptor associated with the access token of the calling process. This is not the same as granting access to everyone by assigning a NULL discretionary access control list (DACL). By default, the default DACL in the access token of a process allows access only to the user represented by the access token.

For information about creating a security descriptor, see Creating a Secur

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值