Win32 API 日本語リファレンス
ホームSystem.Registry › RegDeleteKeyExW

RegDeleteKeyExW

関数
32/64ビットビューを指定してサブキーを削除する。
DLLADVAPI32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// ADVAPI32.dll  (Unicode / -W)
#include <windows.h>

WIN32_ERROR RegDeleteKeyExW(
    HKEY hKey,
    LPCWSTR lpSubKey,
    DWORD samDesired,
    DWORD Reserved   // optional
);

パラメーター

名前方向
hKeyHKEYin
lpSubKeyLPCWSTRin
samDesiredDWORDin
ReservedDWORDoptional

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

// ADVAPI32.dll  (Unicode / -W)
#include <windows.h>

WIN32_ERROR RegDeleteKeyExW(
    HKEY hKey,
    LPCWSTR lpSubKey,
    DWORD samDesired,
    DWORD Reserved   // optional
);
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint RegDeleteKeyExW(
    IntPtr hKey,   // HKEY
    [MarshalAs(UnmanagedType.LPWStr)] string lpSubKey,   // LPCWSTR
    uint samDesired,   // DWORD
    uint Reserved   // DWORD optional
);
<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RegDeleteKeyExW(
    hKey As IntPtr,   ' HKEY
    <MarshalAs(UnmanagedType.LPWStr)> lpSubKey As String,   ' LPCWSTR
    samDesired As UInteger,   ' DWORD
    Reserved As UInteger   ' DWORD optional
) As UInteger
End Function
' hKey : HKEY
' lpSubKey : LPCWSTR
' samDesired : DWORD
' Reserved : DWORD optional
Declare PtrSafe Function RegDeleteKeyExW Lib "advapi32" ( _
    ByVal hKey As LongPtr, _
    ByVal lpSubKey As LongPtr, _
    ByVal samDesired As Long, _
    ByVal Reserved 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

RegDeleteKeyExW = ctypes.windll.advapi32.RegDeleteKeyExW
RegDeleteKeyExW.restype = wintypes.DWORD
RegDeleteKeyExW.argtypes = [
    wintypes.HANDLE,  # hKey : HKEY
    wintypes.LPCWSTR,  # lpSubKey : LPCWSTR
    wintypes.DWORD,  # samDesired : DWORD
    wintypes.DWORD,  # Reserved : DWORD optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
RegDeleteKeyExW = Fiddle::Function.new(
  lib['RegDeleteKeyExW'],
  [
    Fiddle::TYPE_VOIDP,  # hKey : HKEY
    Fiddle::TYPE_VOIDP,  # lpSubKey : LPCWSTR
    -Fiddle::TYPE_INT,  # samDesired : DWORD
    -Fiddle::TYPE_INT,  # Reserved : DWORD optional
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "advapi32")]
extern "system" {
    fn RegDeleteKeyExW(
        hKey: *mut core::ffi::c_void,  // HKEY
        lpSubKey: *const u16,  // LPCWSTR
        samDesired: u32,  // DWORD
        Reserved: u32  // DWORD optional
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode)]
public static extern uint RegDeleteKeyExW(IntPtr hKey, [MarshalAs(UnmanagedType.LPWStr)] string lpSubKey, uint samDesired, uint Reserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_RegDeleteKeyExW' -Namespace Win32 -PassThru
# $api::RegDeleteKeyExW(hKey, lpSubKey, samDesired, Reserved)
#uselib "ADVAPI32.dll"
#func global RegDeleteKeyExW "RegDeleteKeyExW" wptr, wptr, wptr, wptr
; RegDeleteKeyExW hKey, lpSubKey, samDesired, Reserved   ; 戻り値は stat
; hKey : HKEY -> "wptr"
; lpSubKey : LPCWSTR -> "wptr"
; samDesired : DWORD -> "wptr"
; Reserved : DWORD optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ADVAPI32.dll"
#cfunc global RegDeleteKeyExW "RegDeleteKeyExW" sptr, wstr, int, int
; res = RegDeleteKeyExW(hKey, lpSubKey, samDesired, Reserved)
; hKey : HKEY -> "sptr"
; lpSubKey : LPCWSTR -> "wstr"
; samDesired : DWORD -> "int"
; Reserved : DWORD optional -> "int"
; WIN32_ERROR RegDeleteKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD samDesired, DWORD Reserved)
#uselib "ADVAPI32.dll"
#cfunc global RegDeleteKeyExW "RegDeleteKeyExW" intptr, wstr, int, int
; res = RegDeleteKeyExW(hKey, lpSubKey, samDesired, Reserved)
; hKey : HKEY -> "intptr"
; lpSubKey : LPCWSTR -> "wstr"
; samDesired : DWORD -> "int"
; Reserved : DWORD optional -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procRegDeleteKeyExW = advapi32.NewProc("RegDeleteKeyExW")
)

// hKey (HKEY), lpSubKey (LPCWSTR), samDesired (DWORD), Reserved (DWORD optional)
r1, _, err := procRegDeleteKeyExW.Call(
	uintptr(hKey),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpSubKey))),
	uintptr(samDesired),
	uintptr(Reserved),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function RegDeleteKeyExW(
  hKey: THandle;   // HKEY
  lpSubKey: PWideChar;   // LPCWSTR
  samDesired: DWORD;   // DWORD
  Reserved: DWORD   // DWORD optional
): DWORD; stdcall;
  external 'ADVAPI32.dll' name 'RegDeleteKeyExW';
result := DllCall("ADVAPI32\RegDeleteKeyExW"
    , "Ptr", hKey   ; HKEY
    , "WStr", lpSubKey   ; LPCWSTR
    , "UInt", samDesired   ; DWORD
    , "UInt", Reserved   ; DWORD optional
    , "UInt")   ; return: WIN32_ERROR
●RegDeleteKeyExW(hKey, lpSubKey, samDesired, Reserved) = DLL("ADVAPI32.dll", "dword RegDeleteKeyExW(void*, char*, dword, dword)")
# 呼び出し: RegDeleteKeyExW(hKey, lpSubKey, samDesired, Reserved)
# hKey : HKEY -> "void*"
# lpSubKey : LPCWSTR -> "char*"
# samDesired : DWORD -> "dword"
# Reserved : DWORD optional -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。