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

RegDeleteTreeA

関数
指定キー配下のサブキーと値を再帰的に削除する。
DLLADVAPI32.dll文字セットANSI (-A)呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// ADVAPI32.dll  (ANSI / -A)
#include <windows.h>

WIN32_ERROR RegDeleteTreeA(
    HKEY hKey,
    LPCSTR lpSubKey   // optional
);

パラメーター

名前方向
hKeyHKEYin
lpSubKeyLPCSTRinoptional

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

// ADVAPI32.dll  (ANSI / -A)
#include <windows.h>

WIN32_ERROR RegDeleteTreeA(
    HKEY hKey,
    LPCSTR lpSubKey   // optional
);
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint RegDeleteTreeA(
    IntPtr hKey,   // HKEY
    [MarshalAs(UnmanagedType.LPStr)] string lpSubKey   // LPCSTR optional
);
<DllImport("ADVAPI32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function RegDeleteTreeA(
    hKey As IntPtr,   ' HKEY
    <MarshalAs(UnmanagedType.LPStr)> lpSubKey As String   ' LPCSTR optional
) As UInteger
End Function
' hKey : HKEY
' lpSubKey : LPCSTR optional
Declare PtrSafe Function RegDeleteTreeA Lib "advapi32" ( _
    ByVal hKey As LongPtr, _
    ByVal lpSubKey As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

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

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

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procRegDeleteTreeA = advapi32.NewProc("RegDeleteTreeA")
)

// hKey (HKEY), lpSubKey (LPCSTR optional)
r1, _, err := procRegDeleteTreeA.Call(
	uintptr(hKey),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpSubKey))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function RegDeleteTreeA(
  hKey: THandle;   // HKEY
  lpSubKey: PAnsiChar   // LPCSTR optional
): DWORD; stdcall;
  external 'ADVAPI32.dll' name 'RegDeleteTreeA';
result := DllCall("ADVAPI32\RegDeleteTreeA"
    , "Ptr", hKey   ; HKEY
    , "AStr", lpSubKey   ; LPCSTR optional
    , "UInt")   ; return: WIN32_ERROR
●RegDeleteTreeA(hKey, lpSubKey) = DLL("ADVAPI32.dll", "dword RegDeleteTreeA(void*, char*)")
# 呼び出し: RegDeleteTreeA(hKey, lpSubKey)
# hKey : HKEY -> "void*"
# lpSubKey : LPCSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。