网站首页  词典首页

请输入您要查询的函数:

 

术语 lockfile
释义 LockFile
语法:
C++
BOOL WINAPI LockFile(
__in HANDLE hFile,
__in DWORD dwFileOffsetLow,
__in DWORD dwFileOffsetHigh,
__in DWORD nNumberOfBytesToLockLow,
__in DWORD nNumberOfBytesToLockHigh
);
取决于LockFile函数
锁定由调用进程独占访问指定的文件。
向指定附加的选项,使用LockFileEx功能。
参数
hFile [in]
阿处理该文件。文件句柄必须已创建的GENERIC_READ或GENERIC_WRITE访问权限。有关更多信息,请参阅文件安全性和访问权限。
dwFileOffsetLow [in]
的低32位的文件偏移其中锁应该开始的起始字节。
dwFileOffsetHigh [in]
高阶32位的文件偏移其中锁应该开始的起始字节。
nNumberOfBytesToLockLow [in]
在低位的32字节范围的长度位被锁定。
nNumberOfBytesToLockHigh [in]
高阶的32字节范围的长度位被锁定。
返回值
如果函数成功,返回值为非零。
如果函数失败,返回值是零。为了获得更多错误信息,调用GetLastError。
备注
如果对取决于LockFile调用完成同步,一个完成项目可能不会排队完成端口时,与相关的文件句柄。
该UnlockFile函数解锁文件区域的位置取决于LockFile锁定。
锁定一个文件的一个地区提供了锁定进程的线程独占访问指定地区使用此文件句柄。如果该文件句柄是由锁定进程创建一个进程继承,子进程不授予访问锁定的地区。如果锁定进程打开该文件在第二次,也无法通过第二次办理指定地区,直到它解锁地区。
锁定一个文件的一个区域并不妨碍映射文件视图阅读。
您可以锁定字节,超出了当前文件的末尾。这是有用的协调添加记录到一个文件的末尾。
锁可能不会重叠该文件的现有锁定区域。
如果取决于LockFile无法锁定一个文件的一个区域,它立即返回零。它不会阻止。发出文件锁定的请求,将阻塞,直到锁被收购,使用不LOCKFILE_FAIL_IMMEDIATELY LockFileEx。
如果一个进程终止同一个锁定文件的一部分或关闭的文件具有杰出的锁,锁锁定由操作系统。然而,所需的时间,操作系统,以解开这些锁需取决于可用的系统资源。因此,建议您的进程明确解锁所有已锁定的文件时终止。如果不这样做,访问这些文件可能会被拒绝如果操作系统还没有锁定他们。
实例
有关示例,请参阅追加一个文件到另一个文件。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinBase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
参见
CreateFile
文件管理函数
LockFileEx
UnlockFile
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年9月3日
==英文原文==LockFile Function
Locks the specified file for exclusive access by the calling process.
To specify additional options, use the LockFileEx function.
Syntax
C++
BOOL WINAPI LockFile(
__in HANDLE hFile,
__in DWORD dwFileOffsetLow,
__in DWORD dwFileOffsetHigh,
__in DWORD nNumberOfBytesToLockLow,
__in DWORD nNumberOfBytesToLockHigh
);
Parameters
hFile [in]
A handle to the file. The file handle must have been created with the GENERIC_READ or GENERIC_WRITE access right. For more information, see File Security and Access Rights .
dwFileOffsetLow [in]
The low-order 32 bits of the starting byte offset in the file where the lock should begin.
dwFileOffsetHigh [in]
The high-order 32 bits of the starting byte offset in the file where the lock should begin.
nNumberOfBytesToLockLow [in]
The low-order 32 bits of the length of the byte range to be locked.
nNumberOfBytesToLockHigh [in]
The high-order 32 bits of the length of the byte range to be locked.
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 .
Remarks
If the call to LockFile completes synchronously, a completion entry may not be queued when a completion port is associated with the file handle.
The UnlockFile function unlocks a file region locked by LockFile.
Locking a region of a file gives the threads of the locking process 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 region of a file does not prevent reading from a mapped file view.
You can lock bytes that are beyond the end of the current file. This is useful to coordinate adding records to the end of a file.
Locks may not overlap an existing locked region of the file.
If LockFile cannot lock a region of a file, it returns zero immediately. It does not block. To issue a file lock request that will block until the lock is acquired, use LockFileEx without LOCKFILE_FAIL_IMMEDIATELY.
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.
Examples
For an example, see Appending One File to Another File .
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
LockFileEx
UnlockFile
Send comments about this topic to Microsoft
Build date: 9/3/2009
==原始网址==http://msdn.microsoft.com/en-us/library/aa365202(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:26