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

RegGetValueW

関数
型チェック付きで指定したレジストリ値を取得する。
DLLADVAPI32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

WIN32_ERROR RegGetValueW(
    HKEY hkey,
    LPCWSTR lpSubKey,   // optional
    LPCWSTR lpValue,   // optional
    REG_ROUTINE_FLAGS dwFlags,
    REG_VALUE_TYPE* pdwType,   // optional
    void* pvData,   // optional
    DWORD* pcbData   // optional
);

パラメーター

名前方向
hkeyHKEYin
lpSubKeyLPCWSTRinoptional
lpValueLPCWSTRinoptional
dwFlagsREG_ROUTINE_FLAGSin
pdwTypeREG_VALUE_TYPE*outoptional
pvDatavoid*outoptional
pcbDataDWORD*inoutoptional

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR RegGetValueW(
    HKEY hkey,
    LPCWSTR lpSubKey,   // optional
    LPCWSTR lpValue,   // optional
    REG_ROUTINE_FLAGS dwFlags,
    REG_VALUE_TYPE* pdwType,   // optional
    void* pvData,   // optional
    DWORD* pcbData   // optional
);
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint RegGetValueW(
    IntPtr hkey,   // HKEY
    [MarshalAs(UnmanagedType.LPWStr)] string lpSubKey,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string lpValue,   // LPCWSTR optional
    uint dwFlags,   // REG_ROUTINE_FLAGS
    IntPtr pdwType,   // REG_VALUE_TYPE* optional, out
    IntPtr pvData,   // void* optional, out
    IntPtr pcbData   // DWORD* optional, in/out
);
<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RegGetValueW(
    hkey As IntPtr,   ' HKEY
    <MarshalAs(UnmanagedType.LPWStr)> lpSubKey As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> lpValue As String,   ' LPCWSTR optional
    dwFlags As UInteger,   ' REG_ROUTINE_FLAGS
    pdwType As IntPtr,   ' REG_VALUE_TYPE* optional, out
    pvData As IntPtr,   ' void* optional, out
    pcbData As IntPtr   ' DWORD* optional, in/out
) As UInteger
End Function
' hkey : HKEY
' lpSubKey : LPCWSTR optional
' lpValue : LPCWSTR optional
' dwFlags : REG_ROUTINE_FLAGS
' pdwType : REG_VALUE_TYPE* optional, out
' pvData : void* optional, out
' pcbData : DWORD* optional, in/out
Declare PtrSafe Function RegGetValueW Lib "advapi32" ( _
    ByVal hkey As LongPtr, _
    ByVal lpSubKey As LongPtr, _
    ByVal lpValue As LongPtr, _
    ByVal dwFlags As Long, _
    ByVal pdwType As LongPtr, _
    ByVal pvData As LongPtr, _
    ByVal pcbData 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

RegGetValueW = ctypes.windll.advapi32.RegGetValueW
RegGetValueW.restype = wintypes.DWORD
RegGetValueW.argtypes = [
    wintypes.HANDLE,  # hkey : HKEY
    wintypes.LPCWSTR,  # lpSubKey : LPCWSTR optional
    wintypes.LPCWSTR,  # lpValue : LPCWSTR optional
    wintypes.DWORD,  # dwFlags : REG_ROUTINE_FLAGS
    ctypes.c_void_p,  # pdwType : REG_VALUE_TYPE* optional, out
    ctypes.POINTER(None),  # pvData : void* optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcbData : DWORD* optional, in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
RegGetValueW = Fiddle::Function.new(
  lib['RegGetValueW'],
  [
    Fiddle::TYPE_VOIDP,  # hkey : HKEY
    Fiddle::TYPE_VOIDP,  # lpSubKey : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # lpValue : LPCWSTR optional
    -Fiddle::TYPE_INT,  # dwFlags : REG_ROUTINE_FLAGS
    Fiddle::TYPE_VOIDP,  # pdwType : REG_VALUE_TYPE* optional, out
    Fiddle::TYPE_VOIDP,  # pvData : void* optional, out
    Fiddle::TYPE_VOIDP,  # pcbData : DWORD* optional, in/out
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "advapi32")]
extern "system" {
    fn RegGetValueW(
        hkey: *mut core::ffi::c_void,  // HKEY
        lpSubKey: *const u16,  // LPCWSTR optional
        lpValue: *const u16,  // LPCWSTR optional
        dwFlags: u32,  // REG_ROUTINE_FLAGS
        pdwType: *mut u32,  // REG_VALUE_TYPE* optional, out
        pvData: *mut (),  // void* optional, out
        pcbData: *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 RegGetValueW(IntPtr hkey, [MarshalAs(UnmanagedType.LPWStr)] string lpSubKey, [MarshalAs(UnmanagedType.LPWStr)] string lpValue, uint dwFlags, IntPtr pdwType, IntPtr pvData, IntPtr pcbData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_RegGetValueW' -Namespace Win32 -PassThru
# $api::RegGetValueW(hkey, lpSubKey, lpValue, dwFlags, pdwType, pvData, pcbData)
#uselib "ADVAPI32.dll"
#func global RegGetValueW "RegGetValueW" wptr, wptr, wptr, wptr, wptr, wptr, wptr
; RegGetValueW hkey, lpSubKey, lpValue, dwFlags, pdwType, pvData, varptr(pcbData)   ; 戻り値は stat
; hkey : HKEY -> "wptr"
; lpSubKey : LPCWSTR optional -> "wptr"
; lpValue : LPCWSTR optional -> "wptr"
; dwFlags : REG_ROUTINE_FLAGS -> "wptr"
; pdwType : REG_VALUE_TYPE* optional, out -> "wptr"
; pvData : void* optional, out -> "wptr"
; pcbData : DWORD* optional, in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global RegGetValueW "RegGetValueW" sptr, wstr, wstr, int, int, sptr, var
; res = RegGetValueW(hkey, lpSubKey, lpValue, dwFlags, pdwType, pvData, pcbData)
; hkey : HKEY -> "sptr"
; lpSubKey : LPCWSTR optional -> "wstr"
; lpValue : LPCWSTR optional -> "wstr"
; dwFlags : REG_ROUTINE_FLAGS -> "int"
; pdwType : REG_VALUE_TYPE* optional, out -> "int"
; pvData : void* optional, out -> "sptr"
; pcbData : DWORD* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WIN32_ERROR RegGetValueW(HKEY hkey, LPCWSTR lpSubKey, LPCWSTR lpValue, REG_ROUTINE_FLAGS dwFlags, REG_VALUE_TYPE* pdwType, void* pvData, DWORD* pcbData)
#uselib "ADVAPI32.dll"
#cfunc global RegGetValueW "RegGetValueW" intptr, wstr, wstr, int, int, intptr, var
; res = RegGetValueW(hkey, lpSubKey, lpValue, dwFlags, pdwType, pvData, pcbData)
; hkey : HKEY -> "intptr"
; lpSubKey : LPCWSTR optional -> "wstr"
; lpValue : LPCWSTR optional -> "wstr"
; dwFlags : REG_ROUTINE_FLAGS -> "int"
; pdwType : REG_VALUE_TYPE* optional, out -> "int"
; pvData : void* optional, out -> "intptr"
; pcbData : DWORD* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procRegGetValueW = advapi32.NewProc("RegGetValueW")
)

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