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
lpDataBYTE*in
cbDataDWORDin

戻り値の型: 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)。