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

RtlIsZeroMemory

関数
指定バッファがすべてゼロかどうかを判定する。
DLLntdll.dll呼出規約winapi

シグネチャ

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

BOOLEAN RtlIsZeroMemory(
    void* Buffer,
    UINT_PTR Length
);

パラメーター

名前方向説明
Buffervoid*inゼロ判定する対象メモリブロックへのポインタ。
LengthUINT_PTRin判定するバイト数。全てゼロならTRUEを返す。

戻り値の型: BOOLEAN

各言語での呼び出し定義

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

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

RtlIsZeroMemory = ctypes.windll.ntdll.RtlIsZeroMemory
RtlIsZeroMemory.restype = wintypes.BOOLEAN
RtlIsZeroMemory.argtypes = [
    ctypes.POINTER(None),  # Buffer : void*
    ctypes.c_size_t,  # Length : UINT_PTR
]
require 'fiddle'
require 'fiddle/import'

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

var (
	ntdll = windows.NewLazySystemDLL("ntdll.dll")
	procRtlIsZeroMemory = ntdll.NewProc("RtlIsZeroMemory")
)

// Buffer (void*), Length (UINT_PTR)
r1, _, err := procRtlIsZeroMemory.Call(
	uintptr(Buffer),
	uintptr(Length),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOLEAN
function RtlIsZeroMemory(
  Buffer: Pointer;   // void*
  Length: NativeUInt   // UINT_PTR
): ByteBool; stdcall;
  external 'ntdll.dll' name 'RtlIsZeroMemory';
result := DllCall("ntdll\RtlIsZeroMemory"
    , "Ptr", Buffer   ; void*
    , "UPtr", Length   ; UINT_PTR
    , "Char")   ; return: BOOLEAN
●RtlIsZeroMemory(Buffer, Length) = DLL("ntdll.dll", "byte RtlIsZeroMemory(void*, int)")
# 呼び出し: RtlIsZeroMemory(Buffer, Length)
# Buffer : void* -> "void*"
# Length : UINT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "ntdll" fn RtlIsZeroMemory(
    Buffer: ?*anyopaque, // void*
    Length: usize // UINT_PTR
) callconv(std.os.windows.WINAPI) u8;
proc RtlIsZeroMemory(
    Buffer: pointer,  # void*
    Length: uint  # UINT_PTR
): uint8 {.importc: "RtlIsZeroMemory", stdcall, dynlib: "ntdll.dll".}
pragma(lib, "ntdll");
extern(Windows)
ubyte RtlIsZeroMemory(
    void* Buffer,   // void*
    size_t Length   // UINT_PTR
);
ccall((:RtlIsZeroMemory, "ntdll.dll"), stdcall, UInt8,
      (Ptr{Cvoid}, Csize_t),
      Buffer, Length)
# Buffer : void* -> Ptr{Cvoid}
# Length : UINT_PTR -> Csize_t
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint8_t RtlIsZeroMemory(
    void* Buffer,
    uintptr_t Length);
]]
local ntdll = ffi.load("ntdll")
-- ntdll.RtlIsZeroMemory(Buffer, Length)
-- Buffer : void*
-- Length : UINT_PTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ntdll.dll');
const RtlIsZeroMemory = lib.func('__stdcall', 'RtlIsZeroMemory', 'uint8_t', ['void *', 'uintptr_t']);
// RtlIsZeroMemory(Buffer, Length)
// Buffer : void* -> 'void *'
// Length : UINT_PTR -> 'uintptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ntdll.dll", {
  RtlIsZeroMemory: { parameters: ["pointer", "usize"], result: "u8" },
});
// lib.symbols.RtlIsZeroMemory(Buffer, Length)
// Buffer : void* -> "pointer"
// Length : UINT_PTR -> "usize"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint8_t RtlIsZeroMemory(
    void* Buffer,
    size_t Length);
C, "ntdll.dll");
// $ffi->RtlIsZeroMemory(Buffer, Length);
// Buffer : void*
// Length : UINT_PTR
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Ntdll extends StdCallLibrary {
    Ntdll INSTANCE = Native.load("ntdll", Ntdll.class);
    byte RtlIsZeroMemory(
        Pointer Buffer,   // void*
        long Length   // UINT_PTR
    );
}
@[Link("ntdll")]
lib Libntdll
  fun RtlIsZeroMemory = RtlIsZeroMemory(
    Buffer : Void*,   # void*
    Length : LibC::SizeT   # UINT_PTR
  ) : UInt8
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef RtlIsZeroMemoryNative = Uint8 Function(Pointer<Void>, UintPtr);
typedef RtlIsZeroMemoryDart = int Function(Pointer<Void>, int);
final RtlIsZeroMemory = DynamicLibrary.open('ntdll.dll')
    .lookupFunction<RtlIsZeroMemoryNative, RtlIsZeroMemoryDart>('RtlIsZeroMemory');
// Buffer : void* -> Pointer<Void>
// Length : UINT_PTR -> UintPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RtlIsZeroMemory(
  Buffer: Pointer;   // void*
  Length: NativeUInt   // UINT_PTR
): ByteBool; stdcall;
  external 'ntdll.dll' name 'RtlIsZeroMemory';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RtlIsZeroMemory"
  c_RtlIsZeroMemory :: Ptr () -> CUIntPtr -> IO Word8
-- Buffer : void* -> Ptr ()
-- Length : UINT_PTR -> CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let rtliszeromemory =
  foreign "RtlIsZeroMemory"
    ((ptr void) @-> size_t @-> returning uint8_t)
(* Buffer : void* -> (ptr void) *)
(* Length : UINT_PTR -> size_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library ntdll (t "ntdll.dll"))
(cffi:use-foreign-library ntdll)

(cffi:defcfun ("RtlIsZeroMemory" rtl-is-zero-memory :convention :stdcall) :uint8
  (buffer :pointer)   ; void*
  (length :uint64))   ; UINT_PTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RtlIsZeroMemory = Win32::API::More->new('ntdll',
    'BYTE RtlIsZeroMemory(LPVOID Buffer, WPARAM Length)');
# my $ret = $RtlIsZeroMemory->Call($Buffer, $Length);
# Buffer : void* -> LPVOID
# Length : UINT_PTR -> WPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。