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

RegGetValueA

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

シグネチャ

// ADVAPI32.dll  (ANSI / -A)
#include <windows.h>

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

パラメーター

名前方向
hkeyHKEYin
lpSubKeyLPCSTRinoptional
lpValueLPCSTRinoptional
dwFlagsREG_ROUTINE_FLAGSin
pdwTypeREG_VALUE_TYPE*outoptional
pvDatavoid*outoptional
pcbDataDWORD*inoutoptional

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

// ADVAPI32.dll  (ANSI / -A)
#include <windows.h>

WIN32_ERROR RegGetValueA(
    HKEY hkey,
    LPCSTR lpSubKey,   // optional
    LPCSTR lpValue,   // optional
    REG_ROUTINE_FLAGS dwFlags,
    REG_VALUE_TYPE* pdwType,   // optional
    void* pvData,   // optional
    DWORD* pcbData   // optional
);
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint RegGetValueA(
    IntPtr hkey,   // HKEY
    [MarshalAs(UnmanagedType.LPStr)] string lpSubKey,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string lpValue,   // LPCSTR 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.Ansi, ExactSpelling:=True)>
Public Shared Function RegGetValueA(
    hkey As IntPtr,   ' HKEY
    <MarshalAs(UnmanagedType.LPStr)> lpSubKey As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> lpValue As String,   ' LPCSTR 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 : LPCSTR optional
' lpValue : LPCSTR optional
' dwFlags : REG_ROUTINE_FLAGS
' pdwType : REG_VALUE_TYPE* optional, out
' pvData : void* optional, out
' pcbData : DWORD* optional, in/out
Declare PtrSafe Function RegGetValueA Lib "advapi32" ( _
    ByVal hkey As LongPtr, _
    ByVal lpSubKey As String, _
    ByVal lpValue As String, _
    ByVal dwFlags As Long, _
    ByVal pdwType As LongPtr, _
    ByVal pvData As LongPtr, _
    ByVal pcbData As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RegGetValueA = ctypes.windll.advapi32.RegGetValueA
RegGetValueA.restype = wintypes.DWORD
RegGetValueA.argtypes = [
    wintypes.HANDLE,  # hkey : HKEY
    wintypes.LPCSTR,  # lpSubKey : LPCSTR optional
    wintypes.LPCSTR,  # lpValue : LPCSTR 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')
RegGetValueA = Fiddle::Function.new(
  lib['RegGetValueA'],
  [
    Fiddle::TYPE_VOIDP,  # hkey : HKEY
    Fiddle::TYPE_VOIDP,  # lpSubKey : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # lpValue : LPCSTR 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)
#[link(name = "advapi32")]
extern "system" {
    fn RegGetValueA(
        hkey: *mut core::ffi::c_void,  // HKEY
        lpSubKey: *const u8,  // LPCSTR optional
        lpValue: *const u8,  // LPCSTR 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.Ansi)]
public static extern uint RegGetValueA(IntPtr hkey, [MarshalAs(UnmanagedType.LPStr)] string lpSubKey, [MarshalAs(UnmanagedType.LPStr)] string lpValue, uint dwFlags, IntPtr pdwType, IntPtr pvData, IntPtr pcbData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_RegGetValueA' -Namespace Win32 -PassThru
# $api::RegGetValueA(hkey, lpSubKey, lpValue, dwFlags, pdwType, pvData, pcbData)
#uselib "ADVAPI32.dll"
#func global RegGetValueA "RegGetValueA" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; RegGetValueA hkey, lpSubKey, lpValue, dwFlags, pdwType, pvData, varptr(pcbData)   ; 戻り値は stat
; hkey : HKEY -> "sptr"
; lpSubKey : LPCSTR optional -> "sptr"
; lpValue : LPCSTR optional -> "sptr"
; dwFlags : REG_ROUTINE_FLAGS -> "sptr"
; pdwType : REG_VALUE_TYPE* optional, out -> "sptr"
; pvData : void* optional, out -> "sptr"
; pcbData : DWORD* optional, in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global RegGetValueA "RegGetValueA" sptr, str, str, int, int, sptr, var
; res = RegGetValueA(hkey, lpSubKey, lpValue, dwFlags, pdwType, pvData, pcbData)
; hkey : HKEY -> "sptr"
; lpSubKey : LPCSTR optional -> "str"
; lpValue : LPCSTR optional -> "str"
; 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 RegGetValueA(HKEY hkey, LPCSTR lpSubKey, LPCSTR lpValue, REG_ROUTINE_FLAGS dwFlags, REG_VALUE_TYPE* pdwType, void* pvData, DWORD* pcbData)
#uselib "ADVAPI32.dll"
#cfunc global RegGetValueA "RegGetValueA" intptr, str, str, int, int, intptr, var
; res = RegGetValueA(hkey, lpSubKey, lpValue, dwFlags, pdwType, pvData, pcbData)
; hkey : HKEY -> "intptr"
; lpSubKey : LPCSTR optional -> "str"
; lpValue : LPCSTR optional -> "str"
; 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")
	procRegGetValueA = advapi32.NewProc("RegGetValueA")
)

// hkey (HKEY), lpSubKey (LPCSTR optional), lpValue (LPCSTR optional), dwFlags (REG_ROUTINE_FLAGS), pdwType (REG_VALUE_TYPE* optional, out), pvData (void* optional, out), pcbData (DWORD* optional, in/out)
r1, _, err := procRegGetValueA.Call(
	uintptr(hkey),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpSubKey))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpValue))),
	uintptr(dwFlags),
	uintptr(pdwType),
	uintptr(pvData),
	uintptr(pcbData),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function RegGetValueA(
  hkey: THandle;   // HKEY
  lpSubKey: PAnsiChar;   // LPCSTR optional
  lpValue: PAnsiChar;   // LPCSTR 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 'RegGetValueA';
result := DllCall("ADVAPI32\RegGetValueA"
    , "Ptr", hkey   ; HKEY
    , "AStr", lpSubKey   ; LPCSTR optional
    , "AStr", lpValue   ; LPCSTR 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
●RegGetValueA(hkey, lpSubKey, lpValue, dwFlags, pdwType, pvData, pcbData) = DLL("ADVAPI32.dll", "dword RegGetValueA(void*, char*, char*, dword, void*, void*, void*)")
# 呼び出し: RegGetValueA(hkey, lpSubKey, lpValue, dwFlags, pdwType, pvData, pcbData)
# hkey : HKEY -> "void*"
# lpSubKey : LPCSTR optional -> "char*"
# lpValue : LPCSTR 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)。