ホーム › Storage.FileSystem › UnlockFileEx
UnlockFileEx
関数LockFileExでロックした範囲を解除する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL UnlockFileEx(
HANDLE hFile,
DWORD dwReserved, // optional
DWORD nNumberOfBytesToUnlockLow,
DWORD nNumberOfBytesToUnlockHigh,
OVERLAPPED* lpOverlapped
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hFile | HANDLE | in |
| dwReserved | DWORD | optional |
| nNumberOfBytesToUnlockLow | DWORD | in |
| nNumberOfBytesToUnlockHigh | DWORD | in |
| lpOverlapped | OVERLAPPED* | inout |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL UnlockFileEx(
HANDLE hFile,
DWORD dwReserved, // optional
DWORD nNumberOfBytesToUnlockLow,
DWORD nNumberOfBytesToUnlockHigh,
OVERLAPPED* lpOverlapped
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool UnlockFileEx(
IntPtr hFile, // HANDLE
uint dwReserved, // DWORD optional
uint nNumberOfBytesToUnlockLow, // DWORD
uint nNumberOfBytesToUnlockHigh, // DWORD
IntPtr lpOverlapped // OVERLAPPED* in/out
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function UnlockFileEx(
hFile As IntPtr, ' HANDLE
dwReserved As UInteger, ' DWORD optional
nNumberOfBytesToUnlockLow As UInteger, ' DWORD
nNumberOfBytesToUnlockHigh As UInteger, ' DWORD
lpOverlapped As IntPtr ' OVERLAPPED* in/out
) As Boolean
End Function' hFile : HANDLE
' dwReserved : DWORD optional
' nNumberOfBytesToUnlockLow : DWORD
' nNumberOfBytesToUnlockHigh : DWORD
' lpOverlapped : OVERLAPPED* in/out
Declare PtrSafe Function UnlockFileEx Lib "kernel32" ( _
ByVal hFile As LongPtr, _
ByVal dwReserved As Long, _
ByVal nNumberOfBytesToUnlockLow As Long, _
ByVal nNumberOfBytesToUnlockHigh As Long, _
ByVal lpOverlapped As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
UnlockFileEx = ctypes.windll.kernel32.UnlockFileEx
UnlockFileEx.restype = wintypes.BOOL
UnlockFileEx.argtypes = [
wintypes.HANDLE, # hFile : HANDLE
wintypes.DWORD, # dwReserved : DWORD optional
wintypes.DWORD, # nNumberOfBytesToUnlockLow : DWORD
wintypes.DWORD, # nNumberOfBytesToUnlockHigh : DWORD
ctypes.c_void_p, # lpOverlapped : OVERLAPPED* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
UnlockFileEx = Fiddle::Function.new(
lib['UnlockFileEx'],
[
Fiddle::TYPE_VOIDP, # hFile : HANDLE
-Fiddle::TYPE_INT, # dwReserved : DWORD optional
-Fiddle::TYPE_INT, # nNumberOfBytesToUnlockLow : DWORD
-Fiddle::TYPE_INT, # nNumberOfBytesToUnlockHigh : DWORD
Fiddle::TYPE_VOIDP, # lpOverlapped : OVERLAPPED* in/out
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn UnlockFileEx(
hFile: *mut core::ffi::c_void, // HANDLE
dwReserved: u32, // DWORD optional
nNumberOfBytesToUnlockLow: u32, // DWORD
nNumberOfBytesToUnlockHigh: u32, // DWORD
lpOverlapped: *mut OVERLAPPED // OVERLAPPED* in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern bool UnlockFileEx(IntPtr hFile, uint dwReserved, uint nNumberOfBytesToUnlockLow, uint nNumberOfBytesToUnlockHigh, IntPtr lpOverlapped);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_UnlockFileEx' -Namespace Win32 -PassThru
# $api::UnlockFileEx(hFile, dwReserved, nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh, lpOverlapped)#uselib "KERNEL32.dll"
#func global UnlockFileEx "UnlockFileEx" sptr, sptr, sptr, sptr, sptr
; UnlockFileEx hFile, dwReserved, nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh, varptr(lpOverlapped) ; 戻り値は stat
; hFile : HANDLE -> "sptr"
; dwReserved : DWORD optional -> "sptr"
; nNumberOfBytesToUnlockLow : DWORD -> "sptr"
; nNumberOfBytesToUnlockHigh : DWORD -> "sptr"
; lpOverlapped : OVERLAPPED* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global UnlockFileEx "UnlockFileEx" sptr, int, int, int, var ; res = UnlockFileEx(hFile, dwReserved, nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh, lpOverlapped) ; hFile : HANDLE -> "sptr" ; dwReserved : DWORD optional -> "int" ; nNumberOfBytesToUnlockLow : DWORD -> "int" ; nNumberOfBytesToUnlockHigh : DWORD -> "int" ; lpOverlapped : OVERLAPPED* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global UnlockFileEx "UnlockFileEx" sptr, int, int, int, sptr ; res = UnlockFileEx(hFile, dwReserved, nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh, varptr(lpOverlapped)) ; hFile : HANDLE -> "sptr" ; dwReserved : DWORD optional -> "int" ; nNumberOfBytesToUnlockLow : DWORD -> "int" ; nNumberOfBytesToUnlockHigh : DWORD -> "int" ; lpOverlapped : OVERLAPPED* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL UnlockFileEx(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh, OVERLAPPED* lpOverlapped) #uselib "KERNEL32.dll" #cfunc global UnlockFileEx "UnlockFileEx" intptr, int, int, int, var ; res = UnlockFileEx(hFile, dwReserved, nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh, lpOverlapped) ; hFile : HANDLE -> "intptr" ; dwReserved : DWORD optional -> "int" ; nNumberOfBytesToUnlockLow : DWORD -> "int" ; nNumberOfBytesToUnlockHigh : DWORD -> "int" ; lpOverlapped : OVERLAPPED* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL UnlockFileEx(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh, OVERLAPPED* lpOverlapped) #uselib "KERNEL32.dll" #cfunc global UnlockFileEx "UnlockFileEx" intptr, int, int, int, intptr ; res = UnlockFileEx(hFile, dwReserved, nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh, varptr(lpOverlapped)) ; hFile : HANDLE -> "intptr" ; dwReserved : DWORD optional -> "int" ; nNumberOfBytesToUnlockLow : DWORD -> "int" ; nNumberOfBytesToUnlockHigh : DWORD -> "int" ; lpOverlapped : OVERLAPPED* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procUnlockFileEx = kernel32.NewProc("UnlockFileEx")
)
// hFile (HANDLE), dwReserved (DWORD optional), nNumberOfBytesToUnlockLow (DWORD), nNumberOfBytesToUnlockHigh (DWORD), lpOverlapped (OVERLAPPED* in/out)
r1, _, err := procUnlockFileEx.Call(
uintptr(hFile),
uintptr(dwReserved),
uintptr(nNumberOfBytesToUnlockLow),
uintptr(nNumberOfBytesToUnlockHigh),
uintptr(lpOverlapped),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction UnlockFileEx(
hFile: THandle; // HANDLE
dwReserved: DWORD; // DWORD optional
nNumberOfBytesToUnlockLow: DWORD; // DWORD
nNumberOfBytesToUnlockHigh: DWORD; // DWORD
lpOverlapped: Pointer // OVERLAPPED* in/out
): BOOL; stdcall;
external 'KERNEL32.dll' name 'UnlockFileEx';result := DllCall("KERNEL32\UnlockFileEx"
, "Ptr", hFile ; HANDLE
, "UInt", dwReserved ; DWORD optional
, "UInt", nNumberOfBytesToUnlockLow ; DWORD
, "UInt", nNumberOfBytesToUnlockHigh ; DWORD
, "Ptr", lpOverlapped ; OVERLAPPED* in/out
, "Int") ; return: BOOL●UnlockFileEx(hFile, dwReserved, nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh, lpOverlapped) = DLL("KERNEL32.dll", "bool UnlockFileEx(void*, dword, dword, dword, void*)")
# 呼び出し: UnlockFileEx(hFile, dwReserved, nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh, lpOverlapped)
# hFile : HANDLE -> "void*"
# dwReserved : DWORD optional -> "dword"
# nNumberOfBytesToUnlockLow : DWORD -> "dword"
# nNumberOfBytesToUnlockHigh : DWORD -> "dword"
# lpOverlapped : OVERLAPPED* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。