ホーム › System.Memory › RtlCompareMemory
RtlCompareMemory
関数二つのメモリブロックを比較し一致するバイト数を返す。
シグネチャ
// KERNEL32.dll
#include <windows.h>
UINT_PTR RtlCompareMemory(
const void* Source1,
const void* Source2,
UINT_PTR Length
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Source1 | void* | in | 比較する第1メモリブロックへのポインタ。 |
| Source2 | void* | in | 比較する第2メモリブロックへのポインタ。 |
| Length | UINT_PTR | in | 比較するバイト数。戻り値は先頭から一致したバイト数。 |
戻り値の型: UINT_PTR
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
UINT_PTR RtlCompareMemory(
const void* Source1,
const void* Source2,
UINT_PTR Length
);[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern UIntPtr RtlCompareMemory(
IntPtr Source1, // void*
IntPtr Source2, // void*
UIntPtr Length // UINT_PTR
);<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function RtlCompareMemory(
Source1 As IntPtr, ' void*
Source2 As IntPtr, ' void*
Length As UIntPtr ' UINT_PTR
) As UIntPtr
End Function' Source1 : void*
' Source2 : void*
' Length : UINT_PTR
Declare PtrSafe Function RtlCompareMemory Lib "kernel32" ( _
ByVal Source1 As LongPtr, _
ByVal Source2 As LongPtr, _
ByVal Length As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
RtlCompareMemory = ctypes.windll.kernel32.RtlCompareMemory
RtlCompareMemory.restype = ctypes.c_size_t
RtlCompareMemory.argtypes = [
ctypes.POINTER(None), # Source1 : void*
ctypes.POINTER(None), # Source2 : void*
ctypes.c_size_t, # Length : UINT_PTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
RtlCompareMemory = Fiddle::Function.new(
lib['RtlCompareMemory'],
[
Fiddle::TYPE_VOIDP, # Source1 : void*
Fiddle::TYPE_VOIDP, # Source2 : void*
Fiddle::TYPE_UINTPTR_T, # Length : UINT_PTR
],
Fiddle::TYPE_UINTPTR_T)#[link(name = "kernel32")]
extern "system" {
fn RtlCompareMemory(
Source1: *const (), // void*
Source2: *const (), // void*
Length: usize // UINT_PTR
) -> usize;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll")]
public static extern UIntPtr RtlCompareMemory(IntPtr Source1, IntPtr Source2, UIntPtr Length);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_RtlCompareMemory' -Namespace Win32 -PassThru
# $api::RtlCompareMemory(Source1, Source2, Length)#uselib "KERNEL32.dll"
#func global RtlCompareMemory "RtlCompareMemory" sptr, sptr, sptr
; RtlCompareMemory Source1, Source2, Length ; 戻り値は stat
; Source1 : void* -> "sptr"
; Source2 : void* -> "sptr"
; Length : UINT_PTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global RtlCompareMemory "RtlCompareMemory" sptr, sptr, sptr
; res = RtlCompareMemory(Source1, Source2, Length)
; Source1 : void* -> "sptr"
; Source2 : void* -> "sptr"
; Length : UINT_PTR -> "sptr"; UINT_PTR RtlCompareMemory(void* Source1, void* Source2, UINT_PTR Length)
#uselib "KERNEL32.dll"
#cfunc global RtlCompareMemory "RtlCompareMemory" intptr, intptr, intptr
; res = RtlCompareMemory(Source1, Source2, Length)
; Source1 : void* -> "intptr"
; Source2 : void* -> "intptr"
; Length : UINT_PTR -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procRtlCompareMemory = kernel32.NewProc("RtlCompareMemory")
)
// Source1 (void*), Source2 (void*), Length (UINT_PTR)
r1, _, err := procRtlCompareMemory.Call(
uintptr(Source1),
uintptr(Source2),
uintptr(Length),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // UINT_PTRfunction RtlCompareMemory(
Source1: Pointer; // void*
Source2: Pointer; // void*
Length: NativeUInt // UINT_PTR
): NativeUInt; stdcall;
external 'KERNEL32.dll' name 'RtlCompareMemory';result := DllCall("KERNEL32\RtlCompareMemory"
, "Ptr", Source1 ; void*
, "Ptr", Source2 ; void*
, "UPtr", Length ; UINT_PTR
, "UPtr") ; return: UINT_PTR●RtlCompareMemory(Source1, Source2, Length) = DLL("KERNEL32.dll", "int RtlCompareMemory(void*, void*, int)")
# 呼び出し: RtlCompareMemory(Source1, Source2, Length)
# Source1 : void* -> "void*"
# Source2 : void* -> "void*"
# Length : UINT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "kernel32" fn RtlCompareMemory(
Source1: ?*anyopaque, // void*
Source2: ?*anyopaque, // void*
Length: usize // UINT_PTR
) callconv(std.os.windows.WINAPI) usize;proc RtlCompareMemory(
Source1: pointer, # void*
Source2: pointer, # void*
Length: uint # UINT_PTR
): uint {.importc: "RtlCompareMemory", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
size_t RtlCompareMemory(
void* Source1, // void*
void* Source2, // void*
size_t Length // UINT_PTR
);ccall((:RtlCompareMemory, "KERNEL32.dll"), stdcall, Csize_t,
(Ptr{Cvoid}, Ptr{Cvoid}, Csize_t),
Source1, Source2, Length)
# Source1 : void* -> Ptr{Cvoid}
# Source2 : void* -> Ptr{Cvoid}
# Length : UINT_PTR -> Csize_t
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uintptr_t RtlCompareMemory(
void* Source1,
void* Source2,
uintptr_t Length);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.RtlCompareMemory(Source1, Source2, Length)
-- Source1 : void*
-- Source2 : void*
-- Length : UINT_PTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const RtlCompareMemory = lib.func('__stdcall', 'RtlCompareMemory', 'uintptr_t', ['void *', 'void *', 'uintptr_t']);
// RtlCompareMemory(Source1, Source2, Length)
// Source1 : void* -> 'void *'
// Source2 : void* -> 'void *'
// Length : UINT_PTR -> 'uintptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
RtlCompareMemory: { parameters: ["pointer", "pointer", "usize"], result: "usize" },
});
// lib.symbols.RtlCompareMemory(Source1, Source2, Length)
// Source1 : void* -> "pointer"
// Source2 : void* -> "pointer"
// Length : UINT_PTR -> "usize"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
size_t RtlCompareMemory(
void* Source1,
void* Source2,
size_t Length);
C, "KERNEL32.dll");
// $ffi->RtlCompareMemory(Source1, Source2, Length);
// Source1 : void*
// Source2 : 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 Kernel32 extends StdCallLibrary {
Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
long RtlCompareMemory(
Pointer Source1, // void*
Pointer Source2, // void*
long Length // UINT_PTR
);
}@[Link("kernel32")]
lib LibKERNEL32
fun RtlCompareMemory = RtlCompareMemory(
Source1 : Void*, # void*
Source2 : Void*, # void*
Length : LibC::SizeT # UINT_PTR
) : LibC::SizeT
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef RtlCompareMemoryNative = UintPtr Function(Pointer<Void>, Pointer<Void>, UintPtr);
typedef RtlCompareMemoryDart = int Function(Pointer<Void>, Pointer<Void>, int);
final RtlCompareMemory = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<RtlCompareMemoryNative, RtlCompareMemoryDart>('RtlCompareMemory');
// Source1 : void* -> Pointer<Void>
// Source2 : void* -> Pointer<Void>
// Length : UINT_PTR -> UintPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function RtlCompareMemory(
Source1: Pointer; // void*
Source2: Pointer; // void*
Length: NativeUInt // UINT_PTR
): NativeUInt; stdcall;
external 'KERNEL32.dll' name 'RtlCompareMemory';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "RtlCompareMemory"
c_RtlCompareMemory :: Ptr () -> Ptr () -> CUIntPtr -> IO CUIntPtr
-- Source1 : void* -> Ptr ()
-- Source2 : void* -> Ptr ()
-- Length : UINT_PTR -> CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let rtlcomparememory =
foreign "RtlCompareMemory"
((ptr void) @-> (ptr void) @-> size_t @-> returning size_t)
(* Source1 : void* -> (ptr void) *)
(* Source2 : void* -> (ptr void) *)
(* Length : UINT_PTR -> size_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("RtlCompareMemory" rtl-compare-memory :convention :stdcall) :uint64
(source1 :pointer) ; void*
(source2 :pointer) ; void*
(length :uint64)) ; UINT_PTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $RtlCompareMemory = Win32::API::More->new('KERNEL32',
'WPARAM RtlCompareMemory(LPVOID Source1, LPVOID Source2, WPARAM Length)');
# my $ret = $RtlCompareMemory->Call($Source1, $Source2, $Length);
# Source1 : void* -> LPVOID
# Source2 : void* -> LPVOID
# Length : UINT_PTR -> WPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。