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