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