ホーム › System.Registry › RegEnumKeyExW
RegEnumKeyExW
関数サブキー名やクラス、最終更新時刻を列挙して取得する。
シグネチャ
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR RegEnumKeyExW(
HKEY hKey,
DWORD dwIndex,
LPWSTR lpName, // optional
DWORD* lpcchName,
DWORD* lpReserved, // optional
LPWSTR lpClass, // optional
DWORD* lpcchClass, // optional
FILETIME* lpftLastWriteTime // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hKey | HKEY | in |
| dwIndex | DWORD | in |
| lpName | LPWSTR | outoptional |
| lpcchName | DWORD* | inout |
| lpReserved | DWORD* | optional |
| lpClass | LPWSTR | outoptional |
| lpcchClass | DWORD* | inoutoptional |
| lpftLastWriteTime | FILETIME* | outoptional |
戻り値の型: WIN32_ERROR
各言語での呼び出し定義
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR RegEnumKeyExW(
HKEY hKey,
DWORD dwIndex,
LPWSTR lpName, // optional
DWORD* lpcchName,
DWORD* lpReserved, // optional
LPWSTR lpClass, // optional
DWORD* lpcchClass, // optional
FILETIME* lpftLastWriteTime // optional
);[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint RegEnumKeyExW(
IntPtr hKey, // HKEY
uint dwIndex, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpName, // LPWSTR optional, out
ref uint lpcchName, // DWORD* in/out
IntPtr lpReserved, // DWORD* optional
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpClass, // LPWSTR optional, out
IntPtr lpcchClass, // DWORD* optional, in/out
IntPtr lpftLastWriteTime // FILETIME* optional, out
);<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RegEnumKeyExW(
hKey As IntPtr, ' HKEY
dwIndex As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> lpName As System.Text.StringBuilder, ' LPWSTR optional, out
ByRef lpcchName As UInteger, ' DWORD* in/out
lpReserved As IntPtr, ' DWORD* optional
<MarshalAs(UnmanagedType.LPWStr)> lpClass As System.Text.StringBuilder, ' LPWSTR optional, out
lpcchClass As IntPtr, ' DWORD* optional, in/out
lpftLastWriteTime As IntPtr ' FILETIME* optional, out
) As UInteger
End Function' hKey : HKEY
' dwIndex : DWORD
' lpName : LPWSTR optional, out
' lpcchName : DWORD* in/out
' lpReserved : DWORD* optional
' lpClass : LPWSTR optional, out
' lpcchClass : DWORD* optional, in/out
' lpftLastWriteTime : FILETIME* optional, out
Declare PtrSafe Function RegEnumKeyExW Lib "advapi32" ( _
ByVal hKey As LongPtr, _
ByVal dwIndex As Long, _
ByVal lpName As LongPtr, _
ByRef lpcchName As Long, _
ByVal lpReserved As LongPtr, _
ByVal lpClass As LongPtr, _
ByVal lpcchClass As LongPtr, _
ByVal lpftLastWriteTime As LongPtr) 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
RegEnumKeyExW = ctypes.windll.advapi32.RegEnumKeyExW
RegEnumKeyExW.restype = wintypes.DWORD
RegEnumKeyExW.argtypes = [
wintypes.HANDLE, # hKey : HKEY
wintypes.DWORD, # dwIndex : DWORD
wintypes.LPWSTR, # lpName : LPWSTR optional, out
ctypes.POINTER(wintypes.DWORD), # lpcchName : DWORD* in/out
ctypes.POINTER(wintypes.DWORD), # lpReserved : DWORD* optional
wintypes.LPWSTR, # lpClass : LPWSTR optional, out
ctypes.POINTER(wintypes.DWORD), # lpcchClass : DWORD* optional, in/out
ctypes.c_void_p, # lpftLastWriteTime : FILETIME* optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
RegEnumKeyExW = Fiddle::Function.new(
lib['RegEnumKeyExW'],
[
Fiddle::TYPE_VOIDP, # hKey : HKEY
-Fiddle::TYPE_INT, # dwIndex : DWORD
Fiddle::TYPE_VOIDP, # lpName : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # lpcchName : DWORD* in/out
Fiddle::TYPE_VOIDP, # lpReserved : DWORD* optional
Fiddle::TYPE_VOIDP, # lpClass : LPWSTR optional, out
Fiddle::TYPE_VOIDP, # lpcchClass : DWORD* optional, in/out
Fiddle::TYPE_VOIDP, # lpftLastWriteTime : FILETIME* optional, out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "advapi32")]
extern "system" {
fn RegEnumKeyExW(
hKey: *mut core::ffi::c_void, // HKEY
dwIndex: u32, // DWORD
lpName: *mut u16, // LPWSTR optional, out
lpcchName: *mut u32, // DWORD* in/out
lpReserved: *mut u32, // DWORD* optional
lpClass: *mut u16, // LPWSTR optional, out
lpcchClass: *mut u32, // DWORD* optional, in/out
lpftLastWriteTime: *mut FILETIME // FILETIME* optional, out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode)]
public static extern uint RegEnumKeyExW(IntPtr hKey, uint dwIndex, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpName, ref uint lpcchName, IntPtr lpReserved, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpClass, IntPtr lpcchClass, IntPtr lpftLastWriteTime);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_RegEnumKeyExW' -Namespace Win32 -PassThru
# $api::RegEnumKeyExW(hKey, dwIndex, lpName, lpcchName, lpReserved, lpClass, lpcchClass, lpftLastWriteTime)#uselib "ADVAPI32.dll"
#func global RegEnumKeyExW "RegEnumKeyExW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; RegEnumKeyExW hKey, dwIndex, varptr(lpName), varptr(lpcchName), varptr(lpReserved), varptr(lpClass), varptr(lpcchClass), varptr(lpftLastWriteTime) ; 戻り値は stat
; hKey : HKEY -> "wptr"
; dwIndex : DWORD -> "wptr"
; lpName : LPWSTR optional, out -> "wptr"
; lpcchName : DWORD* in/out -> "wptr"
; lpReserved : DWORD* optional -> "wptr"
; lpClass : LPWSTR optional, out -> "wptr"
; lpcchClass : DWORD* optional, in/out -> "wptr"
; lpftLastWriteTime : FILETIME* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ADVAPI32.dll" #cfunc global RegEnumKeyExW "RegEnumKeyExW" sptr, int, var, var, var, var, var, var ; res = RegEnumKeyExW(hKey, dwIndex, lpName, lpcchName, lpReserved, lpClass, lpcchClass, lpftLastWriteTime) ; hKey : HKEY -> "sptr" ; dwIndex : DWORD -> "int" ; lpName : LPWSTR optional, out -> "var" ; lpcchName : DWORD* in/out -> "var" ; lpReserved : DWORD* optional -> "var" ; lpClass : LPWSTR optional, out -> "var" ; lpcchClass : DWORD* optional, in/out -> "var" ; lpftLastWriteTime : FILETIME* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global RegEnumKeyExW "RegEnumKeyExW" sptr, int, sptr, sptr, sptr, sptr, sptr, sptr ; res = RegEnumKeyExW(hKey, dwIndex, varptr(lpName), varptr(lpcchName), varptr(lpReserved), varptr(lpClass), varptr(lpcchClass), varptr(lpftLastWriteTime)) ; hKey : HKEY -> "sptr" ; dwIndex : DWORD -> "int" ; lpName : LPWSTR optional, out -> "sptr" ; lpcchName : DWORD* in/out -> "sptr" ; lpReserved : DWORD* optional -> "sptr" ; lpClass : LPWSTR optional, out -> "sptr" ; lpcchClass : DWORD* optional, in/out -> "sptr" ; lpftLastWriteTime : FILETIME* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; WIN32_ERROR RegEnumKeyExW(HKEY hKey, DWORD dwIndex, LPWSTR lpName, DWORD* lpcchName, DWORD* lpReserved, LPWSTR lpClass, DWORD* lpcchClass, FILETIME* lpftLastWriteTime) #uselib "ADVAPI32.dll" #cfunc global RegEnumKeyExW "RegEnumKeyExW" intptr, int, var, var, var, var, var, var ; res = RegEnumKeyExW(hKey, dwIndex, lpName, lpcchName, lpReserved, lpClass, lpcchClass, lpftLastWriteTime) ; hKey : HKEY -> "intptr" ; dwIndex : DWORD -> "int" ; lpName : LPWSTR optional, out -> "var" ; lpcchName : DWORD* in/out -> "var" ; lpReserved : DWORD* optional -> "var" ; lpClass : LPWSTR optional, out -> "var" ; lpcchClass : DWORD* optional, in/out -> "var" ; lpftLastWriteTime : FILETIME* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WIN32_ERROR RegEnumKeyExW(HKEY hKey, DWORD dwIndex, LPWSTR lpName, DWORD* lpcchName, DWORD* lpReserved, LPWSTR lpClass, DWORD* lpcchClass, FILETIME* lpftLastWriteTime) #uselib "ADVAPI32.dll" #cfunc global RegEnumKeyExW "RegEnumKeyExW" intptr, int, intptr, intptr, intptr, intptr, intptr, intptr ; res = RegEnumKeyExW(hKey, dwIndex, varptr(lpName), varptr(lpcchName), varptr(lpReserved), varptr(lpClass), varptr(lpcchClass), varptr(lpftLastWriteTime)) ; hKey : HKEY -> "intptr" ; dwIndex : DWORD -> "int" ; lpName : LPWSTR optional, out -> "intptr" ; lpcchName : DWORD* in/out -> "intptr" ; lpReserved : DWORD* optional -> "intptr" ; lpClass : LPWSTR optional, out -> "intptr" ; lpcchClass : DWORD* optional, in/out -> "intptr" ; lpftLastWriteTime : FILETIME* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procRegEnumKeyExW = advapi32.NewProc("RegEnumKeyExW")
)
// hKey (HKEY), dwIndex (DWORD), lpName (LPWSTR optional, out), lpcchName (DWORD* in/out), lpReserved (DWORD* optional), lpClass (LPWSTR optional, out), lpcchClass (DWORD* optional, in/out), lpftLastWriteTime (FILETIME* optional, out)
r1, _, err := procRegEnumKeyExW.Call(
uintptr(hKey),
uintptr(dwIndex),
uintptr(lpName),
uintptr(lpcchName),
uintptr(lpReserved),
uintptr(lpClass),
uintptr(lpcchClass),
uintptr(lpftLastWriteTime),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction RegEnumKeyExW(
hKey: THandle; // HKEY
dwIndex: DWORD; // DWORD
lpName: PWideChar; // LPWSTR optional, out
lpcchName: Pointer; // DWORD* in/out
lpReserved: Pointer; // DWORD* optional
lpClass: PWideChar; // LPWSTR optional, out
lpcchClass: Pointer; // DWORD* optional, in/out
lpftLastWriteTime: Pointer // FILETIME* optional, out
): DWORD; stdcall;
external 'ADVAPI32.dll' name 'RegEnumKeyExW';result := DllCall("ADVAPI32\RegEnumKeyExW"
, "Ptr", hKey ; HKEY
, "UInt", dwIndex ; DWORD
, "Ptr", lpName ; LPWSTR optional, out
, "Ptr", lpcchName ; DWORD* in/out
, "Ptr", lpReserved ; DWORD* optional
, "Ptr", lpClass ; LPWSTR optional, out
, "Ptr", lpcchClass ; DWORD* optional, in/out
, "Ptr", lpftLastWriteTime ; FILETIME* optional, out
, "UInt") ; return: WIN32_ERROR●RegEnumKeyExW(hKey, dwIndex, lpName, lpcchName, lpReserved, lpClass, lpcchClass, lpftLastWriteTime) = DLL("ADVAPI32.dll", "dword RegEnumKeyExW(void*, dword, char*, void*, void*, char*, void*, void*)")
# 呼び出し: RegEnumKeyExW(hKey, dwIndex, lpName, lpcchName, lpReserved, lpClass, lpcchClass, lpftLastWriteTime)
# hKey : HKEY -> "void*"
# dwIndex : DWORD -> "dword"
# lpName : LPWSTR optional, out -> "char*"
# lpcchName : DWORD* in/out -> "void*"
# lpReserved : DWORD* optional -> "void*"
# lpClass : LPWSTR optional, out -> "char*"
# lpcchClass : DWORD* optional, in/out -> "void*"
# lpftLastWriteTime : FILETIME* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。