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

GetRegistryValueWithFallbackW

関数
主キーを優先し失敗時はフォールバックキーから値を取得する。
DLLapi-ms-win-core-state-helpers-l1-1-0.dll呼出規約winapi

シグネチャ

// api-ms-win-core-state-helpers-l1-1-0.dll
#include <windows.h>

WIN32_ERROR GetRegistryValueWithFallbackW(
    HKEY hkeyPrimary,   // optional
    LPCWSTR pwszPrimarySubKey,   // optional
    HKEY hkeyFallback,   // optional
    LPCWSTR pwszFallbackSubKey,   // optional
    LPCWSTR pwszValue,
    DWORD dwFlags,
    DWORD* pdwType,   // optional
    void* pvData,   // optional
    DWORD cbDataIn,
    DWORD* pcbDataOut   // optional
);

パラメーター

名前方向
hkeyPrimaryHKEYinoptional
pwszPrimarySubKeyLPCWSTRinoptional
hkeyFallbackHKEYinoptional
pwszFallbackSubKeyLPCWSTRinoptional
pwszValueLPCWSTRin
dwFlagsDWORDin
pdwTypeDWORD*outoptional
pvDatavoid*outoptional
cbDataInDWORDin
pcbDataOutDWORD*outoptional

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

// api-ms-win-core-state-helpers-l1-1-0.dll
#include <windows.h>

WIN32_ERROR GetRegistryValueWithFallbackW(
    HKEY hkeyPrimary,   // optional
    LPCWSTR pwszPrimarySubKey,   // optional
    HKEY hkeyFallback,   // optional
    LPCWSTR pwszFallbackSubKey,   // optional
    LPCWSTR pwszValue,
    DWORD dwFlags,
    DWORD* pdwType,   // optional
    void* pvData,   // optional
    DWORD cbDataIn,
    DWORD* pcbDataOut   // optional
);
[DllImport("api-ms-win-core-state-helpers-l1-1-0.dll", ExactSpelling = true)]
static extern uint GetRegistryValueWithFallbackW(
    IntPtr hkeyPrimary,   // HKEY optional
    [MarshalAs(UnmanagedType.LPWStr)] string pwszPrimarySubKey,   // LPCWSTR optional
    IntPtr hkeyFallback,   // HKEY optional
    [MarshalAs(UnmanagedType.LPWStr)] string pwszFallbackSubKey,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string pwszValue,   // LPCWSTR
    uint dwFlags,   // DWORD
    IntPtr pdwType,   // DWORD* optional, out
    IntPtr pvData,   // void* optional, out
    uint cbDataIn,   // DWORD
    IntPtr pcbDataOut   // DWORD* optional, out
);
<DllImport("api-ms-win-core-state-helpers-l1-1-0.dll", ExactSpelling:=True)>
Public Shared Function GetRegistryValueWithFallbackW(
    hkeyPrimary As IntPtr,   ' HKEY optional
    <MarshalAs(UnmanagedType.LPWStr)> pwszPrimarySubKey As String,   ' LPCWSTR optional
    hkeyFallback As IntPtr,   ' HKEY optional
    <MarshalAs(UnmanagedType.LPWStr)> pwszFallbackSubKey As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> pwszValue As String,   ' LPCWSTR
    dwFlags As UInteger,   ' DWORD
    pdwType As IntPtr,   ' DWORD* optional, out
    pvData As IntPtr,   ' void* optional, out
    cbDataIn As UInteger,   ' DWORD
    pcbDataOut As IntPtr   ' DWORD* optional, out
) As UInteger
End Function
' hkeyPrimary : HKEY optional
' pwszPrimarySubKey : LPCWSTR optional
' hkeyFallback : HKEY optional
' pwszFallbackSubKey : LPCWSTR optional
' pwszValue : LPCWSTR
' dwFlags : DWORD
' pdwType : DWORD* optional, out
' pvData : void* optional, out
' cbDataIn : DWORD
' pcbDataOut : DWORD* optional, out
Declare PtrSafe Function GetRegistryValueWithFallbackW Lib "api-ms-win-core-state-helpers-l1-1-0" ( _
    ByVal hkeyPrimary As LongPtr, _
    ByVal pwszPrimarySubKey As LongPtr, _
    ByVal hkeyFallback As LongPtr, _
    ByVal pwszFallbackSubKey As LongPtr, _
    ByVal pwszValue As LongPtr, _
    ByVal dwFlags As Long, _
    ByVal pdwType As LongPtr, _
    ByVal pvData As LongPtr, _
    ByVal cbDataIn As Long, _
    ByVal pcbDataOut As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetRegistryValueWithFallbackW = ctypes.windll.LoadLibrary("api-ms-win-core-state-helpers-l1-1-0.dll").GetRegistryValueWithFallbackW
GetRegistryValueWithFallbackW.restype = wintypes.DWORD
GetRegistryValueWithFallbackW.argtypes = [
    wintypes.HANDLE,  # hkeyPrimary : HKEY optional
    wintypes.LPCWSTR,  # pwszPrimarySubKey : LPCWSTR optional
    wintypes.HANDLE,  # hkeyFallback : HKEY optional
    wintypes.LPCWSTR,  # pwszFallbackSubKey : LPCWSTR optional
    wintypes.LPCWSTR,  # pwszValue : LPCWSTR
    wintypes.DWORD,  # dwFlags : DWORD
    ctypes.POINTER(wintypes.DWORD),  # pdwType : DWORD* optional, out
    ctypes.POINTER(None),  # pvData : void* optional, out
    wintypes.DWORD,  # cbDataIn : DWORD
    ctypes.POINTER(wintypes.DWORD),  # pcbDataOut : DWORD* optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('api-ms-win-core-state-helpers-l1-1-0.dll')
GetRegistryValueWithFallbackW = Fiddle::Function.new(
  lib['GetRegistryValueWithFallbackW'],
  [
    Fiddle::TYPE_VOIDP,  # hkeyPrimary : HKEY optional
    Fiddle::TYPE_VOIDP,  # pwszPrimarySubKey : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # hkeyFallback : HKEY optional
    Fiddle::TYPE_VOIDP,  # pwszFallbackSubKey : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # pwszValue : LPCWSTR
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
    Fiddle::TYPE_VOIDP,  # pdwType : DWORD* optional, out
    Fiddle::TYPE_VOIDP,  # pvData : void* optional, out
    -Fiddle::TYPE_INT,  # cbDataIn : DWORD
    Fiddle::TYPE_VOIDP,  # pcbDataOut : DWORD* optional, out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "api-ms-win-core-state-helpers-l1-1-0")]
extern "system" {
    fn GetRegistryValueWithFallbackW(
        hkeyPrimary: *mut core::ffi::c_void,  // HKEY optional
        pwszPrimarySubKey: *const u16,  // LPCWSTR optional
        hkeyFallback: *mut core::ffi::c_void,  // HKEY optional
        pwszFallbackSubKey: *const u16,  // LPCWSTR optional
        pwszValue: *const u16,  // LPCWSTR
        dwFlags: u32,  // DWORD
        pdwType: *mut u32,  // DWORD* optional, out
        pvData: *mut (),  // void* optional, out
        cbDataIn: u32,  // DWORD
        pcbDataOut: *mut u32  // DWORD* optional, out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("api-ms-win-core-state-helpers-l1-1-0.dll")]
public static extern uint GetRegistryValueWithFallbackW(IntPtr hkeyPrimary, [MarshalAs(UnmanagedType.LPWStr)] string pwszPrimarySubKey, IntPtr hkeyFallback, [MarshalAs(UnmanagedType.LPWStr)] string pwszFallbackSubKey, [MarshalAs(UnmanagedType.LPWStr)] string pwszValue, uint dwFlags, IntPtr pdwType, IntPtr pvData, uint cbDataIn, IntPtr pcbDataOut);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-state-helpers-l1-1-0_GetRegistryValueWithFallbackW' -Namespace Win32 -PassThru
# $api::GetRegistryValueWithFallbackW(hkeyPrimary, pwszPrimarySubKey, hkeyFallback, pwszFallbackSubKey, pwszValue, dwFlags, pdwType, pvData, cbDataIn, pcbDataOut)
#uselib "api-ms-win-core-state-helpers-l1-1-0.dll"
#func global GetRegistryValueWithFallbackW "GetRegistryValueWithFallbackW" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; GetRegistryValueWithFallbackW hkeyPrimary, pwszPrimarySubKey, hkeyFallback, pwszFallbackSubKey, pwszValue, dwFlags, varptr(pdwType), pvData, cbDataIn, varptr(pcbDataOut)   ; 戻り値は stat
; hkeyPrimary : HKEY optional -> "sptr"
; pwszPrimarySubKey : LPCWSTR optional -> "sptr"
; hkeyFallback : HKEY optional -> "sptr"
; pwszFallbackSubKey : LPCWSTR optional -> "sptr"
; pwszValue : LPCWSTR -> "sptr"
; dwFlags : DWORD -> "sptr"
; pdwType : DWORD* optional, out -> "sptr"
; pvData : void* optional, out -> "sptr"
; cbDataIn : DWORD -> "sptr"
; pcbDataOut : DWORD* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "api-ms-win-core-state-helpers-l1-1-0.dll"
#cfunc global GetRegistryValueWithFallbackW "GetRegistryValueWithFallbackW" sptr, wstr, sptr, wstr, wstr, int, var, sptr, int, var
; res = GetRegistryValueWithFallbackW(hkeyPrimary, pwszPrimarySubKey, hkeyFallback, pwszFallbackSubKey, pwszValue, dwFlags, pdwType, pvData, cbDataIn, pcbDataOut)
; hkeyPrimary : HKEY optional -> "sptr"
; pwszPrimarySubKey : LPCWSTR optional -> "wstr"
; hkeyFallback : HKEY optional -> "sptr"
; pwszFallbackSubKey : LPCWSTR optional -> "wstr"
; pwszValue : LPCWSTR -> "wstr"
; dwFlags : DWORD -> "int"
; pdwType : DWORD* optional, out -> "var"
; pvData : void* optional, out -> "sptr"
; cbDataIn : DWORD -> "int"
; pcbDataOut : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WIN32_ERROR GetRegistryValueWithFallbackW(HKEY hkeyPrimary, LPCWSTR pwszPrimarySubKey, HKEY hkeyFallback, LPCWSTR pwszFallbackSubKey, LPCWSTR pwszValue, DWORD dwFlags, DWORD* pdwType, void* pvData, DWORD cbDataIn, DWORD* pcbDataOut)
#uselib "api-ms-win-core-state-helpers-l1-1-0.dll"
#cfunc global GetRegistryValueWithFallbackW "GetRegistryValueWithFallbackW" intptr, wstr, intptr, wstr, wstr, int, var, intptr, int, var
; res = GetRegistryValueWithFallbackW(hkeyPrimary, pwszPrimarySubKey, hkeyFallback, pwszFallbackSubKey, pwszValue, dwFlags, pdwType, pvData, cbDataIn, pcbDataOut)
; hkeyPrimary : HKEY optional -> "intptr"
; pwszPrimarySubKey : LPCWSTR optional -> "wstr"
; hkeyFallback : HKEY optional -> "intptr"
; pwszFallbackSubKey : LPCWSTR optional -> "wstr"
; pwszValue : LPCWSTR -> "wstr"
; dwFlags : DWORD -> "int"
; pdwType : DWORD* optional, out -> "var"
; pvData : void* optional, out -> "intptr"
; cbDataIn : DWORD -> "int"
; pcbDataOut : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	api_ms_win_core_state_helpers_l1_1_0 = windows.NewLazySystemDLL("api-ms-win-core-state-helpers-l1-1-0.dll")
	procGetRegistryValueWithFallbackW = api_ms_win_core_state_helpers_l1_1_0.NewProc("GetRegistryValueWithFallbackW")
)

// hkeyPrimary (HKEY optional), pwszPrimarySubKey (LPCWSTR optional), hkeyFallback (HKEY optional), pwszFallbackSubKey (LPCWSTR optional), pwszValue (LPCWSTR), dwFlags (DWORD), pdwType (DWORD* optional, out), pvData (void* optional, out), cbDataIn (DWORD), pcbDataOut (DWORD* optional, out)
r1, _, err := procGetRegistryValueWithFallbackW.Call(
	uintptr(hkeyPrimary),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwszPrimarySubKey))),
	uintptr(hkeyFallback),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwszFallbackSubKey))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwszValue))),
	uintptr(dwFlags),
	uintptr(pdwType),
	uintptr(pvData),
	uintptr(cbDataIn),
	uintptr(pcbDataOut),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function GetRegistryValueWithFallbackW(
  hkeyPrimary: THandle;   // HKEY optional
  pwszPrimarySubKey: PWideChar;   // LPCWSTR optional
  hkeyFallback: THandle;   // HKEY optional
  pwszFallbackSubKey: PWideChar;   // LPCWSTR optional
  pwszValue: PWideChar;   // LPCWSTR
  dwFlags: DWORD;   // DWORD
  pdwType: Pointer;   // DWORD* optional, out
  pvData: Pointer;   // void* optional, out
  cbDataIn: DWORD;   // DWORD
  pcbDataOut: Pointer   // DWORD* optional, out
): DWORD; stdcall;
  external 'api-ms-win-core-state-helpers-l1-1-0.dll' name 'GetRegistryValueWithFallbackW';
result := DllCall("api-ms-win-core-state-helpers-l1-1-0\GetRegistryValueWithFallbackW"
    , "Ptr", hkeyPrimary   ; HKEY optional
    , "WStr", pwszPrimarySubKey   ; LPCWSTR optional
    , "Ptr", hkeyFallback   ; HKEY optional
    , "WStr", pwszFallbackSubKey   ; LPCWSTR optional
    , "WStr", pwszValue   ; LPCWSTR
    , "UInt", dwFlags   ; DWORD
    , "Ptr", pdwType   ; DWORD* optional, out
    , "Ptr", pvData   ; void* optional, out
    , "UInt", cbDataIn   ; DWORD
    , "Ptr", pcbDataOut   ; DWORD* optional, out
    , "UInt")   ; return: WIN32_ERROR
●GetRegistryValueWithFallbackW(hkeyPrimary, pwszPrimarySubKey, hkeyFallback, pwszFallbackSubKey, pwszValue, dwFlags, pdwType, pvData, cbDataIn, pcbDataOut) = DLL("api-ms-win-core-state-helpers-l1-1-0.dll", "dword GetRegistryValueWithFallbackW(void*, char*, void*, char*, char*, dword, void*, void*, dword, void*)")
# 呼び出し: GetRegistryValueWithFallbackW(hkeyPrimary, pwszPrimarySubKey, hkeyFallback, pwszFallbackSubKey, pwszValue, dwFlags, pdwType, pvData, cbDataIn, pcbDataOut)
# hkeyPrimary : HKEY optional -> "void*"
# pwszPrimarySubKey : LPCWSTR optional -> "char*"
# hkeyFallback : HKEY optional -> "void*"
# pwszFallbackSubKey : LPCWSTR optional -> "char*"
# pwszValue : LPCWSTR -> "char*"
# dwFlags : DWORD -> "dword"
# pdwType : DWORD* optional, out -> "void*"
# pvData : void* optional, out -> "void*"
# cbDataIn : DWORD -> "dword"
# pcbDataOut : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。