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

IsBadWritePtr

関数
指定範囲が書き込み可能かを検証する(非推奨)。
DLLKERNEL32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

// KERNEL32.dll
#include <windows.h>

BOOL IsBadWritePtr(
    void* lp,   // optional
    UINT_PTR ucb
);

パラメーター

名前方向
lpvoid*inoptional
ucbUINT_PTRin

戻り値の型: BOOL

各言語での呼び出し定義

// KERNEL32.dll
#include <windows.h>

BOOL IsBadWritePtr(
    void* lp,   // optional
    UINT_PTR ucb
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern bool IsBadWritePtr(
    IntPtr lp,   // void* optional
    UIntPtr ucb   // UINT_PTR
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function IsBadWritePtr(
    lp As IntPtr,   ' void* optional
    ucb As UIntPtr   ' UINT_PTR
) As Boolean
End Function
' lp : void* optional
' ucb : UINT_PTR
Declare PtrSafe Function IsBadWritePtr Lib "kernel32" ( _
    ByVal lp As LongPtr, _
    ByVal ucb As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

IsBadWritePtr = ctypes.windll.kernel32.IsBadWritePtr
IsBadWritePtr.restype = wintypes.BOOL
IsBadWritePtr.argtypes = [
    ctypes.POINTER(None),  # lp : void* optional
    ctypes.c_size_t,  # ucb : UINT_PTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
IsBadWritePtr = Fiddle::Function.new(
  lib['IsBadWritePtr'],
  [
    Fiddle::TYPE_VOIDP,  # lp : void* optional
    Fiddle::TYPE_UINTPTR_T,  # ucb : UINT_PTR
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn IsBadWritePtr(
        lp: *mut (),  // void* optional
        ucb: usize  // UINT_PTR
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll")]
public static extern bool IsBadWritePtr(IntPtr lp, UIntPtr ucb);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_IsBadWritePtr' -Namespace Win32 -PassThru
# $api::IsBadWritePtr(lp, ucb)
#uselib "KERNEL32.dll"
#func global IsBadWritePtr "IsBadWritePtr" sptr, sptr
; IsBadWritePtr lp, ucb   ; 戻り値は stat
; lp : void* optional -> "sptr"
; ucb : UINT_PTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global IsBadWritePtr "IsBadWritePtr" sptr, sptr
; res = IsBadWritePtr(lp, ucb)
; lp : void* optional -> "sptr"
; ucb : UINT_PTR -> "sptr"
; BOOL IsBadWritePtr(void* lp, UINT_PTR ucb)
#uselib "KERNEL32.dll"
#cfunc global IsBadWritePtr "IsBadWritePtr" intptr, intptr
; res = IsBadWritePtr(lp, ucb)
; lp : void* optional -> "intptr"
; ucb : UINT_PTR -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procIsBadWritePtr = kernel32.NewProc("IsBadWritePtr")
)

// lp (void* optional), ucb (UINT_PTR)
r1, _, err := procIsBadWritePtr.Call(
	uintptr(lp),
	uintptr(ucb),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function IsBadWritePtr(
  lp: Pointer;   // void* optional
  ucb: NativeUInt   // UINT_PTR
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'IsBadWritePtr';
result := DllCall("KERNEL32\IsBadWritePtr"
    , "Ptr", lp   ; void* optional
    , "UPtr", ucb   ; UINT_PTR
    , "Int")   ; return: BOOL
●IsBadWritePtr(lp, ucb) = DLL("KERNEL32.dll", "bool IsBadWritePtr(void*, int)")
# 呼び出し: IsBadWritePtr(lp, ucb)
# lp : void* optional -> "void*"
# ucb : UINT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。