ホーム › System.Memory › IsBadStringPtrA
IsBadStringPtrA
関数ANSI文字列ポインタが読み取り可能かを検証する(非推奨)。
シグネチャ
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
BOOL IsBadStringPtrA(
LPCSTR lpsz, // optional
UINT_PTR ucchMax
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpsz | LPCSTR | inoptional |
| ucchMax | UINT_PTR | in |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
BOOL IsBadStringPtrA(
LPCSTR lpsz, // optional
UINT_PTR ucchMax
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern bool IsBadStringPtrA(
[MarshalAs(UnmanagedType.LPStr)] string lpsz, // LPCSTR optional
UIntPtr ucchMax // UINT_PTR
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function IsBadStringPtrA(
<MarshalAs(UnmanagedType.LPStr)> lpsz As String, ' LPCSTR optional
ucchMax As UIntPtr ' UINT_PTR
) As Boolean
End Function' lpsz : LPCSTR optional
' ucchMax : UINT_PTR
Declare PtrSafe Function IsBadStringPtrA Lib "kernel32" ( _
ByVal lpsz As String, _
ByVal ucchMax As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
IsBadStringPtrA = ctypes.windll.kernel32.IsBadStringPtrA
IsBadStringPtrA.restype = wintypes.BOOL
IsBadStringPtrA.argtypes = [
wintypes.LPCSTR, # lpsz : LPCSTR optional
ctypes.c_size_t, # ucchMax : UINT_PTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
IsBadStringPtrA = Fiddle::Function.new(
lib['IsBadStringPtrA'],
[
Fiddle::TYPE_VOIDP, # lpsz : LPCSTR optional
Fiddle::TYPE_UINTPTR_T, # ucchMax : UINT_PTR
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn IsBadStringPtrA(
lpsz: *const u8, // LPCSTR optional
ucchMax: usize // UINT_PTR
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi)]
public static extern bool IsBadStringPtrA([MarshalAs(UnmanagedType.LPStr)] string lpsz, UIntPtr ucchMax);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_IsBadStringPtrA' -Namespace Win32 -PassThru
# $api::IsBadStringPtrA(lpsz, ucchMax)#uselib "KERNEL32.dll"
#func global IsBadStringPtrA "IsBadStringPtrA" sptr, sptr
; IsBadStringPtrA lpsz, ucchMax ; 戻り値は stat
; lpsz : LPCSTR optional -> "sptr"
; ucchMax : UINT_PTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global IsBadStringPtrA "IsBadStringPtrA" str, sptr
; res = IsBadStringPtrA(lpsz, ucchMax)
; lpsz : LPCSTR optional -> "str"
; ucchMax : UINT_PTR -> "sptr"; BOOL IsBadStringPtrA(LPCSTR lpsz, UINT_PTR ucchMax)
#uselib "KERNEL32.dll"
#cfunc global IsBadStringPtrA "IsBadStringPtrA" str, intptr
; res = IsBadStringPtrA(lpsz, ucchMax)
; lpsz : LPCSTR optional -> "str"
; ucchMax : UINT_PTR -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procIsBadStringPtrA = kernel32.NewProc("IsBadStringPtrA")
)
// lpsz (LPCSTR optional), ucchMax (UINT_PTR)
r1, _, err := procIsBadStringPtrA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpsz))),
uintptr(ucchMax),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction IsBadStringPtrA(
lpsz: PAnsiChar; // LPCSTR optional
ucchMax: NativeUInt // UINT_PTR
): BOOL; stdcall;
external 'KERNEL32.dll' name 'IsBadStringPtrA';result := DllCall("KERNEL32\IsBadStringPtrA"
, "AStr", lpsz ; LPCSTR optional
, "UPtr", ucchMax ; UINT_PTR
, "Int") ; return: BOOL●IsBadStringPtrA(lpsz, ucchMax) = DLL("KERNEL32.dll", "bool IsBadStringPtrA(char*, int)")
# 呼び出し: IsBadStringPtrA(lpsz, ucchMax)
# lpsz : LPCSTR optional -> "char*"
# ucchMax : UINT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。