ホーム › Networking.Clustering › ResUtilGetBinaryValue
ResUtilGetBinaryValue
関数クラスタキーからバイナリ値を取得する。
シグネチャ
// RESUTILS.dll
#include <windows.h>
DWORD ResUtilGetBinaryValue(
HKEY hkeyClusterKey,
LPCWSTR pszValueName,
BYTE** ppbOutValue,
DWORD* pcbOutValueSize
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hkeyClusterKey | HKEY | in | バイナリ値を読み取る対象のクラスターレジストリキー。 |
| pszValueName | LPCWSTR | in | 読み取る値の名前を示すワイド文字列。 |
| ppbOutValue | BYTE** | out | 割り当てられたバイナリデータバッファを受け取るポインタ。LocalFreeで解放する。 |
| pcbOutValueSize | DWORD* | out | 読み取ったデータのバイト数を受け取るDWORDポインタ。 |
戻り値の型: DWORD
各言語での呼び出し定義
// RESUTILS.dll
#include <windows.h>
DWORD ResUtilGetBinaryValue(
HKEY hkeyClusterKey,
LPCWSTR pszValueName,
BYTE** ppbOutValue,
DWORD* pcbOutValueSize
);[DllImport("RESUTILS.dll", ExactSpelling = true)]
static extern uint ResUtilGetBinaryValue(
IntPtr hkeyClusterKey, // HKEY
[MarshalAs(UnmanagedType.LPWStr)] string pszValueName, // LPCWSTR
IntPtr ppbOutValue, // BYTE** out
out uint pcbOutValueSize // DWORD* out
);<DllImport("RESUTILS.dll", ExactSpelling:=True)>
Public Shared Function ResUtilGetBinaryValue(
hkeyClusterKey As IntPtr, ' HKEY
<MarshalAs(UnmanagedType.LPWStr)> pszValueName As String, ' LPCWSTR
ppbOutValue As IntPtr, ' BYTE** out
<Out> ByRef pcbOutValueSize As UInteger ' DWORD* out
) As UInteger
End Function' hkeyClusterKey : HKEY
' pszValueName : LPCWSTR
' ppbOutValue : BYTE** out
' pcbOutValueSize : DWORD* out
Declare PtrSafe Function ResUtilGetBinaryValue Lib "resutils" ( _
ByVal hkeyClusterKey As LongPtr, _
ByVal pszValueName As LongPtr, _
ByVal ppbOutValue As LongPtr, _
ByRef pcbOutValueSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ResUtilGetBinaryValue = ctypes.windll.resutils.ResUtilGetBinaryValue
ResUtilGetBinaryValue.restype = wintypes.DWORD
ResUtilGetBinaryValue.argtypes = [
wintypes.HANDLE, # hkeyClusterKey : HKEY
wintypes.LPCWSTR, # pszValueName : LPCWSTR
ctypes.c_void_p, # ppbOutValue : BYTE** out
ctypes.POINTER(wintypes.DWORD), # pcbOutValueSize : DWORD* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('RESUTILS.dll')
ResUtilGetBinaryValue = Fiddle::Function.new(
lib['ResUtilGetBinaryValue'],
[
Fiddle::TYPE_VOIDP, # hkeyClusterKey : HKEY
Fiddle::TYPE_VOIDP, # pszValueName : LPCWSTR
Fiddle::TYPE_VOIDP, # ppbOutValue : BYTE** out
Fiddle::TYPE_VOIDP, # pcbOutValueSize : DWORD* out
],
-Fiddle::TYPE_INT)#[link(name = "resutils")]
extern "system" {
fn ResUtilGetBinaryValue(
hkeyClusterKey: *mut core::ffi::c_void, // HKEY
pszValueName: *const u16, // LPCWSTR
ppbOutValue: *mut *mut u8, // BYTE** out
pcbOutValueSize: *mut u32 // DWORD* out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("RESUTILS.dll")]
public static extern uint ResUtilGetBinaryValue(IntPtr hkeyClusterKey, [MarshalAs(UnmanagedType.LPWStr)] string pszValueName, IntPtr ppbOutValue, out uint pcbOutValueSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'RESUTILS_ResUtilGetBinaryValue' -Namespace Win32 -PassThru
# $api::ResUtilGetBinaryValue(hkeyClusterKey, pszValueName, ppbOutValue, pcbOutValueSize)#uselib "RESUTILS.dll"
#func global ResUtilGetBinaryValue "ResUtilGetBinaryValue" sptr, sptr, sptr, sptr
; ResUtilGetBinaryValue hkeyClusterKey, pszValueName, varptr(ppbOutValue), varptr(pcbOutValueSize) ; 戻り値は stat
; hkeyClusterKey : HKEY -> "sptr"
; pszValueName : LPCWSTR -> "sptr"
; ppbOutValue : BYTE** out -> "sptr"
; pcbOutValueSize : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "RESUTILS.dll" #cfunc global ResUtilGetBinaryValue "ResUtilGetBinaryValue" sptr, wstr, var, var ; res = ResUtilGetBinaryValue(hkeyClusterKey, pszValueName, ppbOutValue, pcbOutValueSize) ; hkeyClusterKey : HKEY -> "sptr" ; pszValueName : LPCWSTR -> "wstr" ; ppbOutValue : BYTE** out -> "var" ; pcbOutValueSize : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "RESUTILS.dll" #cfunc global ResUtilGetBinaryValue "ResUtilGetBinaryValue" sptr, wstr, sptr, sptr ; res = ResUtilGetBinaryValue(hkeyClusterKey, pszValueName, varptr(ppbOutValue), varptr(pcbOutValueSize)) ; hkeyClusterKey : HKEY -> "sptr" ; pszValueName : LPCWSTR -> "wstr" ; ppbOutValue : BYTE** out -> "sptr" ; pcbOutValueSize : DWORD* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD ResUtilGetBinaryValue(HKEY hkeyClusterKey, LPCWSTR pszValueName, BYTE** ppbOutValue, DWORD* pcbOutValueSize) #uselib "RESUTILS.dll" #cfunc global ResUtilGetBinaryValue "ResUtilGetBinaryValue" intptr, wstr, var, var ; res = ResUtilGetBinaryValue(hkeyClusterKey, pszValueName, ppbOutValue, pcbOutValueSize) ; hkeyClusterKey : HKEY -> "intptr" ; pszValueName : LPCWSTR -> "wstr" ; ppbOutValue : BYTE** out -> "var" ; pcbOutValueSize : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD ResUtilGetBinaryValue(HKEY hkeyClusterKey, LPCWSTR pszValueName, BYTE** ppbOutValue, DWORD* pcbOutValueSize) #uselib "RESUTILS.dll" #cfunc global ResUtilGetBinaryValue "ResUtilGetBinaryValue" intptr, wstr, intptr, intptr ; res = ResUtilGetBinaryValue(hkeyClusterKey, pszValueName, varptr(ppbOutValue), varptr(pcbOutValueSize)) ; hkeyClusterKey : HKEY -> "intptr" ; pszValueName : LPCWSTR -> "wstr" ; ppbOutValue : BYTE** out -> "intptr" ; pcbOutValueSize : DWORD* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
resutils = windows.NewLazySystemDLL("RESUTILS.dll")
procResUtilGetBinaryValue = resutils.NewProc("ResUtilGetBinaryValue")
)
// hkeyClusterKey (HKEY), pszValueName (LPCWSTR), ppbOutValue (BYTE** out), pcbOutValueSize (DWORD* out)
r1, _, err := procResUtilGetBinaryValue.Call(
uintptr(hkeyClusterKey),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszValueName))),
uintptr(ppbOutValue),
uintptr(pcbOutValueSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction ResUtilGetBinaryValue(
hkeyClusterKey: THandle; // HKEY
pszValueName: PWideChar; // LPCWSTR
ppbOutValue: Pointer; // BYTE** out
pcbOutValueSize: Pointer // DWORD* out
): DWORD; stdcall;
external 'RESUTILS.dll' name 'ResUtilGetBinaryValue';result := DllCall("RESUTILS\ResUtilGetBinaryValue"
, "Ptr", hkeyClusterKey ; HKEY
, "WStr", pszValueName ; LPCWSTR
, "Ptr", ppbOutValue ; BYTE** out
, "Ptr", pcbOutValueSize ; DWORD* out
, "UInt") ; return: DWORD●ResUtilGetBinaryValue(hkeyClusterKey, pszValueName, ppbOutValue, pcbOutValueSize) = DLL("RESUTILS.dll", "dword ResUtilGetBinaryValue(void*, char*, void*, void*)")
# 呼び出し: ResUtilGetBinaryValue(hkeyClusterKey, pszValueName, ppbOutValue, pcbOutValueSize)
# hkeyClusterKey : HKEY -> "void*"
# pszValueName : LPCWSTR -> "char*"
# ppbOutValue : BYTE** out -> "void*"
# pcbOutValueSize : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "resutils" fn ResUtilGetBinaryValue(
hkeyClusterKey: ?*anyopaque, // HKEY
pszValueName: [*c]const u16, // LPCWSTR
ppbOutValue: [*c][*c]u8, // BYTE** out
pcbOutValueSize: [*c]u32 // DWORD* out
) callconv(std.os.windows.WINAPI) u32;proc ResUtilGetBinaryValue(
hkeyClusterKey: pointer, # HKEY
pszValueName: WideCString, # LPCWSTR
ppbOutValue: ptr uint8, # BYTE** out
pcbOutValueSize: ptr uint32 # DWORD* out
): uint32 {.importc: "ResUtilGetBinaryValue", stdcall, dynlib: "RESUTILS.dll".}pragma(lib, "resutils");
extern(Windows)
uint ResUtilGetBinaryValue(
void* hkeyClusterKey, // HKEY
const(wchar)* pszValueName, // LPCWSTR
ubyte** ppbOutValue, // BYTE** out
uint* pcbOutValueSize // DWORD* out
);ccall((:ResUtilGetBinaryValue, "RESUTILS.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Cwstring, Ptr{UInt8}, Ptr{UInt32}),
hkeyClusterKey, pszValueName, ppbOutValue, pcbOutValueSize)
# hkeyClusterKey : HKEY -> Ptr{Cvoid}
# pszValueName : LPCWSTR -> Cwstring
# ppbOutValue : BYTE** out -> Ptr{UInt8}
# pcbOutValueSize : DWORD* out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t ResUtilGetBinaryValue(
void* hkeyClusterKey,
const uint16_t* pszValueName,
uint8_t** ppbOutValue,
uint32_t* pcbOutValueSize);
]]
local resutils = ffi.load("resutils")
-- resutils.ResUtilGetBinaryValue(hkeyClusterKey, pszValueName, ppbOutValue, pcbOutValueSize)
-- hkeyClusterKey : HKEY
-- pszValueName : LPCWSTR
-- ppbOutValue : BYTE** out
-- pcbOutValueSize : DWORD* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('RESUTILS.dll');
const ResUtilGetBinaryValue = lib.func('__stdcall', 'ResUtilGetBinaryValue', 'uint32_t', ['void *', 'str16', 'uint8_t *', 'uint32_t *']);
// ResUtilGetBinaryValue(hkeyClusterKey, pszValueName, ppbOutValue, pcbOutValueSize)
// hkeyClusterKey : HKEY -> 'void *'
// pszValueName : LPCWSTR -> 'str16'
// ppbOutValue : BYTE** out -> 'uint8_t *'
// pcbOutValueSize : DWORD* out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("RESUTILS.dll", {
ResUtilGetBinaryValue: { parameters: ["pointer", "buffer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.ResUtilGetBinaryValue(hkeyClusterKey, pszValueName, ppbOutValue, pcbOutValueSize)
// hkeyClusterKey : HKEY -> "pointer"
// pszValueName : LPCWSTR -> "buffer"
// ppbOutValue : BYTE** out -> "pointer"
// pcbOutValueSize : DWORD* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t ResUtilGetBinaryValue(
void* hkeyClusterKey,
const uint16_t* pszValueName,
uint8_t** ppbOutValue,
uint32_t* pcbOutValueSize);
C, "RESUTILS.dll");
// $ffi->ResUtilGetBinaryValue(hkeyClusterKey, pszValueName, ppbOutValue, pcbOutValueSize);
// hkeyClusterKey : HKEY
// pszValueName : LPCWSTR
// ppbOutValue : BYTE** out
// pcbOutValueSize : DWORD* out
// 構造体/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 Resutils extends StdCallLibrary {
Resutils INSTANCE = Native.load("resutils", Resutils.class);
int ResUtilGetBinaryValue(
Pointer hkeyClusterKey, // HKEY
WString pszValueName, // LPCWSTR
Pointer ppbOutValue, // BYTE** out
IntByReference pcbOutValueSize // DWORD* out
);
}@[Link("resutils")]
lib LibRESUTILS
fun ResUtilGetBinaryValue = ResUtilGetBinaryValue(
hkeyClusterKey : Void*, # HKEY
pszValueName : UInt16*, # LPCWSTR
ppbOutValue : UInt8**, # BYTE** out
pcbOutValueSize : UInt32* # DWORD* out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ResUtilGetBinaryValueNative = Uint32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Uint8>, Pointer<Uint32>);
typedef ResUtilGetBinaryValueDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Uint8>, Pointer<Uint32>);
final ResUtilGetBinaryValue = DynamicLibrary.open('RESUTILS.dll')
.lookupFunction<ResUtilGetBinaryValueNative, ResUtilGetBinaryValueDart>('ResUtilGetBinaryValue');
// hkeyClusterKey : HKEY -> Pointer<Void>
// pszValueName : LPCWSTR -> Pointer<Utf16>
// ppbOutValue : BYTE** out -> Pointer<Uint8>
// pcbOutValueSize : DWORD* out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ResUtilGetBinaryValue(
hkeyClusterKey: THandle; // HKEY
pszValueName: PWideChar; // LPCWSTR
ppbOutValue: Pointer; // BYTE** out
pcbOutValueSize: Pointer // DWORD* out
): DWORD; stdcall;
external 'RESUTILS.dll' name 'ResUtilGetBinaryValue';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ResUtilGetBinaryValue"
c_ResUtilGetBinaryValue :: Ptr () -> CWString -> Ptr Word8 -> Ptr Word32 -> IO Word32
-- hkeyClusterKey : HKEY -> Ptr ()
-- pszValueName : LPCWSTR -> CWString
-- ppbOutValue : BYTE** out -> Ptr Word8
-- pcbOutValueSize : DWORD* out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let resutilgetbinaryvalue =
foreign "ResUtilGetBinaryValue"
((ptr void) @-> (ptr uint16_t) @-> (ptr uint8_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* hkeyClusterKey : HKEY -> (ptr void) *)
(* pszValueName : LPCWSTR -> (ptr uint16_t) *)
(* ppbOutValue : BYTE** out -> (ptr uint8_t) *)
(* pcbOutValueSize : DWORD* out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library resutils (t "RESUTILS.dll"))
(cffi:use-foreign-library resutils)
(cffi:defcfun ("ResUtilGetBinaryValue" res-util-get-binary-value :convention :stdcall) :uint32
(hkey-cluster-key :pointer) ; HKEY
(psz-value-name (:string :encoding :utf-16le)) ; LPCWSTR
(ppb-out-value :pointer) ; BYTE** out
(pcb-out-value-size :pointer)) ; DWORD* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ResUtilGetBinaryValue = Win32::API::More->new('RESUTILS',
'DWORD ResUtilGetBinaryValue(HANDLE hkeyClusterKey, LPCWSTR pszValueName, LPVOID ppbOutValue, LPVOID pcbOutValueSize)');
# my $ret = $ResUtilGetBinaryValue->Call($hkeyClusterKey, $pszValueName, $ppbOutValue, $pcbOutValueSize);
# hkeyClusterKey : HKEY -> HANDLE
# pszValueName : LPCWSTR -> LPCWSTR
# ppbOutValue : BYTE** out -> LPVOID
# pcbOutValueSize : DWORD* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。