网站首页  词典首页

请输入您要查询的函数:

 

术语 createnamedpipe
释义 CreateNamedPipe
语法:
C++
HANDLE WINAPI CreateNamedPipe(
__in LPCTSTR lpName,
__in DWORD dwOpenMode,
__in DWORD dwPipeMode,
__in DWORD nMaxInstances,
__in DWORD nOutBufferSize,
__in DWORD nInBufferSize,
__in DWORD nDefaultTimeOut,
__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes
);
CreateNamedPipe功能
创建一个命名管道实例,并返回处理后续管业务。命名管道服务器进程使用此功能可以创建一个特定的命名管道的第一个实例,建立其基本属性或创建一个已经存在的命名管道的新实例。
参数
lpName [in]
独特的管道名称。此字符串必须具有下列形式:
\\ \\。\\管\\ pipename
名称的pipename部分可以包含任何包括数字和特殊字符的字符而不是其他反斜杠。整个管道的名称字符串最多可以有256个字符长。管名不区分大小写。
dwOpenMode [in]
开放的模式。函数失败如果dwOpenMode指定任何非0或下表中列出的标志。
此参数必须指定下列管接入方式之一。同样的模式必须被指定为每个管道实例。
ModeMeaning
PIPE_ACCESS_DUPLEX
0x00000003The管道是双向的,服务器和客户端程序可以读取和写入管道。这种模式使服务器上的GENERIC_READ和GENERIC_WRITE访问管道当量。客户端可以指定GENERIC_READ或GENERIC_WRITE,或两者兼而有之,当它连接到管道使用CreateFile函数。
PIPE_ACCESS_INBOUND
管道中的数据0x00000001The流动是从客户到服务器。这种模式使服务器上的GENERIC_READ进入管道当量。客户端必须指定GENERIC_WRITE访问时,连接到管道。如果客户端必须读通过调用GetNamedPipeInfo或GetNamedPipeHandleState职能管道设置,客户端必须指定GENERIC_WRITE和FILE_READ_ATTRIBUTES访问时,连接到管道。
PIPE_ACCESS_OUTBOUND
管道中的数据0x00000002The流动是从服务器到客户端只。这种模式使服务器上的GENERIC_WRITE进入管道当量。客户端必须指定GENERIC_READ访问时,连接到管道。如果客户端必须改变通过调用SetNamedPipeHandleState功能管道的设置,客户端必须指定GENERIC_READ和FILE_WRITE_ATTRIBUTES访问时,连接到管道。
此参数还可以包括一个或多个下列标志,它使通过和重叠写模式,更多。这些模式可以是不同的同一管道的不同实例。
ModeMeaning
FILE_FLAG_FIRST_PIPE_INSTANCE
0x00080000If您尝试创建一个与此标志,第一个实例创建成功管道的多个实例,但在下一个实例创建与ERROR_ACCESS_DENIED失败。
Windows 2000中:这个标志是,直到Windows 2000 SP2和Windows XP的支持。
FILE_FLAG_WRITE_THROUGH全方位
0x80000000Write通过模式已启用。这种模式只影响写字节型管业务和,那么,只有当客户端和服务器进程在不同的计算机上。如果这个模式被激活,功能写入命名管道不返回,直到写入数据传输在网络和管道的缓冲区是在远程计算机上。如果这个模式不启用,该系统增强了缓冲的数据,直到最低的字节数的网络运营效率,积累或直到最大经过的时间。
FILE_FLAG_OVERLAPPED
0x40000000Overlapped模式已启用。如果这个模式被激活,功能表演读,写,并连接操作,可能需要大量时间才能完成可以立即返回。这种模式使线程开始运作,以执行其他操作,而费时的操作在后台执行。例如,在重叠模式,一个线程可以处理管道的多个实例同时输入和输出(I / O)操作,或进行同步读写操作在同一管道句柄。如果重叠模式不启用,功能表演读,写,并连接管道处理业务不会返回,直到操作完成。在ReadFileEx和WriteFileEx功能只能用于与管道处理重叠模式。了ReadFile,WriteFile,ConnectNamedPipe和TransactNamedPipe功能,可以执行同步或作为重叠操作。
此参数可以包括下列任何一种安全的接入方式的组合。这些模式可以是不同的同一管道的不同实例。
ModeMeaning
WRITE_DAC
0x00040000LThe调用将具有写访问命名管道的自由访问控制列表(ACL)。
WRITE_OWNER
0x00080000LThe调用将具有写访问命名管道的拥有者。
ACCESS_SYSTEM_SECURITY
0x01000000LThe调用将具有写访问命名管道的的SACL。有关更多信息,请访问控制列表(ACL)和深圳机场的通行权。
dwPipeMode [in]
管模式。函数失败如果dwPipeMode指定任何非0或下表中列出的标志。
以下类型的模式,可以指定一个。同一类型的模式必须被指定为每个管道实例。
ModeMeaning
PIPE_TYPE_BYTE
0x00000000Data写入作为字节流管。这种模式不能用于PIPE_READMODE_MESSAGE。
PIPE_TYPE_MESSAGE
0x00000004Data写入作为信息流管。这种模式可用于任何PIPE_READMODE_MESSAGE或PIPE_READMODE_BYTE。
下面的阅读模式,可以指定一个。同管不同的情况下,可以指定不同的阅读模式。
ModeMeaning
PIPE_READMODE_BYTE
0x00000000Data是读取以字节流管。这种模式可用于任何PIPE_TYPE_MESSAGE或PIPE_TYPE_BYTE。
PIPE_READMODE_MESSAGE
0x00000002Data是读取作为信息流管。这种模式只能使用如果PIPE_TYPE_MESSAGE也指定。
以下等待模式可以指定一个。同管不同的情况下,可以指定不同的等待模式。
ModeMeaning
PIPE_WAIT
0x00000000Blocking模式已启用。当管道句柄在了ReadFile,WriteFile,或ConnectNamedPipe函数指定的操作是没有完成之前,是数据读取,写入的所有数据,或者客户端连接。使用这种模式意味着在等待客户端进程某些情况下无限期地执行一个动作。
PIPE_NOWAIT
0x00000001Nonblocking模式已启用。在这种模式下,ReadFile,WriteFile和ConnectNamedPipe总是立即返回。
请注意,非阻塞模式的支持与Microsoft LAN Manager版本2.0的兼容性,不应用来实现异步I / O与命名管道。欲了解更多有关异步管我的信息/输出,见同步和重叠的输入和输出。
下列其中一个远程客户端模式,可以指定。同管不同的情况下,可以指定不同的远程客户端模式。
ModeMeaning
PIPE_ACCEPT_REMOTE_CLIENTS
从远程客户端0x00000000Connections可以接受和反对为管道的安全描述符检查。
Windows Server 2003和Windows XP/2000操作系统:这个标志是不支持。
PIPE_REJECT_REMOTE_CLIENTS
从远程客户端0x00000008Connections被自动拒绝。
Windows Server 2003和Windows XP/2000操作系统:这个标志是不支持。为了达到相同的结果,拒绝访问对网络酵管。
nMaxInstances [in]
对可用于创建这个管道实例的最大数目。管道的第一个实例可以指定此值,相同的号码必须为管道的另一实例指定。可接受的值是通过PIPE_UNLIMITED_INSTANCES(255)范围1。
如果这个参数是PIPE_UNLIMITED_INSTANCES的管道,可以创造许多情况下只受系统资源的可用性。如果nMaxInstances比PIPE_UNLIMITED_INSTANCES更大,则返回值为ERROR_INVALID_PARAMETER。
nOutBufferSize [in]
的字节数保留的输出缓冲区。一项关于命名管道缓冲区大小的讨论,请参阅下面的备注部分。
nInBufferSize [in]
的字节数要预留输入缓冲区。一项关于命名管道缓冲区大小的讨论,请参阅下面的备注部分。
nDefaultTimeOut [in]
默认的超时值,以毫秒为单位,如果WaitNamedPipe函数指定NMPWAIT_USE_DEFAULT_WAIT。每一个命名管道实例必须指定相同的值。
A value of zero will result in a default time-out of 50 milliseconds.
lpSecurityAttributes [中,可选]
一个 SECURITY_ATTRIBUTES结构,指定为新的命名管道的安全描述符,并决定是否可以继承子进程返回的句柄的指针。如果lpSecurityAttributes为NULL,则命名管道得到默认的安全描述和处理不能被继承。在对一个命名管道授予完全控制到LocalSystem帐户,管理员的默认ACL的安全描述符,和创建者所有者。他们还授予读取权限的Everyone组成员和匿名帐户。
返回值
如果函数成功,返回值是一个句柄到一个命名管道实例服务器端。
如果函数失败,返回值是INVALID_HANDLE_VALUE。为了获得更多错误信息,调用GetLastError。
备注
要通过使用CreateNamedPipe的一个命名管道实例,用户必须具有FILE_CREATE_PIPE_INSTANCE访问命名管道对象。如果一个新的命名的管道正在创建,访问控制列表从安全(ACL)的属性参数定义了命名管道的自由访问控制。
一个命名管道的所有实例都必须指定相同的管式(字节型或信息型),管道接入(全双工,入站或出站),实例计算和超时值。如果使用不同的值,这个函数失败并GetLastError返回ERROR_ACCESS_DENIED。
一个命名管道客户端开始在字节模式,即使在邮件服务器端模式。为了避免问题的接收数据,设置客户端的信息模式,以及。要更改管道模式,管端必须打开一个只读的GENERIC_READ和FILE_WRITE_ATTRIBUTES访问管道。
管道服务器不应执行,直到管道客户端已开始阻塞读操作。否则,竞争状态可能会发生。这通常发生在初始化代码,如C运行时,需要锁定和研究继承处理。
每一个命名管道创建时,系统创建入站和/或出站使用非分页缓冲池,这是物理内存的内核使用。在一些情况下的管道(以及诸如线程和进程对象),您可以创建是有限的可用非分页缓冲池。每个读取或写入请求,需要在为读取或写入数据,加上内部数据结构的额外空间的缓冲区空间。
输入和输出缓冲区大小的咨询。实际缓冲区大小的每个命名管道最终保留或者是系统默认,系统最小或最大,或指定的大小四舍五入到下一个分配的界线。指定的缓冲区的大小应该足够小,您的进程不会因非分页池,但是足以容纳典型的请求。
每当管写操作时,系统首先尝试负责对管道写入内存配额。如果剩余的配额管写就足以满足要求,立即写操作完成。如果剩余的管道写的配额太少,要完成请求,系统将设法扩大缓冲区,以适应数据使用非分页缓冲池的过程中保留。写入操作将阻塞,直到数据从管道,使额外的缓冲配额可以释放读取。因此,如果您指定的缓冲区大小是太小,系统将增长的需要作为缓冲,但缺点是操作将块。如果操作是重叠的,系统线程被阻塞,否则,应用程序线程被阻塞。
一个命名管道实例都删除当最后一个句柄的命名管道实例关闭。
实例
有关示例,请参见多线程管道服务器。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinbase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
Unicode和ANSI namesCreateNamedPipeW(Unicode)和CreateNamedPipeA(ANSI)的
参见
ConnectNamedPipe
CreateFile
管功能
管概述
ReadFile
ReadFileEx
SECURITY_ATTRIBUTES
TransactNamedPipe
WaitNamedPipe
WriteFile
WriteFileEx
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年7月30日
==英文原文==CreateNamedPipe Function
Creates an instance of a named pipe and returns a handle for subsequent pipe operations. A named pipe server process uses this function either to create the first instance of a specific named pipe and establish its basic attributes or to create a new instance of an existing named pipe.
Syntax
C++
HANDLE WINAPI CreateNamedPipe(
__in LPCTSTR lpName,
__in DWORD dwOpenMode,
__in DWORD dwPipeMode,
__in DWORD nMaxInstances,
__in DWORD nOutBufferSize,
__in DWORD nInBufferSize,
__in DWORD nDefaultTimeOut,
__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes
);
Parameters
lpName [in]
The unique pipe name. This string must have the following form:
\\\\.\\pipe\\pipename
The pipename part of the name can include any character other than a backslash, including numbers and special characters. The entire pipe name string can be up to 256 characters long. Pipe names are not case sensitive.
dwOpenMode [in]
The open mode. The function fails if dwOpenMode specifies anything other than 0 or the flags listed in the following tables.
This parameter must specify one of the following pipe access modes. The same mode must be specified for each instance of the pipe.
ModeMeaning
PIPE_ACCESS_DUPLEX
0x00000003The pipe is bi-directional; both server and client processes can read from and write to the pipe. This mode gives the server the equivalent of GENERIC_READ and GENERIC_WRITE access to the pipe. The client can specify GENERIC_READ or GENERIC_WRITE, or both, when it connects to the pipe using the CreateFile function.
PIPE_ACCESS_INBOUND
0x00000001The flow of data in the pipe goes from client to server only. This mode gives the server the equivalent of GENERIC_READ access to the pipe. The client must specify GENERIC_WRITE access when connecting to the pipe. If the client must read pipe settings by calling the GetNamedPipeInfo or GetNamedPipeHandleState functions, the client must specify GENERIC_WRITE and FILE_READ_ATTRIBUTES access when connecting to the pipe.
PIPE_ACCESS_OUTBOUND
0x00000002The flow of data in the pipe goes from server to client only. This mode gives the server the equivalent of GENERIC_WRITE access to the pipe. The client must specify GENERIC_READ access when connecting to the pipe. If the client must change pipe settings by calling the SetNamedPipeHandleState function, the client must specify GENERIC_READ and FILE_WRITE_ATTRIBUTES access when connecting to the pipe.

This parameter can also include one or more of the following flags, which enable the write-through and overlapped modes. These modes can be different for different instances of the same pipe.
ModeMeaning
FILE_FLAG_FIRST_PIPE_INSTANCE
0x00080000If you attempt to create multiple instances of a pipe with this flag, creation of the first instance succeeds, but creation of the next instance fails with ERROR_ACCESS_DENIED.
Windows 2000: This flag is not supported until Windows 2000 SP2 and Windows XP.
FILE_FLAG_WRITE_THROUGH
0x80000000Write-through mode is enabled. This mode affects only write operations on byte-type pipes and, then, only when the client and server processes are on different computers. If this mode is enabled, functions writing to a named pipe do not return until the data written is transmitted across the network and is in the pipe's buffer on the remote computer. If this mode is not enabled, the system enhances the efficiency of network operations by buffering data until a minimum number of bytes accumulate or until a maximum time elapses.
FILE_FLAG_OVERLAPPED
0x40000000Overlapped mode is enabled. If this mode is enabled, functions performing read, write, and connect operations that may take a significant time to be completed can return immediately. This mode enables the thread that started the operation to perform other operations while the time-consuming operation executes in the background. For example, in overlapped mode, a thread can handle simultaneous input and output (I/O) operations on multiple instances of a pipe or perform simultaneous read and write operations on the same pipe handle. If overlapped mode is not enabled, functions performing read, write, and connect operations on the pipe handle do not return until the operation is finished. The ReadFileEx and WriteFileEx functions can only be used with a pipe handle in overlapped mode. The ReadFile , WriteFile , ConnectNamedPipe , and TransactNamedPipe functions can execute either synchronously or as overlapped operations.

This parameter can include any combination of the following security access modes. These modes can be different for different instances of the same pipe.
ModeMeaning
WRITE_DAC
0x00040000LThe caller will have write access to the named pipe's discretionary access control list (ACL).
WRITE_OWNER
0x00080000LThe caller will have write access to the named pipe's owner.
ACCESS_SYSTEM_SECURITY
0x01000000LThe caller will have write access to the named pipe's SACL. For more information, see Access-Control Lists (ACLs) and SACL Access Right .

dwPipeMode [in]
The pipe mode. The function fails if dwPipeMode specifies anything other than 0 or the flags listed in the following tables.
One of the following type modes can be specified. The same type mode must be specified for each instance of the pipe.
ModeMeaning
PIPE_TYPE_BYTE
0x00000000Data is written to the pipe as a stream of bytes. This mode cannot be used with PIPE_READMODE_MESSAGE.
PIPE_TYPE_MESSAGE
0x00000004Data is written to the pipe as a stream of messages. This mode can be used with either PIPE_READMODE_MESSAGE or PIPE_READMODE_BYTE.

One of the following read modes can be specified. Different instances of the same pipe can specify different read modes.
ModeMeaning
PIPE_READMODE_BYTE
0x00000000Data is read from the pipe as a stream of bytes. This mode can be used with either PIPE_TYPE_MESSAGE or PIPE_TYPE_BYTE.
PIPE_READMODE_MESSAGE
0x00000002Data is read from the pipe as a stream of messages. This mode can be only used if PIPE_TYPE_MESSAGE is also specified.

One of the following wait modes can be specified. Different instances of the same pipe can specify different wait modes.
ModeMeaning
PIPE_WAIT
0x00000000Blocking mode is enabled. When the pipe handle is specified in the ReadFile, WriteFile, or ConnectNamedPipe function, the operations are not completed until there is data to read, all data is written, or a client is connected. Use of this mode can mean waiting indefinitely in some situations for a client process to perform an action.
PIPE_NOWAIT
0x00000001Nonblocking mode is enabled. In this mode, ReadFile, WriteFile, and ConnectNamedPipe always return immediately.
Note that nonblocking mode is supported for compatibility with Microsoft LAN Manager version 2.0 and should not be used to achieve asynchronous I/O with named pipes. For more information on asynchronous pipe I/O, see Synchronous and Overlapped Input and Output .

One of the following remote-client modes can be specified. Different instances of the same pipe can specify different remote-client modes.
ModeMeaning
PIPE_ACCEPT_REMOTE_CLIENTS
0x00000000Connections from remote clients can be accepted and checked against the security descriptor for the pipe.
Windows Server 2003 and Windows XP/2000: This flag is not supported.
PIPE_REJECT_REMOTE_CLIENTS
0x00000008Connections from remote clients are automatically rejected.
Windows Server 2003 and Windows XP/2000: This flag is not supported. To achieve the same results, deny access to the pipe to the NETWORK ACE.

nMaxInstances [in]
The maximum number of instances that can be created for this pipe. The first instance of the pipe can specify this value; the same number must be specified for other instances of the pipe. Acceptable values are in the range 1 through PIPE_UNLIMITED_INSTANCES (255).
If this parameter is PIPE_UNLIMITED_INSTANCES, the number of pipe instances that can be created is limited only by the availability of system resources. If nMaxInstances is greater than PIPE_UNLIMITED_INSTANCES, the return value is ERROR_INVALID_PARAMETER.
nOutBufferSize [in]
The number of bytes to reserve for the output buffer. For a discussion on sizing named pipe buffers, see the following Remarks section.
nInBufferSize [in]
The number of bytes to reserve for the input buffer. For a discussion on sizing named pipe buffers, see the following Remarks section.
nDefaultTimeOut [in]
The default time-out value, in milliseconds, if the WaitNamedPipe function specifies NMPWAIT_USE_DEFAULT_WAIT. Each instance of a named pipe must specify the same value.
A value of zero will result in a default time-out of 50 milliseconds.
lpSecurityAttributes [in, optional]
A pointer to a SECURITY_ATTRIBUTES structure that specifies a security descriptor for the new named pipe and determines whether child processes can inherit the returned handle. If lpSecurityAttributes is NULL, the named pipe gets a default security descriptor and the handle cannot be inherited. The ACLs in the default security descriptor for a named pipe grant full control to the LocalSystem account, administrators, and the creator owner. They also grant read access to members of the Everyone group and the anonymous account.
Return Value
If the function succeeds, the return value is a handle to the server end of a named pipe instance.
If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError .
Remarks
To create an instance of a named pipe by using CreateNamedPipe, the user must have FILE_CREATE_PIPE_INSTANCE access to the named pipe object. If a new named pipe is being created, the access control list (ACL) from the security attributes parameter defines the discretionary access control for the named pipe.
All instances of a named pipe must specify the same pipe type (byte-type or message-type), pipe access (duplex, inbound, or outbound), instance count, and time-out value. If different values are used, this function fails and GetLastError returns ERROR_ACCESS_DENIED.
The client side of a named pipe starts out in byte mode, even if the server side is in message mode. To avoid problems receiving data, set the client side to message mode as well. To change the mode of the pipe, the pipe client must open a read-only pipe with GENERIC_READ and FILE_WRITE_ATTRIBUTES access.
The pipe server should not perform a blocking read operation until the pipe client has started. Otherwise, a race condition can occur. This typically occurs when initialization code, such as the C run-time, needs to lock and examine inherited handles.
Every time a named pipe is created, the system creates the inbound and/or outbound buffers using nonpaged pool, which is the physical memory used by the kernel. The number of pipe instances (as well as objects such as threads and processes) that you can create is limited by the available nonpaged pool. Each read or write request requires space in the buffer for the read or write data, plus additional space for the internal data structures.
The input and output buffer sizes are advisory. The actual buffer size reserved for each end of the named pipe is either the system default, the system minimum or maximum, or the specified size rounded up to the next allocation boundary. The buffer size specified should be small enough that your process will not run out of nonpaged pool, but large enough to accommodate typical requests.
Whenever a pipe write operation occurs, the system first tries to charge the memory against the pipe write quota. If the remaining pipe write quota is enough to fulfill the request, the write operation completes immediately. If the remaining pipe write quota is too small to fulfill the request, the system will try to expand the buffers to accommodate the data using nonpaged pool reserved for the process. The write operation will block until the data is read from the pipe so that the additional buffer quota can be released. Therefore, if your specified buffer size is too small, the system will grow the buffer as needed, but the downside is that the operation will block. If the operation is overlapped, a system thread is blocked; otherwise, the application thread is blocked.
An instance of a named pipe is always deleted when the last handle to the instance of the named pipe is closed.
Examples
For an example, see Multithreaded Pipe Server .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
Unicode and ANSI namesCreateNamedPipeW (Unicode) and CreateNamedPipeA (ANSI)
See Also
ConnectNamedPipe
CreateFile
Pipe Functions
Pipes Overview
ReadFile
ReadFileEx
SECURITY_ATTRIBUTES
TransactNamedPipe
WaitNamedPipe
WriteFile
WriteFileEx
Send comments about this topic to Microsoft
Build date: 7/30/2009
==原始网址==http://msdn.microsoft.com/en-us/library/aa365150(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:25:16