ホーム › System.Registry › RegSetKeyValueW
RegSetKeyValueW
関数指定サブキー配下に値とデータを設定する。
シグネチャ
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR RegSetKeyValueW(
HKEY hKey,
LPCWSTR lpSubKey, // optional
LPCWSTR lpValueName, // optional
DWORD dwType,
const void* lpData, // optional
DWORD cbData
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hKey | HKEY | in |
| lpSubKey | LPCWSTR | inoptional |
| lpValueName | LPCWSTR | inoptional |
| dwType | DWORD | in |
| lpData | void* | inoptional |
| cbData | DWORD | in |
戻り値の型: WIN32_ERROR
各言語での呼び出し定義
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR RegSetKeyValueW(
HKEY hKey,
LPCWSTR lpSubKey, // optional
LPCWSTR lpValueName, // optional
DWORD dwType,
const void* lpData, // optional
DWORD cbData
);[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint RegSetKeyValueW(
IntPtr hKey, // HKEY
[MarshalAs(UnmanagedType.LPWStr)] string lpSubKey, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string lpValueName, // LPCWSTR optional
uint dwType, // DWORD
IntPtr lpData, // void* optional
uint cbData // DWORD
);<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RegSetKeyValueW(
hKey As IntPtr, ' HKEY
<MarshalAs(UnmanagedType.LPWStr)> lpSubKey As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> lpValueName As String, ' LPCWSTR optional
dwType As UInteger, ' DWORD
lpData As IntPtr, ' void* optional
cbData As UInteger ' DWORD
) As UInteger
End Function' hKey : HKEY
' lpSubKey : LPCWSTR optional
' lpValueName : LPCWSTR optional
' dwType : DWORD
' lpData : void* optional
' cbData : DWORD
Declare PtrSafe Function RegSetKeyValueW Lib "advapi32" ( _
ByVal hKey As LongPtr, _
ByVal lpSubKey As LongPtr, _
ByVal lpValueName As LongPtr, _
ByVal dwType As Long, _
ByVal lpData As LongPtr, _
ByVal cbData As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
RegSetKeyValueW = ctypes.windll.advapi32.RegSetKeyValueW
RegSetKeyValueW.restype = wintypes.DWORD
RegSetKeyValueW.argtypes = [
wintypes.HANDLE, # hKey : HKEY
wintypes.LPCWSTR, # lpSubKey : LPCWSTR optional
wintypes.LPCWSTR, # lpValueName : LPCWSTR optional
wintypes.DWORD, # dwType : DWORD
ctypes.POINTER(None), # lpData : void* optional
wintypes.DWORD, # cbData : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
RegSetKeyValueW = Fiddle::Function.new(
lib['RegSetKeyValueW'],
[
Fiddle::TYPE_VOIDP, # hKey : HKEY
Fiddle::TYPE_VOIDP, # lpSubKey : LPCWSTR optional
Fiddle::TYPE_VOIDP, # lpValueName : LPCWSTR optional
-Fiddle::TYPE_INT, # dwType : DWORD
Fiddle::TYPE_VOIDP, # lpData : void* optional
-Fiddle::TYPE_INT, # cbData : DWORD
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "advapi32")]
extern "system" {
fn RegSetKeyValueW(
hKey: *mut core::ffi::c_void, // HKEY
lpSubKey: *const u16, // LPCWSTR optional
lpValueName: *const u16, // LPCWSTR optional
dwType: u32, // DWORD
lpData: *const (), // void* optional
cbData: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode)]
public static extern uint RegSetKeyValueW(IntPtr hKey, [MarshalAs(UnmanagedType.LPWStr)] string lpSubKey, [MarshalAs(UnmanagedType.LPWStr)] string lpValueName, uint dwType, IntPtr lpData, uint cbData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_RegSetKeyValueW' -Namespace Win32 -PassThru
# $api::RegSetKeyValueW(hKey, lpSubKey, lpValueName, dwType, lpData, cbData)#uselib "ADVAPI32.dll"
#func global RegSetKeyValueW "RegSetKeyValueW" wptr, wptr, wptr, wptr, wptr, wptr
; RegSetKeyValueW hKey, lpSubKey, lpValueName, dwType, lpData, cbData ; 戻り値は stat
; hKey : HKEY -> "wptr"
; lpSubKey : LPCWSTR optional -> "wptr"
; lpValueName : LPCWSTR optional -> "wptr"
; dwType : DWORD -> "wptr"
; lpData : void* optional -> "wptr"
; cbData : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ADVAPI32.dll"
#cfunc global RegSetKeyValueW "RegSetKeyValueW" sptr, wstr, wstr, int, sptr, int
; res = RegSetKeyValueW(hKey, lpSubKey, lpValueName, dwType, lpData, cbData)
; hKey : HKEY -> "sptr"
; lpSubKey : LPCWSTR optional -> "wstr"
; lpValueName : LPCWSTR optional -> "wstr"
; dwType : DWORD -> "int"
; lpData : void* optional -> "sptr"
; cbData : DWORD -> "int"; WIN32_ERROR RegSetKeyValueW(HKEY hKey, LPCWSTR lpSubKey, LPCWSTR lpValueName, DWORD dwType, void* lpData, DWORD cbData)
#uselib "ADVAPI32.dll"
#cfunc global RegSetKeyValueW "RegSetKeyValueW" intptr, wstr, wstr, int, intptr, int
; res = RegSetKeyValueW(hKey, lpSubKey, lpValueName, dwType, lpData, cbData)
; hKey : HKEY -> "intptr"
; lpSubKey : LPCWSTR optional -> "wstr"
; lpValueName : LPCWSTR optional -> "wstr"
; dwType : DWORD -> "int"
; lpData : void* optional -> "intptr"
; cbData : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procRegSetKeyValueW = advapi32.NewProc("RegSetKeyValueW")
)
// hKey (HKEY), lpSubKey (LPCWSTR optional), lpValueName (LPCWSTR optional), dwType (DWORD), lpData (void* optional), cbData (DWORD)
r1, _, err := procRegSetKeyValueW.Call(
uintptr(hKey),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpSubKey))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpValueName))),
uintptr(dwType),
uintptr(lpData),
uintptr(cbData),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction RegSetKeyValueW(
hKey: THandle; // HKEY
lpSubKey: PWideChar; // LPCWSTR optional
lpValueName: PWideChar; // LPCWSTR optional
dwType: DWORD; // DWORD
lpData: Pointer; // void* optional
cbData: DWORD // DWORD
): DWORD; stdcall;
external 'ADVAPI32.dll' name 'RegSetKeyValueW';result := DllCall("ADVAPI32\RegSetKeyValueW"
, "Ptr", hKey ; HKEY
, "WStr", lpSubKey ; LPCWSTR optional
, "WStr", lpValueName ; LPCWSTR optional
, "UInt", dwType ; DWORD
, "Ptr", lpData ; void* optional
, "UInt", cbData ; DWORD
, "UInt") ; return: WIN32_ERROR●RegSetKeyValueW(hKey, lpSubKey, lpValueName, dwType, lpData, cbData) = DLL("ADVAPI32.dll", "dword RegSetKeyValueW(void*, char*, char*, dword, void*, dword)")
# 呼び出し: RegSetKeyValueW(hKey, lpSubKey, lpValueName, dwType, lpData, cbData)
# hKey : HKEY -> "void*"
# lpSubKey : LPCWSTR optional -> "char*"
# lpValueName : LPCWSTR optional -> "char*"
# dwType : DWORD -> "dword"
# lpData : void* optional -> "void*"
# cbData : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。