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