SHRegGetPathW
関数レジストリ値からファイルパスを取得し環境変数を展開する。
シグネチャ
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR SHRegGetPathW(
HKEY hKey,
LPCWSTR pcszSubKey, // optional
LPCWSTR pcszValue, // optional
LPWSTR pszPath,
DWORD dwFlags
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hKey | HKEY | in |
| pcszSubKey | LPCWSTR | inoptional |
| pcszValue | LPCWSTR | inoptional |
| pszPath | LPWSTR | out |
| dwFlags | DWORD | in |
戻り値の型: WIN32_ERROR
各言語での呼び出し定義
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR SHRegGetPathW(
HKEY hKey,
LPCWSTR pcszSubKey, // optional
LPCWSTR pcszValue, // optional
LPWSTR pszPath,
DWORD dwFlags
);[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint SHRegGetPathW(
IntPtr hKey, // HKEY
[MarshalAs(UnmanagedType.LPWStr)] string pcszSubKey, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string pcszValue, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszPath, // LPWSTR out
uint dwFlags // DWORD
);<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SHRegGetPathW(
hKey As IntPtr, ' HKEY
<MarshalAs(UnmanagedType.LPWStr)> pcszSubKey As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> pcszValue As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> pszPath As System.Text.StringBuilder, ' LPWSTR out
dwFlags As UInteger ' DWORD
) As UInteger
End Function' hKey : HKEY
' pcszSubKey : LPCWSTR optional
' pcszValue : LPCWSTR optional
' pszPath : LPWSTR out
' dwFlags : DWORD
Declare PtrSafe Function SHRegGetPathW Lib "shlwapi" ( _
ByVal hKey As LongPtr, _
ByVal pcszSubKey As LongPtr, _
ByVal pcszValue As LongPtr, _
ByVal pszPath As LongPtr, _
ByVal dwFlags As Long) 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
SHRegGetPathW = ctypes.windll.shlwapi.SHRegGetPathW
SHRegGetPathW.restype = wintypes.DWORD
SHRegGetPathW.argtypes = [
wintypes.HANDLE, # hKey : HKEY
wintypes.LPCWSTR, # pcszSubKey : LPCWSTR optional
wintypes.LPCWSTR, # pcszValue : LPCWSTR optional
wintypes.LPWSTR, # pszPath : LPWSTR out
wintypes.DWORD, # dwFlags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHLWAPI.dll')
SHRegGetPathW = Fiddle::Function.new(
lib['SHRegGetPathW'],
[
Fiddle::TYPE_VOIDP, # hKey : HKEY
Fiddle::TYPE_VOIDP, # pcszSubKey : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pcszValue : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pszPath : LPWSTR out
-Fiddle::TYPE_INT, # dwFlags : DWORD
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "shlwapi")]
extern "system" {
fn SHRegGetPathW(
hKey: *mut core::ffi::c_void, // HKEY
pcszSubKey: *const u16, // LPCWSTR optional
pcszValue: *const u16, // LPCWSTR optional
pszPath: *mut u16, // LPWSTR out
dwFlags: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode)]
public static extern uint SHRegGetPathW(IntPtr hKey, [MarshalAs(UnmanagedType.LPWStr)] string pcszSubKey, [MarshalAs(UnmanagedType.LPWStr)] string pcszValue, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszPath, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_SHRegGetPathW' -Namespace Win32 -PassThru
# $api::SHRegGetPathW(hKey, pcszSubKey, pcszValue, pszPath, dwFlags)#uselib "SHLWAPI.dll"
#func global SHRegGetPathW "SHRegGetPathW" wptr, wptr, wptr, wptr, wptr
; SHRegGetPathW hKey, pcszSubKey, pcszValue, varptr(pszPath), dwFlags ; 戻り値は stat
; hKey : HKEY -> "wptr"
; pcszSubKey : LPCWSTR optional -> "wptr"
; pcszValue : LPCWSTR optional -> "wptr"
; pszPath : LPWSTR out -> "wptr"
; dwFlags : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHLWAPI.dll" #cfunc global SHRegGetPathW "SHRegGetPathW" sptr, wstr, wstr, var, int ; res = SHRegGetPathW(hKey, pcszSubKey, pcszValue, pszPath, dwFlags) ; hKey : HKEY -> "sptr" ; pcszSubKey : LPCWSTR optional -> "wstr" ; pcszValue : LPCWSTR optional -> "wstr" ; pszPath : LPWSTR out -> "var" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHLWAPI.dll" #cfunc global SHRegGetPathW "SHRegGetPathW" sptr, wstr, wstr, sptr, int ; res = SHRegGetPathW(hKey, pcszSubKey, pcszValue, varptr(pszPath), dwFlags) ; hKey : HKEY -> "sptr" ; pcszSubKey : LPCWSTR optional -> "wstr" ; pcszValue : LPCWSTR optional -> "wstr" ; pszPath : LPWSTR out -> "sptr" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; WIN32_ERROR SHRegGetPathW(HKEY hKey, LPCWSTR pcszSubKey, LPCWSTR pcszValue, LPWSTR pszPath, DWORD dwFlags) #uselib "SHLWAPI.dll" #cfunc global SHRegGetPathW "SHRegGetPathW" intptr, wstr, wstr, var, int ; res = SHRegGetPathW(hKey, pcszSubKey, pcszValue, pszPath, dwFlags) ; hKey : HKEY -> "intptr" ; pcszSubKey : LPCWSTR optional -> "wstr" ; pcszValue : LPCWSTR optional -> "wstr" ; pszPath : LPWSTR out -> "var" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WIN32_ERROR SHRegGetPathW(HKEY hKey, LPCWSTR pcszSubKey, LPCWSTR pcszValue, LPWSTR pszPath, DWORD dwFlags) #uselib "SHLWAPI.dll" #cfunc global SHRegGetPathW "SHRegGetPathW" intptr, wstr, wstr, intptr, int ; res = SHRegGetPathW(hKey, pcszSubKey, pcszValue, varptr(pszPath), dwFlags) ; hKey : HKEY -> "intptr" ; pcszSubKey : LPCWSTR optional -> "wstr" ; pcszValue : LPCWSTR optional -> "wstr" ; pszPath : LPWSTR out -> "intptr" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procSHRegGetPathW = shlwapi.NewProc("SHRegGetPathW")
)
// hKey (HKEY), pcszSubKey (LPCWSTR optional), pcszValue (LPCWSTR optional), pszPath (LPWSTR out), dwFlags (DWORD)
r1, _, err := procSHRegGetPathW.Call(
uintptr(hKey),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pcszSubKey))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pcszValue))),
uintptr(pszPath),
uintptr(dwFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction SHRegGetPathW(
hKey: THandle; // HKEY
pcszSubKey: PWideChar; // LPCWSTR optional
pcszValue: PWideChar; // LPCWSTR optional
pszPath: PWideChar; // LPWSTR out
dwFlags: DWORD // DWORD
): DWORD; stdcall;
external 'SHLWAPI.dll' name 'SHRegGetPathW';result := DllCall("SHLWAPI\SHRegGetPathW"
, "Ptr", hKey ; HKEY
, "WStr", pcszSubKey ; LPCWSTR optional
, "WStr", pcszValue ; LPCWSTR optional
, "Ptr", pszPath ; LPWSTR out
, "UInt", dwFlags ; DWORD
, "UInt") ; return: WIN32_ERROR●SHRegGetPathW(hKey, pcszSubKey, pcszValue, pszPath, dwFlags) = DLL("SHLWAPI.dll", "dword SHRegGetPathW(void*, char*, char*, char*, dword)")
# 呼び出し: SHRegGetPathW(hKey, pcszSubKey, pcszValue, pszPath, dwFlags)
# hKey : HKEY -> "void*"
# pcszSubKey : LPCWSTR optional -> "char*"
# pcszValue : LPCWSTR optional -> "char*"
# pszPath : LPWSTR out -> "char*"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。