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