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 | 開いているレジストリ キーへのハンドル。キーは KEY_ENUMERATE_SUB_KEYS アクセス権で開かれている必要があります。詳細については、 Registry Key Security and Access Rights を参照してください。 このハンドルは、 RegCreateKeyEx、RegCreateKeyTransacted、RegOpenKeyEx、または RegOpenKeyTransacted 関数によって返されます。次の 定義済みキー のいずれかを指定することもできます。 |
| dwIndex | DWORD | in | 取得するサブキーのインデックス。このパラメーターは、 RegEnumKeyEx 関数の最初の呼び出しではゼロにし、以降の呼び出しでは増やしていく必要があります。 サブキーには順序がないため、新しいサブキーは任意のインデックスを持ちます。これは、この関数が任意の順序でサブキーを返す可能性があることを意味します。 |
| lpName | LPWSTR | outoptional | 終端の null 文字を含む、サブキーの名前を受け取るバッファーへのポインター。この関数は、完全なキー階層ではなく、サブキーの名前のみをバッファーにコピーします。 関数が失敗した場合、このバッファーには情報はコピーされません。 詳細については、 Registry Element Size Limits を参照してください。 |
| lpcchName | DWORD* | inout | lpName パラメーターで指定されたバッファーのサイズを文字数で指定する変数へのポインター。このサイズには終端の null 文字を含める必要があります。関数が成功すると、lpcName が指す変数には、終端の null 文字を含まない、バッファーに格納された文字数が入ります。 必要なバッファー サイズを判断するには、 RegQueryInfoKey 関数を使用して、hKey パラメーターで識別されるキーの最大のサブキーのサイズを取得します。 |
| lpReserved | DWORD* | optional | このパラメーターは予約されており、NULL にする必要があります。 |
| lpClass | LPWSTR | outoptional | 列挙されたサブキーのユーザー定義クラスを受け取るバッファーへのポインター。このパラメーターには NULL を指定できます。 |
| lpcchClass | DWORD* | inoutoptional | lpClass パラメーターで指定されたバッファーのサイズを文字数で指定する変数へのポインター。サイズには終端の null 文字を含める必要があります。関数が成功すると、lpcClass には、終端の null 文字を含まない、バッファーに格納された文字数が入ります。このパラメーターは、lpClass が NULL の場合にのみ NULL にできます。 |
| lpftLastWriteTime | FILETIME* | outoptional | 列挙されたサブキーが最後に書き込まれた時刻を受け取る FILETIME 構造体へのポインター。このパラメーターには NULL を指定できます。 |
戻り値の型: WIN32_ERROR
公式ドキュメント
指定された開いているレジストリ キーのサブキーを列挙します。この関数は、呼び出されるたびに 1 つのサブキーに関する情報を取得します。(Unicode)
戻り値
関数が成功した場合、戻り値は ERROR_SUCCESS です。
関数が失敗した場合、戻り値は システム エラー コード です。利用可能なサブキーがこれ以上ない場合、関数は ERROR_NO_MORE_ITEMS を返します。
lpName バッファーがキーの名前を受け取るには小さすぎる場合、関数は ERROR_MORE_DATA を返します。
解説(Remarks)
サブキーを列挙するには、アプリケーションは最初に dwIndex パラメーターをゼロに設定して RegEnumKeyEx 関数を呼び出す必要があります。その後、アプリケーションは dwIndex パラメーターを増やしながら、サブキーがなくなる(つまり関数が ERROR_NO_MORE_ITEMS を返す)まで RegEnumKeyEx を呼び出します。
アプリケーションは、関数の最初の呼び出しで dwIndex を最後のサブキーのインデックスに設定し、インデックス 0 のサブキーが列挙されるまでインデックスを減らしていくこともできます。最後のサブキーのインデックスを取得するには、 RegQueryInfoKey 関数を使用します。
アプリケーションが RegEnumKeyEx 関数を使用している間は、列挙中のキーを変更する可能性のあるレジストリ関数を呼び出さないようにしてください。
特定のレジストリ キーにアクセスする操作はリダイレクトされることに注意してください。詳細については、Registry Virtualization および 32-bit and 64-bit Application Data in the Registry を参照してください。
例
例については、 Enumerating Registry Subkeys を参照してください。
winreg.h ヘッダーは、RegEnumKeyEx を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義しています。エンコード非依存のエイリアスの使用を、エンコード非依存でないコードと混在させると、不整合が生じ、コンパイル エラーまたは実行時エラーを引き起こす可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 版の利用を推奨。const std = @import("std");
extern "advapi32" fn RegEnumKeyExW(
hKey: ?*anyopaque, // HKEY
dwIndex: u32, // DWORD
lpName: [*c]u16, // LPWSTR optional, out
lpcchName: [*c]u32, // DWORD* in/out
lpReserved: [*c]u32, // DWORD* optional
lpClass: [*c]u16, // LPWSTR optional, out
lpcchClass: [*c]u32, // DWORD* optional, in/out
lpftLastWriteTime: [*c]FILETIME // FILETIME* optional, out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc RegEnumKeyExW(
hKey: pointer, # HKEY
dwIndex: uint32, # DWORD
lpName: ptr uint16, # LPWSTR optional, out
lpcchName: ptr uint32, # DWORD* in/out
lpReserved: ptr uint32, # DWORD* optional
lpClass: ptr uint16, # LPWSTR optional, out
lpcchClass: ptr uint32, # DWORD* optional, in/out
lpftLastWriteTime: ptr FILETIME # FILETIME* optional, out
): uint32 {.importc: "RegEnumKeyExW", stdcall, dynlib: "ADVAPI32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "advapi32");
extern(Windows)
uint RegEnumKeyExW(
void* hKey, // HKEY
uint dwIndex, // DWORD
wchar* lpName, // LPWSTR optional, out
uint* lpcchName, // DWORD* in/out
uint* lpReserved, // DWORD* optional
wchar* lpClass, // LPWSTR optional, out
uint* lpcchClass, // DWORD* optional, in/out
FILETIME* lpftLastWriteTime // FILETIME* optional, out
);ccall((:RegEnumKeyExW, "ADVAPI32.dll"), stdcall, UInt32,
(Ptr{Cvoid}, UInt32, Ptr{UInt16}, Ptr{UInt32}, Ptr{UInt32}, Ptr{UInt16}, Ptr{UInt32}, Ptr{FILETIME}),
hKey, dwIndex, lpName, lpcchName, lpReserved, lpClass, lpcchClass, lpftLastWriteTime)
# hKey : HKEY -> Ptr{Cvoid}
# dwIndex : DWORD -> UInt32
# lpName : LPWSTR optional, out -> Ptr{UInt16}
# lpcchName : DWORD* in/out -> Ptr{UInt32}
# lpReserved : DWORD* optional -> Ptr{UInt32}
# lpClass : LPWSTR optional, out -> Ptr{UInt16}
# lpcchClass : DWORD* optional, in/out -> Ptr{UInt32}
# lpftLastWriteTime : FILETIME* optional, out -> Ptr{FILETIME}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t RegEnumKeyExW(
void* hKey,
uint32_t dwIndex,
uint16_t* lpName,
uint32_t* lpcchName,
uint32_t* lpReserved,
uint16_t* lpClass,
uint32_t* lpcchClass,
void* lpftLastWriteTime);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.RegEnumKeyExW(hKey, dwIndex, lpName, lpcchName, lpReserved, lpClass, lpcchClass, lpftLastWriteTime)
-- 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
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const RegEnumKeyExW = lib.func('__stdcall', 'RegEnumKeyExW', 'uint32_t', ['void *', 'uint32_t', 'uint16_t *', 'uint32_t *', 'uint32_t *', 'uint16_t *', 'uint32_t *', 'void *']);
// RegEnumKeyExW(hKey, dwIndex, lpName, lpcchName, lpReserved, lpClass, lpcchClass, lpftLastWriteTime)
// hKey : HKEY -> 'void *'
// dwIndex : DWORD -> 'uint32_t'
// lpName : LPWSTR optional, out -> 'uint16_t *'
// lpcchName : DWORD* in/out -> 'uint32_t *'
// lpReserved : DWORD* optional -> 'uint32_t *'
// lpClass : LPWSTR optional, out -> 'uint16_t *'
// lpcchClass : DWORD* optional, in/out -> 'uint32_t *'
// lpftLastWriteTime : FILETIME* optional, out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
RegEnumKeyExW: { parameters: ["pointer", "u32", "buffer", "pointer", "pointer", "buffer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.RegEnumKeyExW(hKey, dwIndex, lpName, lpcchName, lpReserved, lpClass, lpcchClass, lpftLastWriteTime)
// hKey : HKEY -> "pointer"
// dwIndex : DWORD -> "u32"
// lpName : LPWSTR optional, out -> "buffer"
// lpcchName : DWORD* in/out -> "pointer"
// lpReserved : DWORD* optional -> "pointer"
// lpClass : LPWSTR optional, out -> "buffer"
// lpcchClass : DWORD* optional, in/out -> "pointer"
// lpftLastWriteTime : FILETIME* optional, out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t RegEnumKeyExW(
void* hKey,
uint32_t dwIndex,
uint16_t* lpName,
uint32_t* lpcchName,
uint32_t* lpReserved,
uint16_t* lpClass,
uint32_t* lpcchClass,
void* lpftLastWriteTime);
C, "ADVAPI32.dll");
// $ffi->RegEnumKeyExW(hKey, dwIndex, lpName, lpcchName, lpReserved, lpClass, lpcchClass, lpftLastWriteTime);
// 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
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Advapi32 extends StdCallLibrary {
Advapi32 INSTANCE = Native.load("advapi32", Advapi32.class, W32APIOptions.UNICODE_OPTIONS);
int RegEnumKeyExW(
Pointer hKey, // HKEY
int dwIndex, // DWORD
char[] lpName, // LPWSTR optional, out
IntByReference lpcchName, // DWORD* in/out
IntByReference lpReserved, // DWORD* optional
char[] lpClass, // LPWSTR optional, out
IntByReference lpcchClass, // DWORD* optional, in/out
Pointer lpftLastWriteTime // FILETIME* optional, out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("advapi32")]
lib LibADVAPI32
fun RegEnumKeyExW = RegEnumKeyExW(
hKey : Void*, # HKEY
dwIndex : UInt32, # DWORD
lpName : UInt16*, # LPWSTR optional, out
lpcchName : UInt32*, # DWORD* in/out
lpReserved : UInt32*, # DWORD* optional
lpClass : UInt16*, # LPWSTR optional, out
lpcchClass : UInt32*, # DWORD* optional, in/out
lpftLastWriteTime : FILETIME* # FILETIME* optional, out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef RegEnumKeyExWNative = Uint32 Function(Pointer<Void>, Uint32, Pointer<Utf16>, Pointer<Uint32>, Pointer<Uint32>, Pointer<Utf16>, Pointer<Uint32>, Pointer<Void>);
typedef RegEnumKeyExWDart = int Function(Pointer<Void>, int, Pointer<Utf16>, Pointer<Uint32>, Pointer<Uint32>, Pointer<Utf16>, Pointer<Uint32>, Pointer<Void>);
final RegEnumKeyExW = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<RegEnumKeyExWNative, RegEnumKeyExWDart>('RegEnumKeyExW');
// hKey : HKEY -> Pointer<Void>
// dwIndex : DWORD -> Uint32
// lpName : LPWSTR optional, out -> Pointer<Utf16>
// lpcchName : DWORD* in/out -> Pointer<Uint32>
// lpReserved : DWORD* optional -> Pointer<Uint32>
// lpClass : LPWSTR optional, out -> Pointer<Utf16>
// lpcchClass : DWORD* optional, in/out -> Pointer<Uint32>
// lpftLastWriteTime : FILETIME* optional, out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function 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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "RegEnumKeyExW"
c_RegEnumKeyExW :: Ptr () -> Word32 -> CWString -> Ptr Word32 -> Ptr Word32 -> CWString -> Ptr Word32 -> Ptr () -> IO Word32
-- hKey : HKEY -> Ptr ()
-- dwIndex : DWORD -> Word32
-- lpName : LPWSTR optional, out -> CWString
-- lpcchName : DWORD* in/out -> Ptr Word32
-- lpReserved : DWORD* optional -> Ptr Word32
-- lpClass : LPWSTR optional, out -> CWString
-- lpcchClass : DWORD* optional, in/out -> Ptr Word32
-- lpftLastWriteTime : FILETIME* optional, out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let regenumkeyexw =
foreign "RegEnumKeyExW"
((ptr void) @-> uint32_t @-> (ptr uint16_t) @-> (ptr uint32_t) @-> (ptr uint32_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> (ptr void) @-> returning uint32_t)
(* hKey : HKEY -> (ptr void) *)
(* dwIndex : DWORD -> uint32_t *)
(* lpName : LPWSTR optional, out -> (ptr uint16_t) *)
(* lpcchName : DWORD* in/out -> (ptr uint32_t) *)
(* lpReserved : DWORD* optional -> (ptr uint32_t) *)
(* lpClass : LPWSTR optional, out -> (ptr uint16_t) *)
(* lpcchClass : DWORD* optional, in/out -> (ptr uint32_t) *)
(* lpftLastWriteTime : FILETIME* optional, out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)
(cffi:defcfun ("RegEnumKeyExW" reg-enum-key-ex-w :convention :stdcall) :uint32
(h-key :pointer) ; HKEY
(dw-index :uint32) ; DWORD
(lp-name :pointer) ; LPWSTR optional, out
(lpcch-name :pointer) ; DWORD* in/out
(lp-reserved :pointer) ; DWORD* optional
(lp-class :pointer) ; LPWSTR optional, out
(lpcch-class :pointer) ; DWORD* optional, in/out
(lpft-last-write-time :pointer)) ; FILETIME* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $RegEnumKeyExW = Win32::API::More->new('ADVAPI32',
'DWORD RegEnumKeyExW(HANDLE hKey, DWORD dwIndex, LPWSTR lpName, LPVOID lpcchName, LPVOID lpReserved, LPWSTR lpClass, LPVOID lpcchClass, LPVOID lpftLastWriteTime)');
# my $ret = $RegEnumKeyExW->Call($hKey, $dwIndex, $lpName, $lpcchName, $lpReserved, $lpClass, $lpcchClass, $lpftLastWriteTime);
# hKey : HKEY -> HANDLE
# dwIndex : DWORD -> DWORD
# lpName : LPWSTR optional, out -> LPWSTR
# lpcchName : DWORD* in/out -> LPVOID
# lpReserved : DWORD* optional -> LPVOID
# lpClass : LPWSTR optional, out -> LPWSTR
# lpcchClass : DWORD* optional, in/out -> LPVOID
# lpftLastWriteTime : FILETIME* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f RegEnumKeyExA (ANSI版) — サブキー名やクラス、最終更新時刻を列挙して取得する。
- f RegEnumKeyW — 指定キーのサブキーをインデックス指定で列挙する。
- f RegCreateKeyExW — オプションやアクセス権を指定してレジストリキーを作成または開く。
- f RegDeleteKeyW — 指定したサブキーをレジストリから削除する。
- f RegOpenKeyExW — アクセス権を指定してレジストリキーを開く。
- f RegQueryInfoKeyW — 指定キーのサブキー数や値数などの情報を取得する。