Win32 API 日本語リファレンス
ホームSystem.Registry › RegQueryMultipleValuesW

RegQueryMultipleValuesW

関数
指定キーから複数のレジストリ値を一括取得する。
DLLADVAPI32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

WIN32_ERROR RegQueryMultipleValuesW(
    HKEY hKey,
    VALENTW* val_list,
    DWORD num_vals,
    LPWSTR lpValueBuf,   // optional
    DWORD* ldwTotsize   // optional
);

パラメーター

名前方向
hKeyHKEYin
val_listVALENTW*out
num_valsDWORDin
lpValueBufLPWSTRoutoptional
ldwTotsizeDWORD*inoutoptional

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR RegQueryMultipleValuesW(
    HKEY hKey,
    VALENTW* val_list,
    DWORD num_vals,
    LPWSTR lpValueBuf,   // optional
    DWORD* ldwTotsize   // optional
);
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint RegQueryMultipleValuesW(
    IntPtr hKey,   // HKEY
    IntPtr val_list,   // VALENTW* out
    uint num_vals,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpValueBuf,   // LPWSTR optional, out
    IntPtr ldwTotsize   // DWORD* optional, in/out
);
<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RegQueryMultipleValuesW(
    hKey As IntPtr,   ' HKEY
    val_list As IntPtr,   ' VALENTW* out
    num_vals As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> lpValueBuf As System.Text.StringBuilder,   ' LPWSTR optional, out
    ldwTotsize As IntPtr   ' DWORD* optional, in/out
) As UInteger
End Function
' hKey : HKEY
' val_list : VALENTW* out
' num_vals : DWORD
' lpValueBuf : LPWSTR optional, out
' ldwTotsize : DWORD* optional, in/out
Declare PtrSafe Function RegQueryMultipleValuesW Lib "advapi32" ( _
    ByVal hKey As LongPtr, _
    ByVal val_list As LongPtr, _
    ByVal num_vals As Long, _
    ByVal lpValueBuf As LongPtr, _
    ByVal ldwTotsize 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

RegQueryMultipleValuesW = ctypes.windll.advapi32.RegQueryMultipleValuesW
RegQueryMultipleValuesW.restype = wintypes.DWORD
RegQueryMultipleValuesW.argtypes = [
    wintypes.HANDLE,  # hKey : HKEY
    ctypes.c_void_p,  # val_list : VALENTW* out
    wintypes.DWORD,  # num_vals : DWORD
    wintypes.LPWSTR,  # lpValueBuf : LPWSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # ldwTotsize : DWORD* optional, in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procRegQueryMultipleValuesW = advapi32.NewProc("RegQueryMultipleValuesW")
)

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