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