网站首页  词典首页

请输入您要查询的函数:

 

术语 lockfileex
释义 LockFileEx
语法:
C++
BOOL WINAPI LockFileEx(
__in HANDLE hFile,
__in DWORD dwFlags,
__reserved DWORD dwReserved,
__in DWORD nNumberOfBytesToLockLow,
__in DWORD nNumberOfBytesToLockHigh,
__inout LPOVERLAPPED lpOverlapped
);
LockFileEx功能
锁定由调用进程独占访问指定的文件。这个功能可以操作同步或异步。
参数
hFile [in]
阿处理该文件。在处理时一定是要么GENERIC_READ或GENERIC_WRITE访问权限创建。有关更多信息,请参阅文件安全性和访问权限。
dwFlags [in]
此参数可以是一个或多个下列值。
ValueMeaning
LOCKFILE_EXCLUSIVE_LOCK
0x00000002The功能要求独占锁定。否则,它请求一个共享锁。
LOCKFILE_FAIL_IMMEDIATELY
0x00000001The函数立即返回,如果不能获得所请求的锁。否则,它等待。
dwReserved
保留参数,必须设置为零。
nNumberOfBytesToLockLow [in]
在低位的32字节范围的长度位锁定。
nNumberOfBytesToLockHigh [in]
高阶的32字节范围的长度位锁定。
lpOverlapped [ in , out ]
阿要求与指针锁定一个OVERLAPPED结构的函数使用。这种结构,这是必需的,包含了锁的范围开始抵消文件。您必须初始化hEvent成员有效的处理或零。
返回值
如果函数成功,返回值为非零。
如果函数失败,返回值为零或NULL。为了获得更多错误信息,调用GetLastError。
备注
锁定一个文件的一个区域用于获取共享或独占访问指定地区使用此文件句柄。如果该文件句柄是由锁定进程创建一个进程继承,子进程不授予访问锁定的地区。如果锁定进程打开该文件在第二次,也无法通过第二次办理指定地区,直到它解锁地区。
锁定了一个文件的一部分独占访问拒绝所有其他进程读取和写入权限的文件中指定的区域。锁定的区域,超出的电流去年底,文件中的位置是不是一个错误。
锁定了一个共享文件的一部分拒绝访问全过程,包括写权限的进程,首先锁定区域的该文件中指定地区。所有进程可以读取锁定区域。
锁定一个文件的一个区域并不妨碍映射文件视图阅读。
LockFileEx功能的异步操作,如果文件句柄开放供异步I / O,除非LOCKFILE_FAIL_IMMEDIATELY标志被指定。如果一个独占锁定为一个文件,已经有一个共享或独占锁定范围的要求,函数返回错误ERROR_IO_PENDING。该系统将信号OVERLAPPED结构指定的事件之后锁被批准。以决定何时锁已被授予,使用GetOverlappedResult职能或等待职能之一。有关更多信息,请参阅同步和异步I / O。
如果该文件句柄不是为打开异步I / O和锁不可用,此调用等待,直到锁被授予或发生错误,除非LOCKFILE_FAIL_IMMEDIATELY标志被指定。
独占锁不能重叠的一个文件中的现有锁定区域。共享锁锁定可以重叠地区提供锁在该地区举行的只是共享锁。
如果一个进程终止同一个锁定文件的一部分或关闭的文件具有杰出的锁,锁锁定由操作系统。然而,所需的时间,操作系统,以解开这些锁需取决于可用的系统资源。因此,建议您的进程明确解锁所有已锁定的文件时终止。如果不这样做,访问这些文件可能会被拒绝如果操作系统还没有锁定他们。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinBase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
参见
CreateFile
文件管理函数
取决于LockFile
的OVERLAPPED
UnlockFile
UnlockFileEx
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年9月3日
==英文原文==LockFileEx Function
Locks the specified file for exclusive access by the calling process. This function can operate either synchronously or asynchronously.
Syntax
C++
BOOL WINAPI LockFileEx(
__in HANDLE hFile,
__in DWORD dwFlags,
__reserved DWORD dwReserved,
__in DWORD nNumberOfBytesToLockLow,
__in DWORD nNumberOfBytesToLockHigh,
__inout LPOVERLAPPED lpOverlapped
);
Parameters
hFile [in]
A handle to the file. The handle must have been created with either the GENERIC_READ or GENERIC_WRITE access right. For more information, see File Security and Access Rights .
dwFlags [in]
This parameter may be one or more of the following values.
ValueMeaning
LOCKFILE_EXCLUSIVE_LOCK
0x00000002The function requests an exclusive lock. Otherwise, it requests a shared lock.
LOCKFILE_FAIL_IMMEDIATELY
0x00000001The function returns immediately if it is unable to acquire the requested lock. Otherwise, it waits.

dwReserved
Reserved parameter; must be set to zero.
nNumberOfBytesToLockLow [in]
The low-order 32 bits of the length of the byte range to lock.
nNumberOfBytesToLockHigh [in]
The high-order 32 bits of the length of the byte range to lock.
lpOverlapped [in, out]
A pointer to an OVERLAPPED structure that the function uses with the locking request. This structure, which is required, contains the file offset of the beginning of the lock range. You must initialize the hEvent member to a valid handle or zero.
Return Value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero or NULL. To get extended error information, call GetLastError .
Remarks
Locking a region of a file is used to acquire shared or exclusive access to the specified region using this file handle. If the file handle is inherited by a process created by the locking process, the child process is not granted access to the locked region. If the locking process opens the file a second time, it cannot access the specified region through this second handle until it unlocks the region.
Locking a portion of a file for exclusive access denies all other processes both read and write access to the specified region of the file. Locking a region that goes beyond the current end-of-file position is not an error.
Locking a portion of a file for shared access denies all processes write access to the specified region of the file, including the process that first locks the region. All processes can read the locked region.
Locking a region of a file does not prevent reading from a mapped file view.
The LockFileEx function operates asynchronously if the file handle was opened for asynchronous I/O, unless the LOCKFILE_FAIL_IMMEDIATELY flag is specified. If an exclusive lock is requested for a range of a file that already has a shared or exclusive lock, the function returns the error ERROR_IO_PENDING. The system will signal the event specified in the OVERLAPPED structure after the lock is granted. To determine when the lock has been granted, use the GetOverlappedResult function or one of the wait functions . For more information, see Synchronous and Asynchronous I/O .
If the file handle was not opened for asynchronous I/O and the lock is not available, this call waits until the lock is granted or an error occurs, unless the LOCKFILE_FAIL_IMMEDIATELY flag is specified.
Exclusive locks cannot overlap an existing locked region of a file. Shared locks can overlap a locked region provided locks held on that region are only shared locks.
If a process terminates with a portion of a file locked or closes a file that has outstanding locks, the locks are unlocked by the operating system. However, the time it takes for the operating system to unlock these locks depends upon available system resources. Therefore, it is recommended that your process explicitly unlock all files it has locked when it terminates. If this is not done, access to these files may be denied if the operating system has not yet unlocked them.
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinBase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
See Also
CreateFile
File Management Functions
LockFile
OVERLAPPED
UnlockFile
UnlockFileEx
Send comments about this topic to Microsoft
Build date: 9/3/2009
==原始网址==http://msdn.microsoft.com/en-us/library/aa365203(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:19:04