SHRegGetValueW
関数フラグ指定付きでレジストリの値を取得し型変換も行う。
シグネチャ
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR SHRegGetValueW(
HKEY hkey,
LPCWSTR pszSubKey, // optional
LPCWSTR pszValue, // optional
INT srrfFlags,
DWORD* pdwType, // optional
void* pvData, // optional
DWORD* pcbData // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hkey | HKEY | in |
| pszSubKey | LPCWSTR | inoptional |
| pszValue | LPCWSTR | inoptional |
| srrfFlags | INT | in |
| pdwType | DWORD* | outoptional |
| pvData | void* | outoptional |
| pcbData | DWORD* | inoutoptional |
戻り値の型: WIN32_ERROR
各言語での呼び出し定義
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR SHRegGetValueW(
HKEY hkey,
LPCWSTR pszSubKey, // optional
LPCWSTR pszValue, // optional
INT srrfFlags,
DWORD* pdwType, // optional
void* pvData, // optional
DWORD* pcbData // optional
);[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint SHRegGetValueW(
IntPtr hkey, // HKEY
[MarshalAs(UnmanagedType.LPWStr)] string pszSubKey, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string pszValue, // LPCWSTR optional
int srrfFlags, // INT
IntPtr pdwType, // DWORD* optional, out
IntPtr pvData, // void* optional, out
IntPtr pcbData // DWORD* optional, in/out
);<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SHRegGetValueW(
hkey As IntPtr, ' HKEY
<MarshalAs(UnmanagedType.LPWStr)> pszSubKey As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> pszValue As String, ' LPCWSTR optional
srrfFlags As Integer, ' INT
pdwType As IntPtr, ' DWORD* optional, out
pvData As IntPtr, ' void* optional, out
pcbData As IntPtr ' DWORD* optional, in/out
) As UInteger
End Function' hkey : HKEY
' pszSubKey : LPCWSTR optional
' pszValue : LPCWSTR optional
' srrfFlags : INT
' pdwType : DWORD* optional, out
' pvData : void* optional, out
' pcbData : DWORD* optional, in/out
Declare PtrSafe Function SHRegGetValueW Lib "shlwapi" ( _
ByVal hkey As LongPtr, _
ByVal pszSubKey As LongPtr, _
ByVal pszValue As LongPtr, _
ByVal srrfFlags 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
SHRegGetValueW = ctypes.windll.shlwapi.SHRegGetValueW
SHRegGetValueW.restype = wintypes.DWORD
SHRegGetValueW.argtypes = [
wintypes.HANDLE, # hkey : HKEY
wintypes.LPCWSTR, # pszSubKey : LPCWSTR optional
wintypes.LPCWSTR, # pszValue : LPCWSTR optional
ctypes.c_int, # srrfFlags : INT
ctypes.POINTER(wintypes.DWORD), # pdwType : DWORD* 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('SHLWAPI.dll')
SHRegGetValueW = Fiddle::Function.new(
lib['SHRegGetValueW'],
[
Fiddle::TYPE_VOIDP, # hkey : HKEY
Fiddle::TYPE_VOIDP, # pszSubKey : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pszValue : LPCWSTR optional
Fiddle::TYPE_INT, # srrfFlags : INT
Fiddle::TYPE_VOIDP, # pdwType : DWORD* 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 = "shlwapi")]
extern "system" {
fn SHRegGetValueW(
hkey: *mut core::ffi::c_void, // HKEY
pszSubKey: *const u16, // LPCWSTR optional
pszValue: *const u16, // LPCWSTR optional
srrfFlags: i32, // INT
pdwType: *mut u32, // DWORD* 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("SHLWAPI.dll", CharSet = CharSet.Unicode)]
public static extern uint SHRegGetValueW(IntPtr hkey, [MarshalAs(UnmanagedType.LPWStr)] string pszSubKey, [MarshalAs(UnmanagedType.LPWStr)] string pszValue, int srrfFlags, IntPtr pdwType, IntPtr pvData, IntPtr pcbData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_SHRegGetValueW' -Namespace Win32 -PassThru
# $api::SHRegGetValueW(hkey, pszSubKey, pszValue, srrfFlags, pdwType, pvData, pcbData)#uselib "SHLWAPI.dll"
#func global SHRegGetValueW "SHRegGetValueW" wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SHRegGetValueW hkey, pszSubKey, pszValue, srrfFlags, varptr(pdwType), pvData, varptr(pcbData) ; 戻り値は stat
; hkey : HKEY -> "wptr"
; pszSubKey : LPCWSTR optional -> "wptr"
; pszValue : LPCWSTR optional -> "wptr"
; srrfFlags : INT -> "wptr"
; pdwType : DWORD* optional, out -> "wptr"
; pvData : void* optional, out -> "wptr"
; pcbData : DWORD* optional, in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHLWAPI.dll" #cfunc global SHRegGetValueW "SHRegGetValueW" sptr, wstr, wstr, int, var, sptr, var ; res = SHRegGetValueW(hkey, pszSubKey, pszValue, srrfFlags, pdwType, pvData, pcbData) ; hkey : HKEY -> "sptr" ; pszSubKey : LPCWSTR optional -> "wstr" ; pszValue : LPCWSTR optional -> "wstr" ; srrfFlags : INT -> "int" ; pdwType : DWORD* optional, out -> "var" ; pvData : void* optional, out -> "sptr" ; pcbData : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHLWAPI.dll" #cfunc global SHRegGetValueW "SHRegGetValueW" sptr, wstr, wstr, int, sptr, sptr, sptr ; res = SHRegGetValueW(hkey, pszSubKey, pszValue, srrfFlags, varptr(pdwType), pvData, varptr(pcbData)) ; hkey : HKEY -> "sptr" ; pszSubKey : LPCWSTR optional -> "wstr" ; pszValue : LPCWSTR optional -> "wstr" ; srrfFlags : INT -> "int" ; pdwType : DWORD* optional, out -> "sptr" ; pvData : void* optional, out -> "sptr" ; pcbData : DWORD* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; WIN32_ERROR SHRegGetValueW(HKEY hkey, LPCWSTR pszSubKey, LPCWSTR pszValue, INT srrfFlags, DWORD* pdwType, void* pvData, DWORD* pcbData) #uselib "SHLWAPI.dll" #cfunc global SHRegGetValueW "SHRegGetValueW" intptr, wstr, wstr, int, var, intptr, var ; res = SHRegGetValueW(hkey, pszSubKey, pszValue, srrfFlags, pdwType, pvData, pcbData) ; hkey : HKEY -> "intptr" ; pszSubKey : LPCWSTR optional -> "wstr" ; pszValue : LPCWSTR optional -> "wstr" ; srrfFlags : INT -> "int" ; pdwType : DWORD* optional, out -> "var" ; pvData : void* optional, out -> "intptr" ; pcbData : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WIN32_ERROR SHRegGetValueW(HKEY hkey, LPCWSTR pszSubKey, LPCWSTR pszValue, INT srrfFlags, DWORD* pdwType, void* pvData, DWORD* pcbData) #uselib "SHLWAPI.dll" #cfunc global SHRegGetValueW "SHRegGetValueW" intptr, wstr, wstr, int, intptr, intptr, intptr ; res = SHRegGetValueW(hkey, pszSubKey, pszValue, srrfFlags, varptr(pdwType), pvData, varptr(pcbData)) ; hkey : HKEY -> "intptr" ; pszSubKey : LPCWSTR optional -> "wstr" ; pszValue : LPCWSTR optional -> "wstr" ; srrfFlags : INT -> "int" ; pdwType : DWORD* optional, out -> "intptr" ; pvData : void* optional, out -> "intptr" ; pcbData : DWORD* optional, in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procSHRegGetValueW = shlwapi.NewProc("SHRegGetValueW")
)
// hkey (HKEY), pszSubKey (LPCWSTR optional), pszValue (LPCWSTR optional), srrfFlags (INT), pdwType (DWORD* optional, out), pvData (void* optional, out), pcbData (DWORD* optional, in/out)
r1, _, err := procSHRegGetValueW.Call(
uintptr(hkey),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszSubKey))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszValue))),
uintptr(srrfFlags),
uintptr(pdwType),
uintptr(pvData),
uintptr(pcbData),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction SHRegGetValueW(
hkey: THandle; // HKEY
pszSubKey: PWideChar; // LPCWSTR optional
pszValue: PWideChar; // LPCWSTR optional
srrfFlags: Integer; // INT
pdwType: Pointer; // DWORD* optional, out
pvData: Pointer; // void* optional, out
pcbData: Pointer // DWORD* optional, in/out
): DWORD; stdcall;
external 'SHLWAPI.dll' name 'SHRegGetValueW';result := DllCall("SHLWAPI\SHRegGetValueW"
, "Ptr", hkey ; HKEY
, "WStr", pszSubKey ; LPCWSTR optional
, "WStr", pszValue ; LPCWSTR optional
, "Int", srrfFlags ; INT
, "Ptr", pdwType ; DWORD* optional, out
, "Ptr", pvData ; void* optional, out
, "Ptr", pcbData ; DWORD* optional, in/out
, "UInt") ; return: WIN32_ERROR●SHRegGetValueW(hkey, pszSubKey, pszValue, srrfFlags, pdwType, pvData, pcbData) = DLL("SHLWAPI.dll", "dword SHRegGetValueW(void*, char*, char*, int, void*, void*, void*)")
# 呼び出し: SHRegGetValueW(hkey, pszSubKey, pszValue, srrfFlags, pdwType, pvData, pcbData)
# hkey : HKEY -> "void*"
# pszSubKey : LPCWSTR optional -> "char*"
# pszValue : LPCWSTR optional -> "char*"
# srrfFlags : INT -> "int"
# pdwType : DWORD* 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 版の利用を推奨。