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

SHEnumKeyExW

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

シグネチャ

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

WIN32_ERROR SHEnumKeyExW(
    HKEY hkey,
    DWORD dwIndex,
    LPWSTR pszName,
    DWORD* pcchName
);

パラメーター

名前方向
hkeyHKEYin
dwIndexDWORDin
pszNameLPWSTRout
pcchNameDWORD*inout

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

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

SHEnumKeyExW = ctypes.windll.shlwapi.SHEnumKeyExW
SHEnumKeyExW.restype = wintypes.DWORD
SHEnumKeyExW.argtypes = [
    wintypes.HANDLE,  # hkey : HKEY
    wintypes.DWORD,  # dwIndex : DWORD
    wintypes.LPWSTR,  # pszName : LPWSTR out
    ctypes.POINTER(wintypes.DWORD),  # pcchName : DWORD* in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procSHEnumKeyExW = shlwapi.NewProc("SHEnumKeyExW")
)

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