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

SHRegCreateUSKeyA

関数
HKCUとHKLMを統合するユーザー単位レジストリキーを作成する。
DLLSHLWAPI.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

WIN32_ERROR SHRegCreateUSKeyA(
    LPCSTR pszPath,
    DWORD samDesired,
    INT_PTR hRelativeUSKey,   // optional
    INT_PTR* phNewUSKey,
    DWORD dwFlags
);

パラメーター

名前方向
pszPathLPCSTRin
samDesiredDWORDin
hRelativeUSKeyINT_PTRinoptional
phNewUSKeyINT_PTR*out
dwFlagsDWORDin

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR SHRegCreateUSKeyA(
    LPCSTR pszPath,
    DWORD samDesired,
    INT_PTR hRelativeUSKey,   // optional
    INT_PTR* phNewUSKey,
    DWORD dwFlags
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint SHRegCreateUSKeyA(
    [MarshalAs(UnmanagedType.LPStr)] string pszPath,   // LPCSTR
    uint samDesired,   // DWORD
    IntPtr hRelativeUSKey,   // INT_PTR optional
    out IntPtr phNewUSKey,   // INT_PTR* out
    uint dwFlags   // DWORD
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SHRegCreateUSKeyA(
    <MarshalAs(UnmanagedType.LPStr)> pszPath As String,   ' LPCSTR
    samDesired As UInteger,   ' DWORD
    hRelativeUSKey As IntPtr,   ' INT_PTR optional
    <Out> ByRef phNewUSKey As IntPtr,   ' INT_PTR* out
    dwFlags As UInteger   ' DWORD
) As UInteger
End Function
' pszPath : LPCSTR
' samDesired : DWORD
' hRelativeUSKey : INT_PTR optional
' phNewUSKey : INT_PTR* out
' dwFlags : DWORD
Declare PtrSafe Function SHRegCreateUSKeyA Lib "shlwapi" ( _
    ByVal pszPath As String, _
    ByVal samDesired As Long, _
    ByVal hRelativeUSKey As LongPtr, _
    ByRef phNewUSKey As LongPtr, _
    ByVal dwFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SHRegCreateUSKeyA = ctypes.windll.shlwapi.SHRegCreateUSKeyA
SHRegCreateUSKeyA.restype = wintypes.DWORD
SHRegCreateUSKeyA.argtypes = [
    wintypes.LPCSTR,  # pszPath : LPCSTR
    wintypes.DWORD,  # samDesired : DWORD
    ctypes.c_ssize_t,  # hRelativeUSKey : INT_PTR optional
    ctypes.POINTER(ctypes.c_ssize_t),  # phNewUSKey : INT_PTR* out
    wintypes.DWORD,  # dwFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
SHRegCreateUSKeyA = Fiddle::Function.new(
  lib['SHRegCreateUSKeyA'],
  [
    Fiddle::TYPE_VOIDP,  # pszPath : LPCSTR
    -Fiddle::TYPE_INT,  # samDesired : DWORD
    Fiddle::TYPE_INTPTR_T,  # hRelativeUSKey : INT_PTR optional
    Fiddle::TYPE_VOIDP,  # phNewUSKey : INT_PTR* out
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
  ],
  -Fiddle::TYPE_INT)
#[link(name = "shlwapi")]
extern "system" {
    fn SHRegCreateUSKeyA(
        pszPath: *const u8,  // LPCSTR
        samDesired: u32,  // DWORD
        hRelativeUSKey: isize,  // INT_PTR optional
        phNewUSKey: *mut isize,  // INT_PTR* out
        dwFlags: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi)]
public static extern uint SHRegCreateUSKeyA([MarshalAs(UnmanagedType.LPStr)] string pszPath, uint samDesired, IntPtr hRelativeUSKey, out IntPtr phNewUSKey, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_SHRegCreateUSKeyA' -Namespace Win32 -PassThru
# $api::SHRegCreateUSKeyA(pszPath, samDesired, hRelativeUSKey, phNewUSKey, dwFlags)
#uselib "SHLWAPI.dll"
#func global SHRegCreateUSKeyA "SHRegCreateUSKeyA" sptr, sptr, sptr, sptr, sptr
; SHRegCreateUSKeyA pszPath, samDesired, hRelativeUSKey, varptr(phNewUSKey), dwFlags   ; 戻り値は stat
; pszPath : LPCSTR -> "sptr"
; samDesired : DWORD -> "sptr"
; hRelativeUSKey : INT_PTR optional -> "sptr"
; phNewUSKey : INT_PTR* out -> "sptr"
; dwFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SHLWAPI.dll"
#cfunc global SHRegCreateUSKeyA "SHRegCreateUSKeyA" str, int, sptr, var, int
; res = SHRegCreateUSKeyA(pszPath, samDesired, hRelativeUSKey, phNewUSKey, dwFlags)
; pszPath : LPCSTR -> "str"
; samDesired : DWORD -> "int"
; hRelativeUSKey : INT_PTR optional -> "sptr"
; phNewUSKey : INT_PTR* out -> "var"
; dwFlags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WIN32_ERROR SHRegCreateUSKeyA(LPCSTR pszPath, DWORD samDesired, INT_PTR hRelativeUSKey, INT_PTR* phNewUSKey, DWORD dwFlags)
#uselib "SHLWAPI.dll"
#cfunc global SHRegCreateUSKeyA "SHRegCreateUSKeyA" str, int, intptr, var, int
; res = SHRegCreateUSKeyA(pszPath, samDesired, hRelativeUSKey, phNewUSKey, dwFlags)
; pszPath : LPCSTR -> "str"
; samDesired : DWORD -> "int"
; hRelativeUSKey : INT_PTR optional -> "intptr"
; phNewUSKey : INT_PTR* out -> "var"
; dwFlags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procSHRegCreateUSKeyA = shlwapi.NewProc("SHRegCreateUSKeyA")
)

// pszPath (LPCSTR), samDesired (DWORD), hRelativeUSKey (INT_PTR optional), phNewUSKey (INT_PTR* out), dwFlags (DWORD)
r1, _, err := procSHRegCreateUSKeyA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pszPath))),
	uintptr(samDesired),
	uintptr(hRelativeUSKey),
	uintptr(phNewUSKey),
	uintptr(dwFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function SHRegCreateUSKeyA(
  pszPath: PAnsiChar;   // LPCSTR
  samDesired: DWORD;   // DWORD
  hRelativeUSKey: NativeInt;   // INT_PTR optional
  phNewUSKey: Pointer;   // INT_PTR* out
  dwFlags: DWORD   // DWORD
): DWORD; stdcall;
  external 'SHLWAPI.dll' name 'SHRegCreateUSKeyA';
result := DllCall("SHLWAPI\SHRegCreateUSKeyA"
    , "AStr", pszPath   ; LPCSTR
    , "UInt", samDesired   ; DWORD
    , "Ptr", hRelativeUSKey   ; INT_PTR optional
    , "Ptr", phNewUSKey   ; INT_PTR* out
    , "UInt", dwFlags   ; DWORD
    , "UInt")   ; return: WIN32_ERROR
●SHRegCreateUSKeyA(pszPath, samDesired, hRelativeUSKey, phNewUSKey, dwFlags) = DLL("SHLWAPI.dll", "dword SHRegCreateUSKeyA(char*, dword, int, void*, dword)")
# 呼び出し: SHRegCreateUSKeyA(pszPath, samDesired, hRelativeUSKey, phNewUSKey, dwFlags)
# pszPath : LPCSTR -> "char*"
# samDesired : DWORD -> "dword"
# hRelativeUSKey : INT_PTR optional -> "int"
# phNewUSKey : INT_PTR* out -> "void*"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。