网站首页  词典首页

请输入您要查询的函数:

 

术语 writefileex
释义 WriteFileEx
语法:
C++
BOOL WINAPI WriteFileEx(
__in HANDLE hFile,
__in_opt LPCVOID lpBuffer,
__in DWORD nNumberOfBytesToWrite,
__inout LPOVERLAPPED lpOverlapped,
__in_opt LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
);
WriteFileEx功能
数据写入到指定的文件或输入/输出(I / O)设备。它的完成状况报告其异步调用指定的完成例程时,写作完成或取消,调用线程在一个可报警等待状态。
将数据写入一个文件或设备同步,使用WriteFile函数。
参数
hFile [in]
句柄到文件或I / O设备(例如,一个文件,文件流,物理磁盘,卷,控制台缓冲区,磁带驱动器,插座,通信资源,邮筒,或管道)。
此参数可以是任何处理由CreateFile函数,或者套接字处理套接字或接受函数返回FILE_FLAG_OVERLAPPED标志打开。
不关联的I / O处理与此完成端口。有关详细信息,请参见备注部分。
这种处理也必须有GENERIC_WRITE访问权限。欲了解更多有关访问权限的信息,请参阅文件安全性和访问权限。
lpBuffer [中,可选]
甲到缓冲区包含要写入到文件或设备的数据指针。
这个缓冲区必须始终有效写操作的时间。调用者不能使用此缓冲区,直到写入操作完成。
nNumberOfBytesToWrite [in]
的字节数写入文件或设备。
为零值指定一个空写操作。一个空的行为写操作依赖于底层文件系统。
管写通过网络被限制为65,535每写字节操作。欲了解更多有关管道,请参见备注部分。
lpOverlapped [ in , out ]
一个OVERLAPPED数据结构提供的数据将在重叠(异步使用)指针写操作。
对于文件,支持字节偏移,您必须指定偏移量开始写入文件的字节。您可以指定此偏移通过设置偏移和OVERLAPPED结构OffsetHigh成员。对于文件或设备不支持字节偏移,偏移量和OffsetHigh被忽略。
若要写入文件结尾,同时指定胶印,作为0xFFFFFFFF的OVERLAPPED结构OffsetHigh成员。这在功能上等同先前调用CreateFile函数打开hFile使用FILE_APPEND_DATA访问。
该WriteFileEx函数忽略OVERLAPPED结构的hEvent成员。应用程序是免费使用在一个WriteFileEx调用上下文自己的目的,该成员。 WriteFileEx信号调用,或排队打电话的写操作完成,完成例程指向lpCompletionRoutine,所以并不需要一个事件句柄。
该WriteFileEx函数不使用内部和OVERLAPPED结构InternalHigh成员。您不应该改变这些成员的价值。
重叠数据结构必须保持有效的写操作的时间。它不应该是一个变量,可以超出了范围,而等待写入操作完成。
lpCompletionRoutine [中,可选]
一个完成例程被调用时,写操作指针已经完成,并调用线程在一个可报警等待状态。有关此完成例程信息,请参阅FileIOCompletionRoutine。
返回值
如果函数成功,返回值为非零。
如果函数失败,返回值是零。为了获得更多错误信息,调用GetLastError。
如果WriteFileEx函数成功,调用线程异步I / O操作之前:重叠写操作该文件。当这个I / O操作完成,并且调用线程被阻塞在一个可报警等待状态,操作系统调用函数指向lpCompletionRoutine,而等待的和WAIT_IO_COMPLETION返回代码完成。
如果函数成功和文件,写操作完成,但在调用线程的可报警等待状态没有,系统队列调用* lpCompletionRoutine,举行电话会议,直到调用线程进入一个可报警等待状态。如需有关报警等待状态和重叠的输入/输出操作的信息,请参阅关于同步。
备注
当使用WriteFileEx您应该检查GetLastError函数甚至当函数返回的“成功”来检查的条件是“成功”,但有一些结果您可能想知道。例如,一个缓冲区溢出当调用WriteFileEx将返回TRUE,但GetLastError函数将报告与ERROR_MORE_DATA溢出。如果函数调用成功,也没有警告的条件,GetLastError函数将返回ERROR_SUCCESS。
该WriteFileEx函数将失败,如果hFile参数与一个I / O完成端口相关联。要执行写入使用这种类型的处理,使用WriteFile函数。
该WriteFileEx函数可能会失败,如果有太多的异步I / O请求。在这样一个发生故障时,GetLastError函数可以返回ERROR_INVALID_USER_BUFFER或ERROR_NOT_ENOUGH_MEMORY。
要取消所有挂起的异步I / O操作,请使用:
CancelIo,此功能只能取消由指定的文件句柄调用的线程发出的行动。
CancelIoEx,此功能取消了指定的文件处理线程发出的所有业务。
使用CancelSynchronousIo取消等候同步I / O操作。
I / O操作是取消与错误完全ERROR_OPERATION_ABORTED。
如果由hFile指定的文件的一部分,是由另一个进程锁定,指定写操作锁定部分重叠,WriteFileEx失败。
当写入一个文件,最后写入时间没有完全更新,直到所有句柄书写已被关闭。因此,为了确保准确的最后写入时间,立即关闭后,以书面文件的文件句柄。
访问输出缓冲区写操作时使用的缓冲区可能导致从该缓冲区写的数据损坏。应用程序不能写入,重新分配,或免费的输出缓冲区中写入操作使用,直到写入操作完成。
请注意,时间戳可能无法更新远程文件正确。为了确保一致的结果,使用缓冲I / O的
该系统解释零字节写指定一个空写操作和WriteFile不会截断或扩展文件。为了截断或扩展文件,请使用SetEndOfFile功能。
应用程序使用WaitForSingleObjectEx,WaitForMultipleObjectsEx,MsgWaitForMultipleObjectsEx,SignalObjectAndWait,并SleepEx功能,输入一个可报警等待状态。如需有关报警等待状态信息和重叠I / O操作,请参阅关于同步。
如果您直接写信给量,有一个安装的文件系统,必须首先获取独占访问量。否则,您可能会导致数据损坏或系统不稳定,因为您的应用程序的写入可能与从文件系统所带来的其他变化的冲突和留在不一致的状态卷的内容。为了避免这些问题,以下修改过的Windows Vista和更高版本:
阿写卷上的处理会成功,如果卷没有挂载的文件系统,或者如果下列条件之一:
各部门要写入的启动扇区。
各部门要写入居住以外的文件系统空间。
您有明确锁定或卸除使用FSCTL_LOCK_VOLUME或FSCTL_DISMOUNT_VOLUME音量。
该卷并没有实际的文件系统。 (换句话说,它有一个RAW文件系统的安装。)
磁盘上的写入将成功处理如果下列条件之一:
各部门要写入不属于一个卷的程度。
各部门要写入属于一装入的卷,但是您必须明确地锁定或卸除使用FSCTL_LOCK_VOLUME或FSCTL_DISMOUNT_VOLUME音量。
各部门要写入属于一个没有安装的文件系统容量比其他的RAW。
有成功与使用FILE_FLAG_NO_BUFFERINGCreateFile打开文件的工作严格要求。详情请参阅文件缓冲。
交易业务
如果绑定到文件处理事务,那么该文件写入交易。有关更多信息,请参阅关于交互式NTFS。
实例
有关示例,请参见服务器使用命名管道完成例程。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinBase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
参见
CancelIo
CancelIoEx
CancelSynchronousIo
CreateFile
文件管理函数
FileIOCompletionRoutine
MsgWaitForMultipleObjectsEx
ReadFileEx
SetEndOfFile
SetErrorMode
SleepEx
SignalObjectAndWait
WaitForMultipleObjectsEx
WaitForSingleObjectEx
WriteFile
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年9月3日
==英文原文==WriteFileEx Function
Writes data to the specified file or input/output (I/O) device. It reports its completion status asynchronously, calling the specified completion routine when writing is completed or canceled and the calling thread is in an alertable wait state.
To write data to a file or device synchronously, use the WriteFile function.
Syntax
C++
BOOL WINAPI WriteFileEx(
__in HANDLE hFile,
__in_opt LPCVOID lpBuffer,
__in DWORD nNumberOfBytesToWrite,
__inout LPOVERLAPPED lpOverlapped,
__in_opt LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
);
Parameters
hFile [in]
A handle to the file or I/O device (for example, a file, file stream, physical disk, volume, console buffer, tape drive, socket, communications resource, mailslot, or pipe).
This parameter can be any handle opened with the FILE_FLAG_OVERLAPPED flag by the CreateFile function, or a socket handle returned by the socket or accept function.
Do not associate an I/O completion port with this handle. For more information, see the Remarks section.
This handle also must have the GENERIC_WRITE access right. For more information on access rights, see File Security and Access Rights .
lpBuffer [in, optional]
A pointer to the buffer containing the data to be written to the file or device.
This buffer must remain valid for the duration of the write operation. The caller must not use this buffer until the write operation is completed.
nNumberOfBytesToWrite [in]
The number of bytes to be written to the file or device.
A value of zero specifies a null write operation. The behavior of a null write operation depends on the underlying file system.
Pipe write operations across a network are limited to 65,535 bytes per write. For more information regarding pipes, see the Remarks section.
lpOverlapped [in, out]
A pointer to an OVERLAPPED data structure that supplies data to be used during the overlapped (asynchronous) write operation.
For files that support byte offsets, you must specify a byte offset at which to start writing to the file. You specify this offset by setting the Offset and OffsetHigh members of the OVERLAPPED structure. For files or devices that do not support byte offsets, Offset and OffsetHigh are ignored.
To write to the end of file, specify both the Offset and OffsetHigh members of the OVERLAPPED structure as 0xFFFFFFFF. This is functionally equivalent to previously calling the CreateFile function to open hFile using FILE_APPEND_DATA access.
The WriteFileEx function ignores the OVERLAPPED structure's hEvent member. An application is free to use that member for its own purposes in the context of a WriteFileEx call. WriteFileEx signals completion of its writing operation by calling, or queuing a call to, the completion routine pointed to by lpCompletionRoutine, so it does not need an event handle.
The WriteFileEx function does use the Internal and InternalHigh members of the OVERLAPPED structure. You should not change the value of these members.
The OVERLAPPED data structure must remain valid for the duration of the write operation. It should not be a variable that can go out of scope while the write operation is pending completion.
lpCompletionRoutine [in, optional]
A pointer to a completion routine to be called when the write operation has been completed and the calling thread is in an alertable wait state. For more information about this completion routine, see FileIOCompletionRoutine .
Return Value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError .
If the WriteFileEx function succeeds, the calling thread has an asynchronous I/O operation pending: the overlapped write operation to the file. When this I/O operation finishes, and the calling thread is blocked in an alertable wait state, the operating system calls the function pointed to by lpCompletionRoutine, and the wait completes with a return code of WAIT_IO_COMPLETION.
If the function succeeds and the file-writing operation finishes, but the calling thread is not in an alertable wait state, the system queues the call to *lpCompletionRoutine, holding the call until the calling thread enters an alertable wait state. For more information about alertable wait states and overlapped input/output operations, see About Synchronization .
Remarks
When using WriteFileEx you should check GetLastError even when the function returns "success" to check for conditions that are "successes" but have some outcome you might want to know about. For example, a buffer overflow when calling WriteFileEx will return TRUE, but GetLastError will report the overflow with ERROR_MORE_DATA. If the function call is successful and there are no warning conditions, GetLastError will return ERROR_SUCCESS.
The WriteFileEx function will fail if the hFile parameter is associated with an I/O completion port . To perform writes using this type of handle, use the WriteFile function.
The WriteFileEx function may fail if there are too many outstanding asynchronous I/O requests. In the event of such a failure, GetLastError can return ERROR_INVALID_USER_BUFFER or ERROR_NOT_ENOUGH_MEMORY.
To cancel all pending asynchronous I/O operations, use either:
CancelIo —this function only cancels operations issued by the calling thread for the specified file handle.
CancelIoEx —this function cancels all operations issued by the threads for the specified file handle.
Use CancelSynchronousIo to cancel pending synchronous I/O operations.
I/O operations that are canceled complete with the error ERROR_OPERATION_ABORTED.
If part of the file specified by hFile is locked by another process, and the specified write operation overlaps the locked portion, WriteFileEx fails.
When writing to a file, the last write time is not fully updated until all handles used for writing have been closed. Therefore, to ensure an accurate last write time, close the file handle immediately after writing to the file.
Accessing the output buffer while a write operation is using the buffer may lead to corruption of the data written from that buffer. Applications must not write to, reallocate, or free the output buffer that a write operation is using until the write operation completes.
Note that the time stamps may not be updated correctly for a remote file. To ensure consistent results, use unbuffered I/O.
The system interprets zero bytes to write as specifying a null write operation and WriteFile does not truncate or extend the file. To truncate or extend a file, use the SetEndOfFile function.
An application uses the WaitForSingleObjectEx , WaitForMultipleObjectsEx , MsgWaitForMultipleObjectsEx , SignalObjectAndWait , and SleepEx functions to enter an alertable wait state. For more information about alertable wait states and overlapped I/O operations, see About Synchronization .
If you write directly to a volume that has a mounted file system, you must first obtain exclusive access to the volume. Otherwise, you risk causing data corruption or system instability, because your application's writes may conflict with other changes coming from the file system and leave the contents of the volume in an inconsistent state. To prevent these problems, the following changes have been made in Windows Vista and later:
A write on a volume handle will succeed if the volume does not have a mounted file system, or if one of the following conditions is true:
The sectors to be written to are boot sectors.
The sectors to be written to reside outside of file system space.
You have explicitly locked or dismounted the volume by using FSCTL_LOCK_VOLUME or FSCTL_DISMOUNT_VOLUME .
The volume has no actual file system. (In other words, it has a RAW file system mounted.)
A write on a disk handle will succeed if one of the following conditions is true:
The sectors to be written to do not fall within a volume's extents.
The sectors to be written to fall within a mounted volume, but you have explicitly locked or dismounted the volume by using FSCTL_LOCK_VOLUME or FSCTL_DISMOUNT_VOLUME.
The sectors to be written to fall within a volume that has no mounted file system other than RAW.
There are strict requirements for successfully working with files opened with CreateFile using FILE_FLAG_NO_BUFFERING. For details see File Buffering .
Transacted Operations
If there is a transaction bound to the file handle, then the file write is transacted. For more information, see About Transactional NTFS .
Examples
For an example, see Named Pipe Server Using Completion Routines .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinBase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
See Also
CancelIo
CancelIoEx
CancelSynchronousIo
CreateFile
File Management Functions
FileIOCompletionRoutine
MsgWaitForMultipleObjectsEx
ReadFileEx
SetEndOfFile
SetErrorMode
SleepEx
SignalObjectAndWait
WaitForMultipleObjectsEx
WaitForSingleObjectEx
WriteFile
Send comments about this topic to Microsoft
Build date: 9/3/2009
==原始网址==http://msdn.microsoft.com/en-us/library/aa365748(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 11:24:32