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

SHRegEnumUSKeyW

関数
ユーザー単位レジストリキーのサブキーを列挙する。
DLLSHLWAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

WIN32_ERROR SHRegEnumUSKeyW(
    INT_PTR hUSKey,
    DWORD dwIndex,
    LPWSTR pwzName,
    DWORD* pcchName,
    SHREGENUM_FLAGS enumRegFlags
);

パラメーター

名前方向
hUSKeyINT_PTRin
dwIndexDWORDin
pwzNameLPWSTRout
pcchNameDWORD*inout
enumRegFlagsSHREGENUM_FLAGSin

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR SHRegEnumUSKeyW(
    INT_PTR hUSKey,
    DWORD dwIndex,
    LPWSTR pwzName,
    DWORD* pcchName,
    SHREGENUM_FLAGS enumRegFlags
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint SHRegEnumUSKeyW(
    IntPtr hUSKey,   // INT_PTR
    uint dwIndex,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pwzName,   // LPWSTR out
    ref uint pcchName,   // DWORD* in/out
    int enumRegFlags   // SHREGENUM_FLAGS
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SHRegEnumUSKeyW(
    hUSKey As IntPtr,   ' INT_PTR
    dwIndex As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> pwzName As System.Text.StringBuilder,   ' LPWSTR out
    ByRef pcchName As UInteger,   ' DWORD* in/out
    enumRegFlags As Integer   ' SHREGENUM_FLAGS
) As UInteger
End Function
' hUSKey : INT_PTR
' dwIndex : DWORD
' pwzName : LPWSTR out
' pcchName : DWORD* in/out
' enumRegFlags : SHREGENUM_FLAGS
Declare PtrSafe Function SHRegEnumUSKeyW Lib "shlwapi" ( _
    ByVal hUSKey As LongPtr, _
    ByVal dwIndex As Long, _
    ByVal pwzName As LongPtr, _
    ByRef pcchName As Long, _
    ByVal enumRegFlags 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

SHRegEnumUSKeyW = ctypes.windll.shlwapi.SHRegEnumUSKeyW
SHRegEnumUSKeyW.restype = wintypes.DWORD
SHRegEnumUSKeyW.argtypes = [
    ctypes.c_ssize_t,  # hUSKey : INT_PTR
    wintypes.DWORD,  # dwIndex : DWORD
    wintypes.LPWSTR,  # pwzName : LPWSTR out
    ctypes.POINTER(wintypes.DWORD),  # pcchName : DWORD* in/out
    ctypes.c_int,  # enumRegFlags : SHREGENUM_FLAGS
]
require 'fiddle'
require 'fiddle/import'

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

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procSHRegEnumUSKeyW = shlwapi.NewProc("SHRegEnumUSKeyW")
)

// hUSKey (INT_PTR), dwIndex (DWORD), pwzName (LPWSTR out), pcchName (DWORD* in/out), enumRegFlags (SHREGENUM_FLAGS)
r1, _, err := procSHRegEnumUSKeyW.Call(
	uintptr(hUSKey),
	uintptr(dwIndex),
	uintptr(pwzName),
	uintptr(pcchName),
	uintptr(enumRegFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function SHRegEnumUSKeyW(
  hUSKey: NativeInt;   // INT_PTR
  dwIndex: DWORD;   // DWORD
  pwzName: PWideChar;   // LPWSTR out
  pcchName: Pointer;   // DWORD* in/out
  enumRegFlags: Integer   // SHREGENUM_FLAGS
): DWORD; stdcall;
  external 'SHLWAPI.dll' name 'SHRegEnumUSKeyW';
result := DllCall("SHLWAPI\SHRegEnumUSKeyW"
    , "Ptr", hUSKey   ; INT_PTR
    , "UInt", dwIndex   ; DWORD
    , "Ptr", pwzName   ; LPWSTR out
    , "Ptr", pcchName   ; DWORD* in/out
    , "Int", enumRegFlags   ; SHREGENUM_FLAGS
    , "UInt")   ; return: WIN32_ERROR
●SHRegEnumUSKeyW(hUSKey, dwIndex, pwzName, pcchName, enumRegFlags) = DLL("SHLWAPI.dll", "dword SHRegEnumUSKeyW(int, dword, char*, void*, int)")
# 呼び出し: SHRegEnumUSKeyW(hUSKey, dwIndex, pwzName, pcchName, enumRegFlags)
# hUSKey : INT_PTR -> "int"
# dwIndex : DWORD -> "dword"
# pwzName : LPWSTR out -> "char*"
# pcchName : DWORD* in/out -> "void*"
# enumRegFlags : SHREGENUM_FLAGS -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。