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

RegUnLoadKeyA

関数
読み込み済みのハイブをレジストリからアンロードする。
DLLADVAPI32.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

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

パラメーター

名前方向説明
hKeyHKEYin

アンロードするレジストリ キーへのハンドル。このパラメーターには、 RegConnectRegistry 関数の呼び出しによって返されたハンドル、または次のいずれかの定義済みハンドルを指定できます。

HKEY_LOCAL_MACHINE HKEY_USERS

lpSubKeyLPCSTRinoptional

アンロードするサブキーの名前。lpSubKey パラメーターで参照されるキーは、 RegLoadKey 関数を使用して作成されている必要があります。

キー名では大文字と小文字は区別されません。

詳細については、 Registry Element Size Limits を参照してください。

戻り値の型: WIN32_ERROR

公式ドキュメント

指定したレジストリ キーとそのサブキーをレジストリからアンロードします。(ANSI)

戻り値

関数が成功した場合、戻り値は ERROR_SUCCESS です。

関数が失敗した場合、戻り値は Winerror.h で定義されている 0 以外のエラー コードです。 FormatMessage 関数を FORMAT_MESSAGE_FROM_SYSTEM フラグとともに使用すると、エラーの一般的な説明を取得できます。

解説(Remarks)

この関数はレジストリからハイブを削除しますが、レジストリ情報を格納しているファイルは変更しません。ハイブとは、レジストリ階層の最上位を起点とする、キー、サブキー、および値からなる個別のまとまりです。

呼び出し元のプロセスは、レジストリが存在するコンピューター上で SE_RESTORE_NAME 特権および SE_BACKUP_NAME 特権を持っている必要があります。詳細については、 Running with Special Privileges を参照してください。

メモ

winreg.h ヘッダーは、RegUnLoadKey をエイリアスとして定義しており、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI バージョンまたは Unicode バージョンを自動的に選択します。エンコードに依存しないエイリアスの使用と、エンコードに依存しないわけではないコードを混在させると、不一致が生じ、コンパイル エラーまたは実行時エラーを引き起こす可能性があります。詳細については、Conventions for Function Prototypes を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

WIN32_ERROR RegUnLoadKeyA(
    HKEY hKey,
    LPCSTR lpSubKey   // optional
);
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint RegUnLoadKeyA(
    IntPtr hKey,   // HKEY
    [MarshalAs(UnmanagedType.LPStr)] string lpSubKey   // LPCSTR optional
);
<DllImport("ADVAPI32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function RegUnLoadKeyA(
    hKey As IntPtr,   ' HKEY
    <MarshalAs(UnmanagedType.LPStr)> lpSubKey As String   ' LPCSTR optional
) As UInteger
End Function
' hKey : HKEY
' lpSubKey : LPCSTR optional
Declare PtrSafe Function RegUnLoadKeyA 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

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

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

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procRegUnLoadKeyA = advapi32.NewProc("RegUnLoadKeyA")
)

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

extern "advapi32" fn RegUnLoadKeyA(
    hKey: ?*anyopaque, // HKEY
    lpSubKey: [*c]const u8 // LPCSTR optional
) callconv(std.os.windows.WINAPI) u32;
proc RegUnLoadKeyA(
    hKey: pointer,  # HKEY
    lpSubKey: cstring  # LPCSTR optional
): uint32 {.importc: "RegUnLoadKeyA", stdcall, dynlib: "ADVAPI32.dll".}
pragma(lib, "advapi32");
extern(Windows)
uint RegUnLoadKeyA(
    void* hKey,   // HKEY
    const(char)* lpSubKey   // LPCSTR optional
);
ccall((:RegUnLoadKeyA, "ADVAPI32.dll"), stdcall, UInt32,
      (Ptr{Cvoid}, Cstring),
      hKey, lpSubKey)
# hKey : HKEY -> Ptr{Cvoid}
# lpSubKey : LPCSTR optional -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t RegUnLoadKeyA(
    void* hKey,
    const char* lpSubKey);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.RegUnLoadKeyA(hKey, lpSubKey)
-- hKey : HKEY
-- lpSubKey : LPCSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const RegUnLoadKeyA = lib.func('__stdcall', 'RegUnLoadKeyA', 'uint32_t', ['void *', 'str']);
// RegUnLoadKeyA(hKey, lpSubKey)
// hKey : HKEY -> 'void *'
// lpSubKey : LPCSTR optional -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ADVAPI32.dll", {
  RegUnLoadKeyA: { parameters: ["pointer", "buffer"], result: "u32" },
});
// lib.symbols.RegUnLoadKeyA(hKey, lpSubKey)
// hKey : HKEY -> "pointer"
// lpSubKey : LPCSTR optional -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t RegUnLoadKeyA(
    void* hKey,
    const char* lpSubKey);
C, "ADVAPI32.dll");
// $ffi->RegUnLoadKeyA(hKey, lpSubKey);
// hKey : HKEY
// lpSubKey : LPCSTR optional
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Advapi32 extends StdCallLibrary {
    Advapi32 INSTANCE = Native.load("advapi32", Advapi32.class, W32APIOptions.ASCII_OPTIONS);
    int RegUnLoadKeyA(
        Pointer hKey,   // HKEY
        String lpSubKey   // LPCSTR optional
    );
}
@[Link("advapi32")]
lib LibADVAPI32
  fun RegUnLoadKeyA = RegUnLoadKeyA(
    hKey : Void*,   # HKEY
    lpSubKey : UInt8*   # LPCSTR optional
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef RegUnLoadKeyANative = Uint32 Function(Pointer<Void>, Pointer<Utf8>);
typedef RegUnLoadKeyADart = int Function(Pointer<Void>, Pointer<Utf8>);
final RegUnLoadKeyA = DynamicLibrary.open('ADVAPI32.dll')
    .lookupFunction<RegUnLoadKeyANative, RegUnLoadKeyADart>('RegUnLoadKeyA');
// hKey : HKEY -> Pointer<Void>
// lpSubKey : LPCSTR optional -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RegUnLoadKeyA(
  hKey: THandle;   // HKEY
  lpSubKey: PAnsiChar   // LPCSTR optional
): DWORD; stdcall;
  external 'ADVAPI32.dll' name 'RegUnLoadKeyA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RegUnLoadKeyA"
  c_RegUnLoadKeyA :: Ptr () -> CString -> IO Word32
-- hKey : HKEY -> Ptr ()
-- lpSubKey : LPCSTR optional -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let regunloadkeya =
  foreign "RegUnLoadKeyA"
    ((ptr void) @-> string @-> returning uint32_t)
(* hKey : HKEY -> (ptr void) *)
(* lpSubKey : LPCSTR optional -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)

(cffi:defcfun ("RegUnLoadKeyA" reg-un-load-key-a :convention :stdcall) :uint32
  (h-key :pointer)   ; HKEY
  (lp-sub-key :string))   ; LPCSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RegUnLoadKeyA = Win32::API::More->new('ADVAPI32',
    'DWORD RegUnLoadKeyA(HANDLE hKey, LPCSTR lpSubKey)');
# my $ret = $RegUnLoadKeyA->Call($hKey, $lpSubKey);
# hKey : HKEY -> HANDLE
# lpSubKey : LPCSTR optional -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
公式の関連項目
使用する型