Win32 API 日本語リファレンス
ホームUI.Shell › SHDeleteEmptyKeyW

SHDeleteEmptyKeyW

関数
サブキーを持たない空のレジストリキーを削除する。
DLLSHLWAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

WIN32_ERROR SHDeleteEmptyKeyW(
    HKEY hkey,
    LPCWSTR pszSubKey   // optional
);

パラメーター

名前方向
hkeyHKEYin
pszSubKeyLPCWSTRinoptional

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR SHDeleteEmptyKeyW(
    HKEY hkey,
    LPCWSTR pszSubKey   // optional
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint SHDeleteEmptyKeyW(
    IntPtr hkey,   // HKEY
    [MarshalAs(UnmanagedType.LPWStr)] string pszSubKey   // LPCWSTR optional
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SHDeleteEmptyKeyW(
    hkey As IntPtr,   ' HKEY
    <MarshalAs(UnmanagedType.LPWStr)> pszSubKey As String   ' LPCWSTR optional
) As UInteger
End Function
' hkey : HKEY
' pszSubKey : LPCWSTR optional
Declare PtrSafe Function SHDeleteEmptyKeyW 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

SHDeleteEmptyKeyW = ctypes.windll.shlwapi.SHDeleteEmptyKeyW
SHDeleteEmptyKeyW.restype = wintypes.DWORD
SHDeleteEmptyKeyW.argtypes = [
    wintypes.HANDLE,  # hkey : HKEY
    wintypes.LPCWSTR,  # pszSubKey : LPCWSTR optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
SHDeleteEmptyKeyW = Fiddle::Function.new(
  lib['SHDeleteEmptyKeyW'],
  [
    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 SHDeleteEmptyKeyW(
        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 SHDeleteEmptyKeyW(IntPtr hkey, [MarshalAs(UnmanagedType.LPWStr)] string pszSubKey);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_SHDeleteEmptyKeyW' -Namespace Win32 -PassThru
# $api::SHDeleteEmptyKeyW(hkey, pszSubKey)
#uselib "SHLWAPI.dll"
#func global SHDeleteEmptyKeyW "SHDeleteEmptyKeyW" wptr, wptr
; SHDeleteEmptyKeyW hkey, pszSubKey   ; 戻り値は stat
; hkey : HKEY -> "wptr"
; pszSubKey : LPCWSTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHLWAPI.dll"
#cfunc global SHDeleteEmptyKeyW "SHDeleteEmptyKeyW" sptr, wstr
; res = SHDeleteEmptyKeyW(hkey, pszSubKey)
; hkey : HKEY -> "sptr"
; pszSubKey : LPCWSTR optional -> "wstr"
; WIN32_ERROR SHDeleteEmptyKeyW(HKEY hkey, LPCWSTR pszSubKey)
#uselib "SHLWAPI.dll"
#cfunc global SHDeleteEmptyKeyW "SHDeleteEmptyKeyW" intptr, wstr
; res = SHDeleteEmptyKeyW(hkey, pszSubKey)
; hkey : HKEY -> "intptr"
; pszSubKey : LPCWSTR optional -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procSHDeleteEmptyKeyW = shlwapi.NewProc("SHDeleteEmptyKeyW")
)

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