SHRegSetPathA
関数ファイルパスを環境変数化してレジストリ値に書き込む。
シグネチャ
// SHLWAPI.dll (ANSI / -A)
#include <windows.h>
WIN32_ERROR SHRegSetPathA(
HKEY hKey,
LPCSTR pcszSubKey, // optional
LPCSTR pcszValue, // optional
LPCSTR pcszPath,
DWORD dwFlags
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hKey | HKEY | in |
| pcszSubKey | LPCSTR | inoptional |
| pcszValue | LPCSTR | inoptional |
| pcszPath | LPCSTR | in |
| dwFlags | DWORD | in |
戻り値の型: WIN32_ERROR
各言語での呼び出し定義
// SHLWAPI.dll (ANSI / -A)
#include <windows.h>
WIN32_ERROR SHRegSetPathA(
HKEY hKey,
LPCSTR pcszSubKey, // optional
LPCSTR pcszValue, // optional
LPCSTR pcszPath,
DWORD dwFlags
);[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint SHRegSetPathA(
IntPtr hKey, // HKEY
[MarshalAs(UnmanagedType.LPStr)] string pcszSubKey, // LPCSTR optional
[MarshalAs(UnmanagedType.LPStr)] string pcszValue, // LPCSTR optional
[MarshalAs(UnmanagedType.LPStr)] string pcszPath, // LPCSTR
uint dwFlags // DWORD
);<DllImport("SHLWAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SHRegSetPathA(
hKey As IntPtr, ' HKEY
<MarshalAs(UnmanagedType.LPStr)> pcszSubKey As String, ' LPCSTR optional
<MarshalAs(UnmanagedType.LPStr)> pcszValue As String, ' LPCSTR optional
<MarshalAs(UnmanagedType.LPStr)> pcszPath As String, ' LPCSTR
dwFlags As UInteger ' DWORD
) As UInteger
End Function' hKey : HKEY
' pcszSubKey : LPCSTR optional
' pcszValue : LPCSTR optional
' pcszPath : LPCSTR
' dwFlags : DWORD
Declare PtrSafe Function SHRegSetPathA Lib "shlwapi" ( _
ByVal hKey As LongPtr, _
ByVal pcszSubKey As String, _
ByVal pcszValue As String, _
ByVal pcszPath 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
SHRegSetPathA = ctypes.windll.shlwapi.SHRegSetPathA
SHRegSetPathA.restype = wintypes.DWORD
SHRegSetPathA.argtypes = [
wintypes.HANDLE, # hKey : HKEY
wintypes.LPCSTR, # pcszSubKey : LPCSTR optional
wintypes.LPCSTR, # pcszValue : LPCSTR optional
wintypes.LPCSTR, # pcszPath : LPCSTR
wintypes.DWORD, # dwFlags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHLWAPI.dll')
SHRegSetPathA = Fiddle::Function.new(
lib['SHRegSetPathA'],
[
Fiddle::TYPE_VOIDP, # hKey : HKEY
Fiddle::TYPE_VOIDP, # pcszSubKey : LPCSTR optional
Fiddle::TYPE_VOIDP, # pcszValue : LPCSTR optional
Fiddle::TYPE_VOIDP, # pcszPath : LPCSTR
-Fiddle::TYPE_INT, # dwFlags : DWORD
],
-Fiddle::TYPE_INT)#[link(name = "shlwapi")]
extern "system" {
fn SHRegSetPathA(
hKey: *mut core::ffi::c_void, // HKEY
pcszSubKey: *const u8, // LPCSTR optional
pcszValue: *const u8, // LPCSTR optional
pcszPath: *const u8, // LPCSTR
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 SHRegSetPathA(IntPtr hKey, [MarshalAs(UnmanagedType.LPStr)] string pcszSubKey, [MarshalAs(UnmanagedType.LPStr)] string pcszValue, [MarshalAs(UnmanagedType.LPStr)] string pcszPath, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_SHRegSetPathA' -Namespace Win32 -PassThru
# $api::SHRegSetPathA(hKey, pcszSubKey, pcszValue, pcszPath, dwFlags)#uselib "SHLWAPI.dll"
#func global SHRegSetPathA "SHRegSetPathA" sptr, sptr, sptr, sptr, sptr
; SHRegSetPathA hKey, pcszSubKey, pcszValue, pcszPath, dwFlags ; 戻り値は stat
; hKey : HKEY -> "sptr"
; pcszSubKey : LPCSTR optional -> "sptr"
; pcszValue : LPCSTR optional -> "sptr"
; pcszPath : LPCSTR -> "sptr"
; dwFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SHLWAPI.dll"
#cfunc global SHRegSetPathA "SHRegSetPathA" sptr, str, str, str, int
; res = SHRegSetPathA(hKey, pcszSubKey, pcszValue, pcszPath, dwFlags)
; hKey : HKEY -> "sptr"
; pcszSubKey : LPCSTR optional -> "str"
; pcszValue : LPCSTR optional -> "str"
; pcszPath : LPCSTR -> "str"
; dwFlags : DWORD -> "int"; WIN32_ERROR SHRegSetPathA(HKEY hKey, LPCSTR pcszSubKey, LPCSTR pcszValue, LPCSTR pcszPath, DWORD dwFlags)
#uselib "SHLWAPI.dll"
#cfunc global SHRegSetPathA "SHRegSetPathA" intptr, str, str, str, int
; res = SHRegSetPathA(hKey, pcszSubKey, pcszValue, pcszPath, dwFlags)
; hKey : HKEY -> "intptr"
; pcszSubKey : LPCSTR optional -> "str"
; pcszValue : LPCSTR optional -> "str"
; pcszPath : LPCSTR -> "str"
; dwFlags : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procSHRegSetPathA = shlwapi.NewProc("SHRegSetPathA")
)
// hKey (HKEY), pcszSubKey (LPCSTR optional), pcszValue (LPCSTR optional), pcszPath (LPCSTR), dwFlags (DWORD)
r1, _, err := procSHRegSetPathA.Call(
uintptr(hKey),
uintptr(unsafe.Pointer(windows.BytePtrFromString(pcszSubKey))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(pcszValue))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(pcszPath))),
uintptr(dwFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction SHRegSetPathA(
hKey: THandle; // HKEY
pcszSubKey: PAnsiChar; // LPCSTR optional
pcszValue: PAnsiChar; // LPCSTR optional
pcszPath: PAnsiChar; // LPCSTR
dwFlags: DWORD // DWORD
): DWORD; stdcall;
external 'SHLWAPI.dll' name 'SHRegSetPathA';result := DllCall("SHLWAPI\SHRegSetPathA"
, "Ptr", hKey ; HKEY
, "AStr", pcszSubKey ; LPCSTR optional
, "AStr", pcszValue ; LPCSTR optional
, "AStr", pcszPath ; LPCSTR
, "UInt", dwFlags ; DWORD
, "UInt") ; return: WIN32_ERROR●SHRegSetPathA(hKey, pcszSubKey, pcszValue, pcszPath, dwFlags) = DLL("SHLWAPI.dll", "dword SHRegSetPathA(void*, char*, char*, char*, dword)")
# 呼び出し: SHRegSetPathA(hKey, pcszSubKey, pcszValue, pcszPath, dwFlags)
# hKey : HKEY -> "void*"
# pcszSubKey : LPCSTR optional -> "char*"
# pcszValue : LPCSTR optional -> "char*"
# pcszPath : LPCSTR -> "char*"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。