ホーム › System.Registry › GetRegistryValueWithFallbackW
GetRegistryValueWithFallbackW
関数主キーを優先し失敗時はフォールバックキーから値を取得する。
シグネチャ
// 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
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hkeyPrimary | HKEY | inoptional | 最初に検索する優先側の開いているレジストリキーのハンドル。 |
| pwszPrimarySubKey | LPCWSTR | inoptional | 優先側キー下のサブキーパスを指すワイド文字列。 |
| hkeyFallback | HKEY | inoptional | 優先側で見つからない場合に検索する代替キーのハンドル。 |
| pwszFallbackSubKey | LPCWSTR | inoptional | 代替側キー下のサブキーパスを指すワイド文字列。 |
| pwszValue | LPCWSTR | in | 取得する値の名前を指すワイド文字列。 |
| dwFlags | DWORD | in | 取得を制御するフラグ(許可するデータ型RRF_RT_*等)。 |
| pdwType | DWORD* | outoptional | 取得した値のデータ型を受け取るポインタ(出力)。不要ならNULL可。 |
| pvData | void* | outoptional | 値のデータを受け取るバッファ(出力)。 |
| cbDataIn | DWORD | in | pvDataバッファのサイズ(バイト数、入力)。 |
| pcbDataOut | DWORD* | 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 方式にも切替可。#uselib "api-ms-win-core-state-helpers-l1-1-0.dll" #cfunc global GetRegistryValueWithFallbackW "GetRegistryValueWithFallbackW" sptr, wstr, sptr, wstr, wstr, int, sptr, sptr, int, sptr ; res = GetRegistryValueWithFallbackW(hkeyPrimary, pwszPrimarySubKey, hkeyFallback, pwszFallbackSubKey, pwszValue, dwFlags, varptr(pdwType), pvData, cbDataIn, varptr(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 -> "sptr" ; pvData : void* optional, out -> "sptr" ; cbDataIn : DWORD -> "int" ; pcbDataOut : DWORD* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; 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, intptr, intptr, int, intptr ; res = GetRegistryValueWithFallbackW(hkeyPrimary, pwszPrimarySubKey, hkeyFallback, pwszFallbackSubKey, pwszValue, dwFlags, varptr(pdwType), pvData, cbDataIn, varptr(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 -> "intptr" ; pvData : void* optional, out -> "intptr" ; cbDataIn : DWORD -> "int" ; pcbDataOut : DWORD* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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_ERRORfunction 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)。const std = @import("std");
extern "api-ms-win-core-state-helpers-l1-1-0" fn GetRegistryValueWithFallbackW(
hkeyPrimary: ?*anyopaque, // HKEY optional
pwszPrimarySubKey: [*c]const u16, // LPCWSTR optional
hkeyFallback: ?*anyopaque, // HKEY optional
pwszFallbackSubKey: [*c]const u16, // LPCWSTR optional
pwszValue: [*c]const u16, // LPCWSTR
dwFlags: u32, // DWORD
pdwType: [*c]u32, // DWORD* optional, out
pvData: ?*anyopaque, // void* optional, out
cbDataIn: u32, // DWORD
pcbDataOut: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) u32;proc GetRegistryValueWithFallbackW(
hkeyPrimary: pointer, # HKEY optional
pwszPrimarySubKey: WideCString, # LPCWSTR optional
hkeyFallback: pointer, # HKEY optional
pwszFallbackSubKey: WideCString, # LPCWSTR optional
pwszValue: WideCString, # LPCWSTR
dwFlags: uint32, # DWORD
pdwType: ptr uint32, # DWORD* optional, out
pvData: pointer, # void* optional, out
cbDataIn: uint32, # DWORD
pcbDataOut: ptr uint32 # DWORD* optional, out
): uint32 {.importc: "GetRegistryValueWithFallbackW", stdcall, dynlib: "api-ms-win-core-state-helpers-l1-1-0.dll".}pragma(lib, "api-ms-win-core-state-helpers-l1-1-0");
extern(Windows)
uint GetRegistryValueWithFallbackW(
void* hkeyPrimary, // HKEY optional
const(wchar)* pwszPrimarySubKey, // LPCWSTR optional
void* hkeyFallback, // HKEY optional
const(wchar)* pwszFallbackSubKey, // LPCWSTR optional
const(wchar)* pwszValue, // LPCWSTR
uint dwFlags, // DWORD
uint* pdwType, // DWORD* optional, out
void* pvData, // void* optional, out
uint cbDataIn, // DWORD
uint* pcbDataOut // DWORD* optional, out
);ccall((:GetRegistryValueWithFallbackW, "api-ms-win-core-state-helpers-l1-1-0.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Cwstring, Ptr{Cvoid}, Cwstring, Cwstring, UInt32, Ptr{UInt32}, Ptr{Cvoid}, UInt32, Ptr{UInt32}),
hkeyPrimary, pwszPrimarySubKey, hkeyFallback, pwszFallbackSubKey, pwszValue, dwFlags, pdwType, pvData, cbDataIn, pcbDataOut)
# hkeyPrimary : HKEY optional -> Ptr{Cvoid}
# pwszPrimarySubKey : LPCWSTR optional -> Cwstring
# hkeyFallback : HKEY optional -> Ptr{Cvoid}
# pwszFallbackSubKey : LPCWSTR optional -> Cwstring
# pwszValue : LPCWSTR -> Cwstring
# dwFlags : DWORD -> UInt32
# pdwType : DWORD* optional, out -> Ptr{UInt32}
# pvData : void* optional, out -> Ptr{Cvoid}
# cbDataIn : DWORD -> UInt32
# pcbDataOut : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t GetRegistryValueWithFallbackW(
void* hkeyPrimary,
const uint16_t* pwszPrimarySubKey,
void* hkeyFallback,
const uint16_t* pwszFallbackSubKey,
const uint16_t* pwszValue,
uint32_t dwFlags,
uint32_t* pdwType,
void* pvData,
uint32_t cbDataIn,
uint32_t* pcbDataOut);
]]
local api-ms-win-core-state-helpers-l1-1-0 = ffi.load("api-ms-win-core-state-helpers-l1-1-0")
-- api-ms-win-core-state-helpers-l1-1-0.GetRegistryValueWithFallbackW(hkeyPrimary, pwszPrimarySubKey, hkeyFallback, pwszFallbackSubKey, pwszValue, dwFlags, pdwType, pvData, cbDataIn, pcbDataOut)
-- 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
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('api-ms-win-core-state-helpers-l1-1-0.dll');
const GetRegistryValueWithFallbackW = lib.func('__stdcall', 'GetRegistryValueWithFallbackW', 'uint32_t', ['void *', 'str16', 'void *', 'str16', 'str16', 'uint32_t', 'uint32_t *', 'void *', 'uint32_t', 'uint32_t *']);
// GetRegistryValueWithFallbackW(hkeyPrimary, pwszPrimarySubKey, hkeyFallback, pwszFallbackSubKey, pwszValue, dwFlags, pdwType, pvData, cbDataIn, pcbDataOut)
// hkeyPrimary : HKEY optional -> 'void *'
// pwszPrimarySubKey : LPCWSTR optional -> 'str16'
// hkeyFallback : HKEY optional -> 'void *'
// pwszFallbackSubKey : LPCWSTR optional -> 'str16'
// pwszValue : LPCWSTR -> 'str16'
// dwFlags : DWORD -> 'uint32_t'
// pdwType : DWORD* optional, out -> 'uint32_t *'
// pvData : void* optional, out -> 'void *'
// cbDataIn : DWORD -> 'uint32_t'
// pcbDataOut : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("api-ms-win-core-state-helpers-l1-1-0.dll", {
GetRegistryValueWithFallbackW: { parameters: ["pointer", "buffer", "pointer", "buffer", "buffer", "u32", "pointer", "pointer", "u32", "pointer"], result: "u32" },
});
// lib.symbols.GetRegistryValueWithFallbackW(hkeyPrimary, pwszPrimarySubKey, hkeyFallback, pwszFallbackSubKey, pwszValue, dwFlags, pdwType, pvData, cbDataIn, pcbDataOut)
// hkeyPrimary : HKEY optional -> "pointer"
// pwszPrimarySubKey : LPCWSTR optional -> "buffer"
// hkeyFallback : HKEY optional -> "pointer"
// pwszFallbackSubKey : LPCWSTR optional -> "buffer"
// pwszValue : LPCWSTR -> "buffer"
// dwFlags : DWORD -> "u32"
// pdwType : DWORD* optional, out -> "pointer"
// pvData : void* optional, out -> "pointer"
// cbDataIn : DWORD -> "u32"
// pcbDataOut : DWORD* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t GetRegistryValueWithFallbackW(
void* hkeyPrimary,
const uint16_t* pwszPrimarySubKey,
void* hkeyFallback,
const uint16_t* pwszFallbackSubKey,
const uint16_t* pwszValue,
uint32_t dwFlags,
uint32_t* pdwType,
void* pvData,
uint32_t cbDataIn,
uint32_t* pcbDataOut);
C, "api-ms-win-core-state-helpers-l1-1-0.dll");
// $ffi->GetRegistryValueWithFallbackW(hkeyPrimary, pwszPrimarySubKey, hkeyFallback, pwszFallbackSubKey, pwszValue, dwFlags, pdwType, pvData, cbDataIn, pcbDataOut);
// 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
// 構造体/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 Api-ms-win-core-state-helpers-l1-1-0 extends StdCallLibrary {
Api-ms-win-core-state-helpers-l1-1-0 INSTANCE = Native.load("api-ms-win-core-state-helpers-l1-1-0", Api-ms-win-core-state-helpers-l1-1-0.class);
int GetRegistryValueWithFallbackW(
Pointer hkeyPrimary, // HKEY optional
WString pwszPrimarySubKey, // LPCWSTR optional
Pointer hkeyFallback, // HKEY optional
WString pwszFallbackSubKey, // LPCWSTR optional
WString pwszValue, // LPCWSTR
int dwFlags, // DWORD
IntByReference pdwType, // DWORD* optional, out
Pointer pvData, // void* optional, out
int cbDataIn, // DWORD
IntByReference pcbDataOut // DWORD* optional, out
);
}@[Link("api-ms-win-core-state-helpers-l1-1-0")]
lib Libapi-ms-win-core-state-helpers-l1-1-0
fun GetRegistryValueWithFallbackW = GetRegistryValueWithFallbackW(
hkeyPrimary : Void*, # HKEY optional
pwszPrimarySubKey : UInt16*, # LPCWSTR optional
hkeyFallback : Void*, # HKEY optional
pwszFallbackSubKey : UInt16*, # LPCWSTR optional
pwszValue : UInt16*, # LPCWSTR
dwFlags : UInt32, # DWORD
pdwType : UInt32*, # DWORD* optional, out
pvData : Void*, # void* optional, out
cbDataIn : UInt32, # DWORD
pcbDataOut : UInt32* # DWORD* 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 GetRegistryValueWithFallbackWNative = Uint32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Uint32, Pointer<Uint32>, Pointer<Void>, Uint32, Pointer<Uint32>);
typedef GetRegistryValueWithFallbackWDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, int, Pointer<Uint32>, Pointer<Void>, int, Pointer<Uint32>);
final GetRegistryValueWithFallbackW = DynamicLibrary.open('api-ms-win-core-state-helpers-l1-1-0.dll')
.lookupFunction<GetRegistryValueWithFallbackWNative, GetRegistryValueWithFallbackWDart>('GetRegistryValueWithFallbackW');
// hkeyPrimary : HKEY optional -> Pointer<Void>
// pwszPrimarySubKey : LPCWSTR optional -> Pointer<Utf16>
// hkeyFallback : HKEY optional -> Pointer<Void>
// pwszFallbackSubKey : LPCWSTR optional -> Pointer<Utf16>
// pwszValue : LPCWSTR -> Pointer<Utf16>
// dwFlags : DWORD -> Uint32
// pdwType : DWORD* optional, out -> Pointer<Uint32>
// pvData : void* optional, out -> Pointer<Void>
// cbDataIn : DWORD -> Uint32
// pcbDataOut : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetRegistryValueWithFallbackW"
c_GetRegistryValueWithFallbackW :: Ptr () -> CWString -> Ptr () -> CWString -> CWString -> Word32 -> Ptr Word32 -> Ptr () -> Word32 -> Ptr Word32 -> IO Word32
-- hkeyPrimary : HKEY optional -> Ptr ()
-- pwszPrimarySubKey : LPCWSTR optional -> CWString
-- hkeyFallback : HKEY optional -> Ptr ()
-- pwszFallbackSubKey : LPCWSTR optional -> CWString
-- pwszValue : LPCWSTR -> CWString
-- dwFlags : DWORD -> Word32
-- pdwType : DWORD* optional, out -> Ptr Word32
-- pvData : void* optional, out -> Ptr ()
-- cbDataIn : DWORD -> Word32
-- pcbDataOut : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getregistryvaluewithfallbackw =
foreign "GetRegistryValueWithFallbackW"
((ptr void) @-> (ptr uint16_t) @-> (ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint32_t) @-> (ptr void) @-> uint32_t @-> (ptr uint32_t) @-> returning uint32_t)
(* hkeyPrimary : HKEY optional -> (ptr void) *)
(* pwszPrimarySubKey : LPCWSTR optional -> (ptr uint16_t) *)
(* hkeyFallback : HKEY optional -> (ptr void) *)
(* pwszFallbackSubKey : LPCWSTR optional -> (ptr uint16_t) *)
(* pwszValue : LPCWSTR -> (ptr uint16_t) *)
(* dwFlags : DWORD -> uint32_t *)
(* pdwType : DWORD* optional, out -> (ptr uint32_t) *)
(* pvData : void* optional, out -> (ptr void) *)
(* cbDataIn : DWORD -> uint32_t *)
(* pcbDataOut : DWORD* optional, out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library api-ms-win-core-state-helpers-l1-1-0 (t "api-ms-win-core-state-helpers-l1-1-0.dll"))
(cffi:use-foreign-library api-ms-win-core-state-helpers-l1-1-0)
(cffi:defcfun ("GetRegistryValueWithFallbackW" get-registry-value-with-fallback-w :convention :stdcall) :uint32
(hkey-primary :pointer) ; HKEY optional
(pwsz-primary-sub-key (:string :encoding :utf-16le)) ; LPCWSTR optional
(hkey-fallback :pointer) ; HKEY optional
(pwsz-fallback-sub-key (:string :encoding :utf-16le)) ; LPCWSTR optional
(pwsz-value (:string :encoding :utf-16le)) ; LPCWSTR
(dw-flags :uint32) ; DWORD
(pdw-type :pointer) ; DWORD* optional, out
(pv-data :pointer) ; void* optional, out
(cb-data-in :uint32) ; DWORD
(pcb-data-out :pointer)) ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetRegistryValueWithFallbackW = Win32::API::More->new('api-ms-win-core-state-helpers-l1-1-0',
'DWORD GetRegistryValueWithFallbackW(HANDLE hkeyPrimary, LPCWSTR pwszPrimarySubKey, HANDLE hkeyFallback, LPCWSTR pwszFallbackSubKey, LPCWSTR pwszValue, DWORD dwFlags, LPVOID pdwType, LPVOID pvData, DWORD cbDataIn, LPVOID pcbDataOut)');
# my $ret = $GetRegistryValueWithFallbackW->Call($hkeyPrimary, $pwszPrimarySubKey, $hkeyFallback, $pwszFallbackSubKey, $pwszValue, $dwFlags, $pdwType, $pvData, $cbDataIn, $pcbDataOut);
# hkeyPrimary : HKEY optional -> HANDLE
# pwszPrimarySubKey : LPCWSTR optional -> LPCWSTR
# hkeyFallback : HKEY optional -> HANDLE
# pwszFallbackSubKey : LPCWSTR optional -> LPCWSTR
# pwszValue : LPCWSTR -> LPCWSTR
# dwFlags : DWORD -> DWORD
# pdwType : DWORD* optional, out -> LPVOID
# pvData : void* optional, out -> LPVOID
# cbDataIn : DWORD -> DWORD
# pcbDataOut : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型