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

SHRegOpenUSKeyW

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

シグネチャ

// SHLWAPI.dll  (Unicode / -W)
#include <windows.h>

WIN32_ERROR SHRegOpenUSKeyW(
    LPCWSTR pwzPath,
    DWORD samDesired,
    INT_PTR hRelativeUSKey,   // optional
    INT_PTR* phNewUSKey,
    BOOL fIgnoreHKCU
);

パラメーター

名前方向
pwzPathLPCWSTRin
samDesiredDWORDin
hRelativeUSKeyINT_PTRinoptional
phNewUSKeyINT_PTR*out
fIgnoreHKCUBOOLin

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

// SHLWAPI.dll  (Unicode / -W)
#include <windows.h>

WIN32_ERROR SHRegOpenUSKeyW(
    LPCWSTR pwzPath,
    DWORD samDesired,
    INT_PTR hRelativeUSKey,   // optional
    INT_PTR* phNewUSKey,
    BOOL fIgnoreHKCU
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint SHRegOpenUSKeyW(
    [MarshalAs(UnmanagedType.LPWStr)] string pwzPath,   // LPCWSTR
    uint samDesired,   // DWORD
    IntPtr hRelativeUSKey,   // INT_PTR optional
    out IntPtr phNewUSKey,   // INT_PTR* out
    bool fIgnoreHKCU   // BOOL
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SHRegOpenUSKeyW(
    <MarshalAs(UnmanagedType.LPWStr)> pwzPath As String,   ' LPCWSTR
    samDesired As UInteger,   ' DWORD
    hRelativeUSKey As IntPtr,   ' INT_PTR optional
    <Out> ByRef phNewUSKey As IntPtr,   ' INT_PTR* out
    fIgnoreHKCU As Boolean   ' BOOL
) As UInteger
End Function
' pwzPath : LPCWSTR
' samDesired : DWORD
' hRelativeUSKey : INT_PTR optional
' phNewUSKey : INT_PTR* out
' fIgnoreHKCU : BOOL
Declare PtrSafe Function SHRegOpenUSKeyW Lib "shlwapi" ( _
    ByVal pwzPath As LongPtr, _
    ByVal samDesired As Long, _
    ByVal hRelativeUSKey As LongPtr, _
    ByRef phNewUSKey As LongPtr, _
    ByVal fIgnoreHKCU 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

SHRegOpenUSKeyW = ctypes.windll.shlwapi.SHRegOpenUSKeyW
SHRegOpenUSKeyW.restype = wintypes.DWORD
SHRegOpenUSKeyW.argtypes = [
    wintypes.LPCWSTR,  # pwzPath : LPCWSTR
    wintypes.DWORD,  # samDesired : DWORD
    ctypes.c_ssize_t,  # hRelativeUSKey : INT_PTR optional
    ctypes.POINTER(ctypes.c_ssize_t),  # phNewUSKey : INT_PTR* out
    wintypes.BOOL,  # fIgnoreHKCU : BOOL
]
require 'fiddle'
require 'fiddle/import'

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

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procSHRegOpenUSKeyW = shlwapi.NewProc("SHRegOpenUSKeyW")
)

// pwzPath (LPCWSTR), samDesired (DWORD), hRelativeUSKey (INT_PTR optional), phNewUSKey (INT_PTR* out), fIgnoreHKCU (BOOL)
r1, _, err := procSHRegOpenUSKeyW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwzPath))),
	uintptr(samDesired),
	uintptr(hRelativeUSKey),
	uintptr(phNewUSKey),
	uintptr(fIgnoreHKCU),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function SHRegOpenUSKeyW(
  pwzPath: PWideChar;   // LPCWSTR
  samDesired: DWORD;   // DWORD
  hRelativeUSKey: NativeInt;   // INT_PTR optional
  phNewUSKey: Pointer;   // INT_PTR* out
  fIgnoreHKCU: BOOL   // BOOL
): DWORD; stdcall;
  external 'SHLWAPI.dll' name 'SHRegOpenUSKeyW';
result := DllCall("SHLWAPI\SHRegOpenUSKeyW"
    , "WStr", pwzPath   ; LPCWSTR
    , "UInt", samDesired   ; DWORD
    , "Ptr", hRelativeUSKey   ; INT_PTR optional
    , "Ptr", phNewUSKey   ; INT_PTR* out
    , "Int", fIgnoreHKCU   ; BOOL
    , "UInt")   ; return: WIN32_ERROR
●SHRegOpenUSKeyW(pwzPath, samDesired, hRelativeUSKey, phNewUSKey, fIgnoreHKCU) = DLL("SHLWAPI.dll", "dword SHRegOpenUSKeyW(char*, dword, int, void*, bool)")
# 呼び出し: SHRegOpenUSKeyW(pwzPath, samDesired, hRelativeUSKey, phNewUSKey, fIgnoreHKCU)
# pwzPath : LPCWSTR -> "char*"
# samDesired : DWORD -> "dword"
# hRelativeUSKey : INT_PTR optional -> "int"
# phNewUSKey : INT_PTR* out -> "void*"
# fIgnoreHKCU : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。