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

ClusterRegSetValue

関数
クラスターレジストリキーに値を設定する。
DLLCLUSAPI.dll呼出規約winapiSetLastErrorあり対応OSwindowsserver2008

シグネチャ

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

DWORD ClusterRegSetValue(
    HKEY hKey,
    LPCWSTR lpszValueName,
    DWORD dwType,
    const BYTE* lpData,
    DWORD cbData
);

パラメーター

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

戻り値の型: DWORD

各言語での呼び出し定義

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

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

ClusterRegSetValue = ctypes.windll.clusapi.ClusterRegSetValue
ClusterRegSetValue.restype = wintypes.DWORD
ClusterRegSetValue.argtypes = [
    wintypes.HANDLE,  # hKey : HKEY
    wintypes.LPCWSTR,  # lpszValueName : LPCWSTR
    wintypes.DWORD,  # dwType : DWORD
    ctypes.POINTER(ctypes.c_ubyte),  # lpData : BYTE*
    wintypes.DWORD,  # cbData : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	clusapi = windows.NewLazySystemDLL("CLUSAPI.dll")
	procClusterRegSetValue = clusapi.NewProc("ClusterRegSetValue")
)

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

extern "clusapi" fn ClusterRegSetValue(
    hKey: ?*anyopaque, // HKEY
    lpszValueName: [*c]const u16, // LPCWSTR
    dwType: u32, // DWORD
    lpData: [*c]u8, // BYTE*
    cbData: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
proc ClusterRegSetValue(
    hKey: pointer,  # HKEY
    lpszValueName: WideCString,  # LPCWSTR
    dwType: uint32,  # DWORD
    lpData: ptr uint8,  # BYTE*
    cbData: uint32  # DWORD
): uint32 {.importc: "ClusterRegSetValue", stdcall, dynlib: "CLUSAPI.dll".}
pragma(lib, "clusapi");
extern(Windows)
uint ClusterRegSetValue(
    void* hKey,   // HKEY
    const(wchar)* lpszValueName,   // LPCWSTR
    uint dwType,   // DWORD
    ubyte* lpData,   // BYTE*
    uint cbData   // DWORD
);
ccall((:ClusterRegSetValue, "CLUSAPI.dll"), stdcall, UInt32,
      (Ptr{Cvoid}, Cwstring, UInt32, Ptr{UInt8}, UInt32),
      hKey, lpszValueName, dwType, lpData, cbData)
# hKey : HKEY -> Ptr{Cvoid}
# lpszValueName : LPCWSTR -> Cwstring
# dwType : DWORD -> UInt32
# lpData : BYTE* -> Ptr{UInt8}
# cbData : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t ClusterRegSetValue(
    void* hKey,
    const uint16_t* lpszValueName,
    uint32_t dwType,
    uint8_t* lpData,
    uint32_t cbData);
]]
local clusapi = ffi.load("clusapi")
-- clusapi.ClusterRegSetValue(hKey, lpszValueName, dwType, lpData, cbData)
-- hKey : HKEY
-- lpszValueName : LPCWSTR
-- dwType : DWORD
-- lpData : BYTE*
-- cbData : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('CLUSAPI.dll');
const ClusterRegSetValue = lib.func('__stdcall', 'ClusterRegSetValue', 'uint32_t', ['void *', 'str16', 'uint32_t', 'uint8_t *', 'uint32_t']);
// ClusterRegSetValue(hKey, lpszValueName, dwType, lpData, cbData)
// hKey : HKEY -> 'void *'
// lpszValueName : LPCWSTR -> 'str16'
// dwType : DWORD -> 'uint32_t'
// lpData : BYTE* -> 'uint8_t *'
// cbData : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("CLUSAPI.dll", {
  ClusterRegSetValue: { parameters: ["pointer", "buffer", "u32", "pointer", "u32"], result: "u32" },
});
// lib.symbols.ClusterRegSetValue(hKey, lpszValueName, dwType, lpData, cbData)
// hKey : HKEY -> "pointer"
// lpszValueName : LPCWSTR -> "buffer"
// dwType : DWORD -> "u32"
// lpData : BYTE* -> "pointer"
// cbData : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t ClusterRegSetValue(
    void* hKey,
    const uint16_t* lpszValueName,
    uint32_t dwType,
    uint8_t* lpData,
    uint32_t cbData);
C, "CLUSAPI.dll");
// $ffi->ClusterRegSetValue(hKey, lpszValueName, dwType, lpData, cbData);
// hKey : HKEY
// lpszValueName : LPCWSTR
// dwType : DWORD
// lpData : BYTE*
// cbData : 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 Clusapi extends StdCallLibrary {
    Clusapi INSTANCE = Native.load("clusapi", Clusapi.class);
    int ClusterRegSetValue(
        Pointer hKey,   // HKEY
        WString lpszValueName,   // LPCWSTR
        int dwType,   // DWORD
        byte[] lpData,   // BYTE*
        int cbData   // DWORD
    );
}
@[Link("clusapi")]
lib LibCLUSAPI
  fun ClusterRegSetValue = ClusterRegSetValue(
    hKey : Void*,   # HKEY
    lpszValueName : UInt16*,   # LPCWSTR
    dwType : UInt32,   # DWORD
    lpData : UInt8*,   # BYTE*
    cbData : 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 ClusterRegSetValueNative = Uint32 Function(Pointer<Void>, Pointer<Utf16>, Uint32, Pointer<Uint8>, Uint32);
typedef ClusterRegSetValueDart = int Function(Pointer<Void>, Pointer<Utf16>, int, Pointer<Uint8>, int);
final ClusterRegSetValue = DynamicLibrary.open('CLUSAPI.dll')
    .lookupFunction<ClusterRegSetValueNative, ClusterRegSetValueDart>('ClusterRegSetValue');
// hKey : HKEY -> Pointer<Void>
// lpszValueName : LPCWSTR -> Pointer<Utf16>
// dwType : DWORD -> Uint32
// lpData : BYTE* -> Pointer<Uint8>
// cbData : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ClusterRegSetValue(
  hKey: THandle;   // HKEY
  lpszValueName: PWideChar;   // LPCWSTR
  dwType: DWORD;   // DWORD
  lpData: Pointer;   // BYTE*
  cbData: DWORD   // DWORD
): DWORD; stdcall;
  external 'CLUSAPI.dll' name 'ClusterRegSetValue';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let clusterregsetvalue =
  foreign "ClusterRegSetValue"
    ((ptr void) @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint8_t) @-> uint32_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 *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library clusapi (t "CLUSAPI.dll"))
(cffi:use-foreign-library clusapi)

(cffi:defcfun ("ClusterRegSetValue" cluster-reg-set-value :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
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ClusterRegSetValue = Win32::API::More->new('CLUSAPI',
    'DWORD ClusterRegSetValue(HANDLE hKey, LPCWSTR lpszValueName, DWORD dwType, LPVOID lpData, DWORD cbData)');
# my $ret = $ClusterRegSetValue->Call($hKey, $lpszValueName, $dwType, $lpData, $cbData);
# hKey : HKEY -> HANDLE
# lpszValueName : LPCWSTR -> LPCWSTR
# dwType : DWORD -> DWORD
# lpData : BYTE* -> LPVOID
# cbData : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API