Win32 API 日本語リファレンス
ホームNetworking.Clustering › ClusterRegSetValueEx

ClusterRegSetValueEx

関数
理由付きでクラスターレジストリキーに値を設定する。
DLLCLUSAPI.dll呼出規約winapi

シグネチャ

// CLUSAPI.dll
#include <windows.h>

DWORD ClusterRegSetValueEx(
    HKEY hKey,
    LPCWSTR lpszValueName,
    DWORD dwType,
    const BYTE* lpData,
    DWORD cbData,
    LPCWSTR lpszReason   // optional
);

パラメーター

名前方向説明
hKeyHKEYin値を設定する対象の開いているクラスターレジストリキー。
lpszValueNameLPCWSTRin設定する値の名前を示すワイド文字列。
dwTypeDWORDin値のデータ型(REG_SZ、REG_DWORD等)。
lpDataBYTE*in書き込むデータを格納したバッファ。
cbDataDWORDinlpDataのサイズ(バイト)。
lpszReasonLPCWSTRinoptional操作理由を示すワイド文字列。監査ログ用でNULL可。

戻り値の型: DWORD

各言語での呼び出し定義

// CLUSAPI.dll
#include <windows.h>

DWORD ClusterRegSetValueEx(
    HKEY hKey,
    LPCWSTR lpszValueName,
    DWORD dwType,
    const BYTE* lpData,
    DWORD cbData,
    LPCWSTR lpszReason   // optional
);
[DllImport("CLUSAPI.dll", ExactSpelling = true)]
static extern uint ClusterRegSetValueEx(
    IntPtr hKey,   // HKEY
    [MarshalAs(UnmanagedType.LPWStr)] string lpszValueName,   // LPCWSTR
    uint dwType,   // DWORD
    IntPtr lpData,   // BYTE*
    uint cbData,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string lpszReason   // LPCWSTR optional
);
<DllImport("CLUSAPI.dll", ExactSpelling:=True)>
Public Shared Function ClusterRegSetValueEx(
    hKey As IntPtr,   ' HKEY
    <MarshalAs(UnmanagedType.LPWStr)> lpszValueName As String,   ' LPCWSTR
    dwType As UInteger,   ' DWORD
    lpData As IntPtr,   ' BYTE*
    cbData As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> lpszReason As String   ' LPCWSTR optional
) As UInteger
End Function
' hKey : HKEY
' lpszValueName : LPCWSTR
' dwType : DWORD
' lpData : BYTE*
' cbData : DWORD
' lpszReason : LPCWSTR optional
Declare PtrSafe Function ClusterRegSetValueEx Lib "clusapi" ( _
    ByVal hKey As LongPtr, _
    ByVal lpszValueName As LongPtr, _
    ByVal dwType As Long, _
    ByVal lpData As LongPtr, _
    ByVal cbData As Long, _
    ByVal lpszReason As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ClusterRegSetValueEx = ctypes.windll.clusapi.ClusterRegSetValueEx
ClusterRegSetValueEx.restype = wintypes.DWORD
ClusterRegSetValueEx.argtypes = [
    wintypes.HANDLE,  # hKey : HKEY
    wintypes.LPCWSTR,  # lpszValueName : LPCWSTR
    wintypes.DWORD,  # dwType : DWORD
    ctypes.POINTER(ctypes.c_ubyte),  # lpData : BYTE*
    wintypes.DWORD,  # cbData : DWORD
    wintypes.LPCWSTR,  # lpszReason : LPCWSTR optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CLUSAPI.dll')
ClusterRegSetValueEx = Fiddle::Function.new(
  lib['ClusterRegSetValueEx'],
  [
    Fiddle::TYPE_VOIDP,  # hKey : HKEY
    Fiddle::TYPE_VOIDP,  # lpszValueName : LPCWSTR
    -Fiddle::TYPE_INT,  # dwType : DWORD
    Fiddle::TYPE_VOIDP,  # lpData : BYTE*
    -Fiddle::TYPE_INT,  # cbData : DWORD
    Fiddle::TYPE_VOIDP,  # lpszReason : LPCWSTR optional
  ],
  -Fiddle::TYPE_INT)
#[link(name = "clusapi")]
extern "system" {
    fn ClusterRegSetValueEx(
        hKey: *mut core::ffi::c_void,  // HKEY
        lpszValueName: *const u16,  // LPCWSTR
        dwType: u32,  // DWORD
        lpData: *const u8,  // BYTE*
        cbData: u32,  // DWORD
        lpszReason: *const u16  // LPCWSTR optional
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("CLUSAPI.dll")]
public static extern uint ClusterRegSetValueEx(IntPtr hKey, [MarshalAs(UnmanagedType.LPWStr)] string lpszValueName, uint dwType, IntPtr lpData, uint cbData, [MarshalAs(UnmanagedType.LPWStr)] string lpszReason);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CLUSAPI_ClusterRegSetValueEx' -Namespace Win32 -PassThru
# $api::ClusterRegSetValueEx(hKey, lpszValueName, dwType, lpData, cbData, lpszReason)
#uselib "CLUSAPI.dll"
#func global ClusterRegSetValueEx "ClusterRegSetValueEx" sptr, sptr, sptr, sptr, sptr, sptr
; ClusterRegSetValueEx hKey, lpszValueName, dwType, varptr(lpData), cbData, lpszReason   ; 戻り値は stat
; hKey : HKEY -> "sptr"
; lpszValueName : LPCWSTR -> "sptr"
; dwType : DWORD -> "sptr"
; lpData : BYTE* -> "sptr"
; cbData : DWORD -> "sptr"
; lpszReason : LPCWSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "CLUSAPI.dll"
#cfunc global ClusterRegSetValueEx "ClusterRegSetValueEx" sptr, wstr, int, var, int, wstr
; res = ClusterRegSetValueEx(hKey, lpszValueName, dwType, lpData, cbData, lpszReason)
; hKey : HKEY -> "sptr"
; lpszValueName : LPCWSTR -> "wstr"
; dwType : DWORD -> "int"
; lpData : BYTE* -> "var"
; cbData : DWORD -> "int"
; lpszReason : LPCWSTR optional -> "wstr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD ClusterRegSetValueEx(HKEY hKey, LPCWSTR lpszValueName, DWORD dwType, BYTE* lpData, DWORD cbData, LPCWSTR lpszReason)
#uselib "CLUSAPI.dll"
#cfunc global ClusterRegSetValueEx "ClusterRegSetValueEx" intptr, wstr, int, var, int, wstr
; res = ClusterRegSetValueEx(hKey, lpszValueName, dwType, lpData, cbData, lpszReason)
; hKey : HKEY -> "intptr"
; lpszValueName : LPCWSTR -> "wstr"
; dwType : DWORD -> "int"
; lpData : BYTE* -> "var"
; cbData : DWORD -> "int"
; lpszReason : LPCWSTR optional -> "wstr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	clusapi = windows.NewLazySystemDLL("CLUSAPI.dll")
	procClusterRegSetValueEx = clusapi.NewProc("ClusterRegSetValueEx")
)

// hKey (HKEY), lpszValueName (LPCWSTR), dwType (DWORD), lpData (BYTE*), cbData (DWORD), lpszReason (LPCWSTR optional)
r1, _, err := procClusterRegSetValueEx.Call(
	uintptr(hKey),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszValueName))),
	uintptr(dwType),
	uintptr(lpData),
	uintptr(cbData),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszReason))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function ClusterRegSetValueEx(
  hKey: THandle;   // HKEY
  lpszValueName: PWideChar;   // LPCWSTR
  dwType: DWORD;   // DWORD
  lpData: Pointer;   // BYTE*
  cbData: DWORD;   // DWORD
  lpszReason: PWideChar   // LPCWSTR optional
): DWORD; stdcall;
  external 'CLUSAPI.dll' name 'ClusterRegSetValueEx';
result := DllCall("CLUSAPI\ClusterRegSetValueEx"
    , "Ptr", hKey   ; HKEY
    , "WStr", lpszValueName   ; LPCWSTR
    , "UInt", dwType   ; DWORD
    , "Ptr", lpData   ; BYTE*
    , "UInt", cbData   ; DWORD
    , "WStr", lpszReason   ; LPCWSTR optional
    , "UInt")   ; return: DWORD
●ClusterRegSetValueEx(hKey, lpszValueName, dwType, lpData, cbData, lpszReason) = DLL("CLUSAPI.dll", "dword ClusterRegSetValueEx(void*, char*, dword, void*, dword, char*)")
# 呼び出し: ClusterRegSetValueEx(hKey, lpszValueName, dwType, lpData, cbData, lpszReason)
# hKey : HKEY -> "void*"
# lpszValueName : LPCWSTR -> "char*"
# dwType : DWORD -> "dword"
# lpData : BYTE* -> "void*"
# cbData : DWORD -> "dword"
# lpszReason : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "clusapi" fn ClusterRegSetValueEx(
    hKey: ?*anyopaque, // HKEY
    lpszValueName: [*c]const u16, // LPCWSTR
    dwType: u32, // DWORD
    lpData: [*c]u8, // BYTE*
    cbData: u32, // DWORD
    lpszReason: [*c]const u16 // LPCWSTR optional
) callconv(std.os.windows.WINAPI) u32;
proc ClusterRegSetValueEx(
    hKey: pointer,  # HKEY
    lpszValueName: WideCString,  # LPCWSTR
    dwType: uint32,  # DWORD
    lpData: ptr uint8,  # BYTE*
    cbData: uint32,  # DWORD
    lpszReason: WideCString  # LPCWSTR optional
): uint32 {.importc: "ClusterRegSetValueEx", stdcall, dynlib: "CLUSAPI.dll".}
pragma(lib, "clusapi");
extern(Windows)
uint ClusterRegSetValueEx(
    void* hKey,   // HKEY
    const(wchar)* lpszValueName,   // LPCWSTR
    uint dwType,   // DWORD
    ubyte* lpData,   // BYTE*
    uint cbData,   // DWORD
    const(wchar)* lpszReason   // LPCWSTR optional
);
ccall((:ClusterRegSetValueEx, "CLUSAPI.dll"), stdcall, UInt32,
      (Ptr{Cvoid}, Cwstring, UInt32, Ptr{UInt8}, UInt32, Cwstring),
      hKey, lpszValueName, dwType, lpData, cbData, lpszReason)
# hKey : HKEY -> Ptr{Cvoid}
# lpszValueName : LPCWSTR -> Cwstring
# dwType : DWORD -> UInt32
# lpData : BYTE* -> Ptr{UInt8}
# cbData : DWORD -> UInt32
# lpszReason : LPCWSTR optional -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t ClusterRegSetValueEx(
    void* hKey,
    const uint16_t* lpszValueName,
    uint32_t dwType,
    uint8_t* lpData,
    uint32_t cbData,
    const uint16_t* lpszReason);
]]
local clusapi = ffi.load("clusapi")
-- clusapi.ClusterRegSetValueEx(hKey, lpszValueName, dwType, lpData, cbData, lpszReason)
-- hKey : HKEY
-- lpszValueName : LPCWSTR
-- dwType : DWORD
-- lpData : BYTE*
-- cbData : DWORD
-- lpszReason : LPCWSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('CLUSAPI.dll');
const ClusterRegSetValueEx = lib.func('__stdcall', 'ClusterRegSetValueEx', 'uint32_t', ['void *', 'str16', 'uint32_t', 'uint8_t *', 'uint32_t', 'str16']);
// ClusterRegSetValueEx(hKey, lpszValueName, dwType, lpData, cbData, lpszReason)
// hKey : HKEY -> 'void *'
// lpszValueName : LPCWSTR -> 'str16'
// dwType : DWORD -> 'uint32_t'
// lpData : BYTE* -> 'uint8_t *'
// cbData : DWORD -> 'uint32_t'
// lpszReason : LPCWSTR optional -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("CLUSAPI.dll", {
  ClusterRegSetValueEx: { parameters: ["pointer", "buffer", "u32", "pointer", "u32", "buffer"], result: "u32" },
});
// lib.symbols.ClusterRegSetValueEx(hKey, lpszValueName, dwType, lpData, cbData, lpszReason)
// hKey : HKEY -> "pointer"
// lpszValueName : LPCWSTR -> "buffer"
// dwType : DWORD -> "u32"
// lpData : BYTE* -> "pointer"
// cbData : DWORD -> "u32"
// lpszReason : LPCWSTR optional -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t ClusterRegSetValueEx(
    void* hKey,
    const uint16_t* lpszValueName,
    uint32_t dwType,
    uint8_t* lpData,
    uint32_t cbData,
    const uint16_t* lpszReason);
C, "CLUSAPI.dll");
// $ffi->ClusterRegSetValueEx(hKey, lpszValueName, dwType, lpData, cbData, lpszReason);
// hKey : HKEY
// lpszValueName : LPCWSTR
// dwType : DWORD
// lpData : BYTE*
// cbData : DWORD
// lpszReason : LPCWSTR optional
// 構造体/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 Clusapi extends StdCallLibrary {
    Clusapi INSTANCE = Native.load("clusapi", Clusapi.class);
    int ClusterRegSetValueEx(
        Pointer hKey,   // HKEY
        WString lpszValueName,   // LPCWSTR
        int dwType,   // DWORD
        byte[] lpData,   // BYTE*
        int cbData,   // DWORD
        WString lpszReason   // LPCWSTR optional
    );
}
@[Link("clusapi")]
lib LibCLUSAPI
  fun ClusterRegSetValueEx = ClusterRegSetValueEx(
    hKey : Void*,   # HKEY
    lpszValueName : UInt16*,   # LPCWSTR
    dwType : UInt32,   # DWORD
    lpData : UInt8*,   # BYTE*
    cbData : UInt32,   # DWORD
    lpszReason : UInt16*   # LPCWSTR optional
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef ClusterRegSetValueExNative = Uint32 Function(Pointer<Void>, Pointer<Utf16>, Uint32, Pointer<Uint8>, Uint32, Pointer<Utf16>);
typedef ClusterRegSetValueExDart = int Function(Pointer<Void>, Pointer<Utf16>, int, Pointer<Uint8>, int, Pointer<Utf16>);
final ClusterRegSetValueEx = DynamicLibrary.open('CLUSAPI.dll')
    .lookupFunction<ClusterRegSetValueExNative, ClusterRegSetValueExDart>('ClusterRegSetValueEx');
// hKey : HKEY -> Pointer<Void>
// lpszValueName : LPCWSTR -> Pointer<Utf16>
// dwType : DWORD -> Uint32
// lpData : BYTE* -> Pointer<Uint8>
// cbData : DWORD -> Uint32
// lpszReason : LPCWSTR optional -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ClusterRegSetValueEx(
  hKey: THandle;   // HKEY
  lpszValueName: PWideChar;   // LPCWSTR
  dwType: DWORD;   // DWORD
  lpData: Pointer;   // BYTE*
  cbData: DWORD;   // DWORD
  lpszReason: PWideChar   // LPCWSTR optional
): DWORD; stdcall;
  external 'CLUSAPI.dll' name 'ClusterRegSetValueEx';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ClusterRegSetValueEx"
  c_ClusterRegSetValueEx :: Ptr () -> CWString -> Word32 -> Ptr Word8 -> Word32 -> CWString -> IO Word32
-- hKey : HKEY -> Ptr ()
-- lpszValueName : LPCWSTR -> CWString
-- dwType : DWORD -> Word32
-- lpData : BYTE* -> Ptr Word8
-- cbData : DWORD -> Word32
-- lpszReason : LPCWSTR optional -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let clusterregsetvalueex =
  foreign "ClusterRegSetValueEx"
    ((ptr void) @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint8_t) @-> uint32_t @-> (ptr uint16_t) @-> returning uint32_t)
(* hKey : HKEY -> (ptr void) *)
(* lpszValueName : LPCWSTR -> (ptr uint16_t) *)
(* dwType : DWORD -> uint32_t *)
(* lpData : BYTE* -> (ptr uint8_t) *)
(* cbData : DWORD -> uint32_t *)
(* lpszReason : LPCWSTR optional -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library clusapi (t "CLUSAPI.dll"))
(cffi:use-foreign-library clusapi)

(cffi:defcfun ("ClusterRegSetValueEx" cluster-reg-set-value-ex :convention :stdcall) :uint32
  (h-key :pointer)   ; HKEY
  (lpsz-value-name (:string :encoding :utf-16le))   ; LPCWSTR
  (dw-type :uint32)   ; DWORD
  (lp-data :pointer)   ; BYTE*
  (cb-data :uint32)   ; DWORD
  (lpsz-reason (:string :encoding :utf-16le)))   ; LPCWSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ClusterRegSetValueEx = Win32::API::More->new('CLUSAPI',
    'DWORD ClusterRegSetValueEx(HANDLE hKey, LPCWSTR lpszValueName, DWORD dwType, LPVOID lpData, DWORD cbData, LPCWSTR lpszReason)');
# my $ret = $ClusterRegSetValueEx->Call($hKey, $lpszValueName, $dwType, $lpData, $cbData, $lpszReason);
# hKey : HKEY -> HANDLE
# lpszValueName : LPCWSTR -> LPCWSTR
# dwType : DWORD -> DWORD
# lpData : BYTE* -> LPVOID
# cbData : DWORD -> DWORD
# lpszReason : LPCWSTR optional -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API