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