Win32 API 日本語リファレンス
ホームUI.Shell › SHSetValueA

SHSetValueA

関数
サブキーと値名を指定してレジストリに値を設定する。
DLLSHLWAPI.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// SHLWAPI.dll  (ANSI / -A)
#include <windows.h>

INT SHSetValueA(
    HKEY hkey,
    LPCSTR pszSubKey,   // optional
    LPCSTR pszValue,   // optional
    DWORD dwType,
    const void* pvData,   // optional
    DWORD cbData
);

パラメーター

名前方向
hkeyHKEYin
pszSubKeyLPCSTRinoptional
pszValueLPCSTRinoptional
dwTypeDWORDin
pvDatavoid*inoptional
cbDataDWORDin

戻り値の型: INT

各言語での呼び出し定義

// SHLWAPI.dll  (ANSI / -A)
#include <windows.h>

INT SHSetValueA(
    HKEY hkey,
    LPCSTR pszSubKey,   // optional
    LPCSTR pszValue,   // optional
    DWORD dwType,
    const void* pvData,   // optional
    DWORD cbData
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern int SHSetValueA(
    IntPtr hkey,   // HKEY
    [MarshalAs(UnmanagedType.LPStr)] string pszSubKey,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string pszValue,   // LPCSTR optional
    uint dwType,   // DWORD
    IntPtr pvData,   // void* optional
    uint cbData   // DWORD
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SHSetValueA(
    hkey As IntPtr,   ' HKEY
    <MarshalAs(UnmanagedType.LPStr)> pszSubKey As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> pszValue As String,   ' LPCSTR optional
    dwType As UInteger,   ' DWORD
    pvData As IntPtr,   ' void* optional
    cbData As UInteger   ' DWORD
) As Integer
End Function
' hkey : HKEY
' pszSubKey : LPCSTR optional
' pszValue : LPCSTR optional
' dwType : DWORD
' pvData : void* optional
' cbData : DWORD
Declare PtrSafe Function SHSetValueA Lib "shlwapi" ( _
    ByVal hkey As LongPtr, _
    ByVal pszSubKey As String, _
    ByVal pszValue As String, _
    ByVal dwType As Long, _
    ByVal pvData 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

SHSetValueA = ctypes.windll.shlwapi.SHSetValueA
SHSetValueA.restype = ctypes.c_int
SHSetValueA.argtypes = [
    wintypes.HANDLE,  # hkey : HKEY
    wintypes.LPCSTR,  # pszSubKey : LPCSTR optional
    wintypes.LPCSTR,  # pszValue : LPCSTR 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')
SHSetValueA = Fiddle::Function.new(
  lib['SHSetValueA'],
  [
    Fiddle::TYPE_VOIDP,  # hkey : HKEY
    Fiddle::TYPE_VOIDP,  # pszSubKey : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # pszValue : LPCSTR optional
    -Fiddle::TYPE_INT,  # dwType : DWORD
    Fiddle::TYPE_VOIDP,  # pvData : void* optional
    -Fiddle::TYPE_INT,  # cbData : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "shlwapi")]
extern "system" {
    fn SHSetValueA(
        hkey: *mut core::ffi::c_void,  // HKEY
        pszSubKey: *const u8,  // LPCSTR optional
        pszValue: *const u8,  // LPCSTR 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.Ansi)]
public static extern int SHSetValueA(IntPtr hkey, [MarshalAs(UnmanagedType.LPStr)] string pszSubKey, [MarshalAs(UnmanagedType.LPStr)] string pszValue, uint dwType, IntPtr pvData, uint cbData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_SHSetValueA' -Namespace Win32 -PassThru
# $api::SHSetValueA(hkey, pszSubKey, pszValue, dwType, pvData, cbData)
#uselib "SHLWAPI.dll"
#func global SHSetValueA "SHSetValueA" sptr, sptr, sptr, sptr, sptr, sptr
; SHSetValueA hkey, pszSubKey, pszValue, dwType, pvData, cbData   ; 戻り値は stat
; hkey : HKEY -> "sptr"
; pszSubKey : LPCSTR optional -> "sptr"
; pszValue : LPCSTR optional -> "sptr"
; dwType : DWORD -> "sptr"
; pvData : void* optional -> "sptr"
; cbData : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHLWAPI.dll"
#cfunc global SHSetValueA "SHSetValueA" sptr, str, str, int, sptr, int
; res = SHSetValueA(hkey, pszSubKey, pszValue, dwType, pvData, cbData)
; hkey : HKEY -> "sptr"
; pszSubKey : LPCSTR optional -> "str"
; pszValue : LPCSTR optional -> "str"
; dwType : DWORD -> "int"
; pvData : void* optional -> "sptr"
; cbData : DWORD -> "int"
; INT SHSetValueA(HKEY hkey, LPCSTR pszSubKey, LPCSTR pszValue, DWORD dwType, void* pvData, DWORD cbData)
#uselib "SHLWAPI.dll"
#cfunc global SHSetValueA "SHSetValueA" intptr, str, str, int, intptr, int
; res = SHSetValueA(hkey, pszSubKey, pszValue, dwType, pvData, cbData)
; hkey : HKEY -> "intptr"
; pszSubKey : LPCSTR optional -> "str"
; pszValue : LPCSTR optional -> "str"
; dwType : DWORD -> "int"
; pvData : void* optional -> "intptr"
; cbData : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procSHSetValueA = shlwapi.NewProc("SHSetValueA")
)

// hkey (HKEY), pszSubKey (LPCSTR optional), pszValue (LPCSTR optional), dwType (DWORD), pvData (void* optional), cbData (DWORD)
r1, _, err := procSHSetValueA.Call(
	uintptr(hkey),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pszSubKey))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pszValue))),
	uintptr(dwType),
	uintptr(pvData),
	uintptr(cbData),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function SHSetValueA(
  hkey: THandle;   // HKEY
  pszSubKey: PAnsiChar;   // LPCSTR optional
  pszValue: PAnsiChar;   // LPCSTR optional
  dwType: DWORD;   // DWORD
  pvData: Pointer;   // void* optional
  cbData: DWORD   // DWORD
): Integer; stdcall;
  external 'SHLWAPI.dll' name 'SHSetValueA';
result := DllCall("SHLWAPI\SHSetValueA"
    , "Ptr", hkey   ; HKEY
    , "AStr", pszSubKey   ; LPCSTR optional
    , "AStr", pszValue   ; LPCSTR optional
    , "UInt", dwType   ; DWORD
    , "Ptr", pvData   ; void* optional
    , "UInt", cbData   ; DWORD
    , "Int")   ; return: INT
●SHSetValueA(hkey, pszSubKey, pszValue, dwType, pvData, cbData) = DLL("SHLWAPI.dll", "int SHSetValueA(void*, char*, char*, dword, void*, dword)")
# 呼び出し: SHSetValueA(hkey, pszSubKey, pszValue, dwType, pvData, cbData)
# hkey : HKEY -> "void*"
# pszSubKey : LPCSTR optional -> "char*"
# pszValue : LPCSTR optional -> "char*"
# dwType : DWORD -> "dword"
# pvData : void* optional -> "void*"
# cbData : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。