ホーム › System.Memory › VirtualFree
VirtualFree
関数確保した仮想メモリ領域を解放または解除する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL VirtualFree(
void* lpAddress,
UINT_PTR dwSize,
VIRTUAL_FREE_TYPE dwFreeType
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpAddress | void* | inout |
| dwSize | UINT_PTR | in |
| dwFreeType | VIRTUAL_FREE_TYPE | in |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL VirtualFree(
void* lpAddress,
UINT_PTR dwSize,
VIRTUAL_FREE_TYPE dwFreeType
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool VirtualFree(
IntPtr lpAddress, // void* in/out
UIntPtr dwSize, // UINT_PTR
uint dwFreeType // VIRTUAL_FREE_TYPE
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function VirtualFree(
lpAddress As IntPtr, ' void* in/out
dwSize As UIntPtr, ' UINT_PTR
dwFreeType As UInteger ' VIRTUAL_FREE_TYPE
) As Boolean
End Function' lpAddress : void* in/out
' dwSize : UINT_PTR
' dwFreeType : VIRTUAL_FREE_TYPE
Declare PtrSafe Function VirtualFree Lib "kernel32" ( _
ByVal lpAddress As LongPtr, _
ByVal dwSize As LongPtr, _
ByVal dwFreeType As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
VirtualFree = ctypes.windll.kernel32.VirtualFree
VirtualFree.restype = wintypes.BOOL
VirtualFree.argtypes = [
ctypes.POINTER(None), # lpAddress : void* in/out
ctypes.c_size_t, # dwSize : UINT_PTR
wintypes.DWORD, # dwFreeType : VIRTUAL_FREE_TYPE
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
VirtualFree = Fiddle::Function.new(
lib['VirtualFree'],
[
Fiddle::TYPE_VOIDP, # lpAddress : void* in/out
Fiddle::TYPE_UINTPTR_T, # dwSize : UINT_PTR
-Fiddle::TYPE_INT, # dwFreeType : VIRTUAL_FREE_TYPE
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn VirtualFree(
lpAddress: *mut (), // void* in/out
dwSize: usize, // UINT_PTR
dwFreeType: u32 // VIRTUAL_FREE_TYPE
) -> 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 VirtualFree(IntPtr lpAddress, UIntPtr dwSize, uint dwFreeType);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_VirtualFree' -Namespace Win32 -PassThru
# $api::VirtualFree(lpAddress, dwSize, dwFreeType)#uselib "KERNEL32.dll"
#func global VirtualFree "VirtualFree" sptr, sptr, sptr
; VirtualFree lpAddress, dwSize, dwFreeType ; 戻り値は stat
; lpAddress : void* in/out -> "sptr"
; dwSize : UINT_PTR -> "sptr"
; dwFreeType : VIRTUAL_FREE_TYPE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global VirtualFree "VirtualFree" sptr, sptr, int
; res = VirtualFree(lpAddress, dwSize, dwFreeType)
; lpAddress : void* in/out -> "sptr"
; dwSize : UINT_PTR -> "sptr"
; dwFreeType : VIRTUAL_FREE_TYPE -> "int"; BOOL VirtualFree(void* lpAddress, UINT_PTR dwSize, VIRTUAL_FREE_TYPE dwFreeType)
#uselib "KERNEL32.dll"
#cfunc global VirtualFree "VirtualFree" intptr, intptr, int
; res = VirtualFree(lpAddress, dwSize, dwFreeType)
; lpAddress : void* in/out -> "intptr"
; dwSize : UINT_PTR -> "intptr"
; dwFreeType : VIRTUAL_FREE_TYPE -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procVirtualFree = kernel32.NewProc("VirtualFree")
)
// lpAddress (void* in/out), dwSize (UINT_PTR), dwFreeType (VIRTUAL_FREE_TYPE)
r1, _, err := procVirtualFree.Call(
uintptr(lpAddress),
uintptr(dwSize),
uintptr(dwFreeType),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction VirtualFree(
lpAddress: Pointer; // void* in/out
dwSize: NativeUInt; // UINT_PTR
dwFreeType: DWORD // VIRTUAL_FREE_TYPE
): BOOL; stdcall;
external 'KERNEL32.dll' name 'VirtualFree';result := DllCall("KERNEL32\VirtualFree"
, "Ptr", lpAddress ; void* in/out
, "UPtr", dwSize ; UINT_PTR
, "UInt", dwFreeType ; VIRTUAL_FREE_TYPE
, "Int") ; return: BOOL●VirtualFree(lpAddress, dwSize, dwFreeType) = DLL("KERNEL32.dll", "bool VirtualFree(void*, int, dword)")
# 呼び出し: VirtualFree(lpAddress, dwSize, dwFreeType)
# lpAddress : void* in/out -> "void*"
# dwSize : UINT_PTR -> "int"
# dwFreeType : VIRTUAL_FREE_TYPE -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。