Win32 API 日本語リファレンス
ホームSystem.RemoteDesktop › WTSFreeMemoryExW

WTSFreeMemoryExW

関数
WTS関数が割り当てた型付きメモリを解放する。
DLLWTSAPI32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 7 以降

シグネチャ

// WTSAPI32.dll  (Unicode / -W)
#include <windows.h>

BOOL WTSFreeMemoryExW(
    WTS_TYPE_CLASS WTSTypeClass,
    void* pMemory,
    DWORD NumberOfEntries
);

パラメーター

名前方向
WTSTypeClassWTS_TYPE_CLASSin
pMemoryvoid*in
NumberOfEntriesDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

// WTSAPI32.dll  (Unicode / -W)
#include <windows.h>

BOOL WTSFreeMemoryExW(
    WTS_TYPE_CLASS WTSTypeClass,
    void* pMemory,
    DWORD NumberOfEntries
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WTSAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool WTSFreeMemoryExW(
    int WTSTypeClass,   // WTS_TYPE_CLASS
    IntPtr pMemory,   // void*
    uint NumberOfEntries   // DWORD
);
<DllImport("WTSAPI32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WTSFreeMemoryExW(
    WTSTypeClass As Integer,   ' WTS_TYPE_CLASS
    pMemory As IntPtr,   ' void*
    NumberOfEntries As UInteger   ' DWORD
) As Boolean
End Function
' WTSTypeClass : WTS_TYPE_CLASS
' pMemory : void*
' NumberOfEntries : DWORD
Declare PtrSafe Function WTSFreeMemoryExW Lib "wtsapi32" ( _
    ByVal WTSTypeClass As Long, _
    ByVal pMemory As LongPtr, _
    ByVal NumberOfEntries As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WTSFreeMemoryExW = ctypes.windll.wtsapi32.WTSFreeMemoryExW
WTSFreeMemoryExW.restype = wintypes.BOOL
WTSFreeMemoryExW.argtypes = [
    ctypes.c_int,  # WTSTypeClass : WTS_TYPE_CLASS
    ctypes.POINTER(None),  # pMemory : void*
    wintypes.DWORD,  # NumberOfEntries : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WTSAPI32.dll')
WTSFreeMemoryExW = Fiddle::Function.new(
  lib['WTSFreeMemoryExW'],
  [
    Fiddle::TYPE_INT,  # WTSTypeClass : WTS_TYPE_CLASS
    Fiddle::TYPE_VOIDP,  # pMemory : void*
    -Fiddle::TYPE_INT,  # NumberOfEntries : DWORD
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "wtsapi32")]
extern "system" {
    fn WTSFreeMemoryExW(
        WTSTypeClass: i32,  // WTS_TYPE_CLASS
        pMemory: *mut (),  // void*
        NumberOfEntries: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WTSAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool WTSFreeMemoryExW(int WTSTypeClass, IntPtr pMemory, uint NumberOfEntries);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WTSAPI32_WTSFreeMemoryExW' -Namespace Win32 -PassThru
# $api::WTSFreeMemoryExW(WTSTypeClass, pMemory, NumberOfEntries)
#uselib "WTSAPI32.dll"
#func global WTSFreeMemoryExW "WTSFreeMemoryExW" wptr, wptr, wptr
; WTSFreeMemoryExW WTSTypeClass, pMemory, NumberOfEntries   ; 戻り値は stat
; WTSTypeClass : WTS_TYPE_CLASS -> "wptr"
; pMemory : void* -> "wptr"
; NumberOfEntries : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WTSAPI32.dll"
#cfunc global WTSFreeMemoryExW "WTSFreeMemoryExW" int, sptr, int
; res = WTSFreeMemoryExW(WTSTypeClass, pMemory, NumberOfEntries)
; WTSTypeClass : WTS_TYPE_CLASS -> "int"
; pMemory : void* -> "sptr"
; NumberOfEntries : DWORD -> "int"
; BOOL WTSFreeMemoryExW(WTS_TYPE_CLASS WTSTypeClass, void* pMemory, DWORD NumberOfEntries)
#uselib "WTSAPI32.dll"
#cfunc global WTSFreeMemoryExW "WTSFreeMemoryExW" int, intptr, int
; res = WTSFreeMemoryExW(WTSTypeClass, pMemory, NumberOfEntries)
; WTSTypeClass : WTS_TYPE_CLASS -> "int"
; pMemory : void* -> "intptr"
; NumberOfEntries : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wtsapi32 = windows.NewLazySystemDLL("WTSAPI32.dll")
	procWTSFreeMemoryExW = wtsapi32.NewProc("WTSFreeMemoryExW")
)

// WTSTypeClass (WTS_TYPE_CLASS), pMemory (void*), NumberOfEntries (DWORD)
r1, _, err := procWTSFreeMemoryExW.Call(
	uintptr(WTSTypeClass),
	uintptr(pMemory),
	uintptr(NumberOfEntries),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function WTSFreeMemoryExW(
  WTSTypeClass: Integer;   // WTS_TYPE_CLASS
  pMemory: Pointer;   // void*
  NumberOfEntries: DWORD   // DWORD
): BOOL; stdcall;
  external 'WTSAPI32.dll' name 'WTSFreeMemoryExW';
result := DllCall("WTSAPI32\WTSFreeMemoryExW"
    , "Int", WTSTypeClass   ; WTS_TYPE_CLASS
    , "Ptr", pMemory   ; void*
    , "UInt", NumberOfEntries   ; DWORD
    , "Int")   ; return: BOOL
●WTSFreeMemoryExW(WTSTypeClass, pMemory, NumberOfEntries) = DLL("WTSAPI32.dll", "bool WTSFreeMemoryExW(int, void*, dword)")
# 呼び出し: WTSFreeMemoryExW(WTSTypeClass, pMemory, NumberOfEntries)
# WTSTypeClass : WTS_TYPE_CLASS -> "int"
# pMemory : void* -> "void*"
# NumberOfEntries : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。