ホーム › System.Memory › IsBadReadPtr
IsBadReadPtr
関数指定範囲が読み取り可能かを検証する(非推奨)。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL IsBadReadPtr(
const void* lp, // optional
UINT_PTR ucb
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lp | void* | inoptional |
| ucb | UINT_PTR | in |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL IsBadReadPtr(
const void* lp, // optional
UINT_PTR ucb
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern bool IsBadReadPtr(
IntPtr lp, // void* optional
UIntPtr ucb // UINT_PTR
);<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function IsBadReadPtr(
lp As IntPtr, ' void* optional
ucb As UIntPtr ' UINT_PTR
) As Boolean
End Function' lp : void* optional
' ucb : UINT_PTR
Declare PtrSafe Function IsBadReadPtr 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
IsBadReadPtr = ctypes.windll.kernel32.IsBadReadPtr
IsBadReadPtr.restype = wintypes.BOOL
IsBadReadPtr.argtypes = [
ctypes.POINTER(None), # lp : void* optional
ctypes.c_size_t, # ucb : UINT_PTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
IsBadReadPtr = Fiddle::Function.new(
lib['IsBadReadPtr'],
[
Fiddle::TYPE_VOIDP, # lp : void* optional
Fiddle::TYPE_UINTPTR_T, # ucb : UINT_PTR
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn IsBadReadPtr(
lp: *const (), // 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 IsBadReadPtr(IntPtr lp, UIntPtr ucb);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_IsBadReadPtr' -Namespace Win32 -PassThru
# $api::IsBadReadPtr(lp, ucb)#uselib "KERNEL32.dll"
#func global IsBadReadPtr "IsBadReadPtr" sptr, sptr
; IsBadReadPtr lp, ucb ; 戻り値は stat
; lp : void* optional -> "sptr"
; ucb : UINT_PTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global IsBadReadPtr "IsBadReadPtr" sptr, sptr
; res = IsBadReadPtr(lp, ucb)
; lp : void* optional -> "sptr"
; ucb : UINT_PTR -> "sptr"; BOOL IsBadReadPtr(void* lp, UINT_PTR ucb)
#uselib "KERNEL32.dll"
#cfunc global IsBadReadPtr "IsBadReadPtr" intptr, intptr
; res = IsBadReadPtr(lp, ucb)
; lp : void* optional -> "intptr"
; ucb : UINT_PTR -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procIsBadReadPtr = kernel32.NewProc("IsBadReadPtr")
)
// lp (void* optional), ucb (UINT_PTR)
r1, _, err := procIsBadReadPtr.Call(
uintptr(lp),
uintptr(ucb),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction IsBadReadPtr(
lp: Pointer; // void* optional
ucb: NativeUInt // UINT_PTR
): BOOL; stdcall;
external 'KERNEL32.dll' name 'IsBadReadPtr';result := DllCall("KERNEL32\IsBadReadPtr"
, "Ptr", lp ; void* optional
, "UPtr", ucb ; UINT_PTR
, "Int") ; return: BOOL●IsBadReadPtr(lp, ucb) = DLL("KERNEL32.dll", "bool IsBadReadPtr(void*, int)")
# 呼び出し: IsBadReadPtr(lp, ucb)
# lp : void* optional -> "void*"
# ucb : UINT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。