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

RegDeleteKeyValueA

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

シグネチャ

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

WIN32_ERROR RegDeleteKeyValueA(
    HKEY hKey,
    LPCSTR lpSubKey,   // optional
    LPCSTR lpValueName   // optional
);

パラメーター

名前方向
hKeyHKEYin
lpSubKeyLPCSTRinoptional
lpValueNameLPCSTRinoptional

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

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

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

lib = Fiddle.dlopen('ADVAPI32.dll')
RegDeleteKeyValueA = Fiddle::Function.new(
  lib['RegDeleteKeyValueA'],
  [
    Fiddle::TYPE_VOIDP,  # hKey : HKEY
    Fiddle::TYPE_VOIDP,  # lpSubKey : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # lpValueName : LPCSTR optional
  ],
  -Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn RegDeleteKeyValueA(
        hKey: *mut core::ffi::c_void,  // HKEY
        lpSubKey: *const u8,  // LPCSTR optional
        lpValueName: *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 RegDeleteKeyValueA(IntPtr hKey, [MarshalAs(UnmanagedType.LPStr)] string lpSubKey, [MarshalAs(UnmanagedType.LPStr)] string lpValueName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_RegDeleteKeyValueA' -Namespace Win32 -PassThru
# $api::RegDeleteKeyValueA(hKey, lpSubKey, lpValueName)
#uselib "ADVAPI32.dll"
#func global RegDeleteKeyValueA "RegDeleteKeyValueA" sptr, sptr, sptr
; RegDeleteKeyValueA hKey, lpSubKey, lpValueName   ; 戻り値は stat
; hKey : HKEY -> "sptr"
; lpSubKey : LPCSTR optional -> "sptr"
; lpValueName : LPCSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ADVAPI32.dll"
#cfunc global RegDeleteKeyValueA "RegDeleteKeyValueA" sptr, str, str
; res = RegDeleteKeyValueA(hKey, lpSubKey, lpValueName)
; hKey : HKEY -> "sptr"
; lpSubKey : LPCSTR optional -> "str"
; lpValueName : LPCSTR optional -> "str"
; WIN32_ERROR RegDeleteKeyValueA(HKEY hKey, LPCSTR lpSubKey, LPCSTR lpValueName)
#uselib "ADVAPI32.dll"
#cfunc global RegDeleteKeyValueA "RegDeleteKeyValueA" intptr, str, str
; res = RegDeleteKeyValueA(hKey, lpSubKey, lpValueName)
; hKey : HKEY -> "intptr"
; lpSubKey : LPCSTR optional -> "str"
; lpValueName : LPCSTR optional -> "str"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procRegDeleteKeyValueA = advapi32.NewProc("RegDeleteKeyValueA")
)

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