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

SHRegCloseUSKey

関数
開いているユーザー単位レジストリキーのハンドルを閉じる。
DLLSHLWAPI.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// SHLWAPI.dll
#include <windows.h>

WIN32_ERROR SHRegCloseUSKey(
    INT_PTR hUSKey
);

パラメーター

名前方向説明
hUSKeyINT_PTRin

現在開いているレジストリ サブキーへのハンドルです。このサブキーは KEY_SET_VALUE アクセス権で開かれている必要があります。詳細については、レジストリ キーのセキュリティとアクセス権を参照してください。

このハンドルは SHRegOpenUSKey 関数を使用して取得できます。

戻り値の型: WIN32_ERROR

公式ドキュメント

ユーザー固有のサブツリー (HKEY_CURRENT_USER または HKEY_LOCAL_MACHINE) 内にある、ユーザー固有のレジストリ サブキーへのハンドルを閉じます。

戻り値

型: LSTATUS

成功した場合は ERROR_SUCCESS を返します。それ以外の場合は、Winerror.h で定義されている 0 以外のエラー コードを返します。エラーの一般的な説明を取得するには、FormatMessageFORMAT_MESSAGE_FROM_SYSTEM フラグとともに使用してください。

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

各言語での呼び出し定義

// SHLWAPI.dll
#include <windows.h>

WIN32_ERROR SHRegCloseUSKey(
    INT_PTR hUSKey
);
[DllImport("SHLWAPI.dll", ExactSpelling = true)]
static extern uint SHRegCloseUSKey(
    IntPtr hUSKey   // INT_PTR
);
<DllImport("SHLWAPI.dll", ExactSpelling:=True)>
Public Shared Function SHRegCloseUSKey(
    hUSKey As IntPtr   ' INT_PTR
) As UInteger
End Function
' hUSKey : INT_PTR
Declare PtrSafe Function SHRegCloseUSKey Lib "shlwapi" ( _
    ByVal hUSKey As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SHRegCloseUSKey = ctypes.windll.shlwapi.SHRegCloseUSKey
SHRegCloseUSKey.restype = wintypes.DWORD
SHRegCloseUSKey.argtypes = [
    ctypes.c_ssize_t,  # hUSKey : INT_PTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
SHRegCloseUSKey = Fiddle::Function.new(
  lib['SHRegCloseUSKey'],
  [
    Fiddle::TYPE_INTPTR_T,  # hUSKey : INT_PTR
  ],
  -Fiddle::TYPE_INT)
#[link(name = "shlwapi")]
extern "system" {
    fn SHRegCloseUSKey(
        hUSKey: isize  // INT_PTR
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHLWAPI.dll")]
public static extern uint SHRegCloseUSKey(IntPtr hUSKey);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_SHRegCloseUSKey' -Namespace Win32 -PassThru
# $api::SHRegCloseUSKey(hUSKey)
#uselib "SHLWAPI.dll"
#func global SHRegCloseUSKey "SHRegCloseUSKey" sptr
; SHRegCloseUSKey hUSKey   ; 戻り値は stat
; hUSKey : INT_PTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHLWAPI.dll"
#cfunc global SHRegCloseUSKey "SHRegCloseUSKey" sptr
; res = SHRegCloseUSKey(hUSKey)
; hUSKey : INT_PTR -> "sptr"
; WIN32_ERROR SHRegCloseUSKey(INT_PTR hUSKey)
#uselib "SHLWAPI.dll"
#cfunc global SHRegCloseUSKey "SHRegCloseUSKey" intptr
; res = SHRegCloseUSKey(hUSKey)
; hUSKey : INT_PTR -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procSHRegCloseUSKey = shlwapi.NewProc("SHRegCloseUSKey")
)

// hUSKey (INT_PTR)
r1, _, err := procSHRegCloseUSKey.Call(
	uintptr(hUSKey),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function SHRegCloseUSKey(
  hUSKey: NativeInt   // INT_PTR
): DWORD; stdcall;
  external 'SHLWAPI.dll' name 'SHRegCloseUSKey';
result := DllCall("SHLWAPI\SHRegCloseUSKey"
    , "Ptr", hUSKey   ; INT_PTR
    , "UInt")   ; return: WIN32_ERROR
●SHRegCloseUSKey(hUSKey) = DLL("SHLWAPI.dll", "dword SHRegCloseUSKey(int)")
# 呼び出し: SHRegCloseUSKey(hUSKey)
# hUSKey : INT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "shlwapi" fn SHRegCloseUSKey(
    hUSKey: isize // INT_PTR
) callconv(std.os.windows.WINAPI) u32;
proc SHRegCloseUSKey(
    hUSKey: int  # INT_PTR
): uint32 {.importc: "SHRegCloseUSKey", stdcall, dynlib: "SHLWAPI.dll".}
pragma(lib, "shlwapi");
extern(Windows)
uint SHRegCloseUSKey(
    ptrdiff_t hUSKey   // INT_PTR
);
ccall((:SHRegCloseUSKey, "SHLWAPI.dll"), stdcall, UInt32,
      (Int,),
      hUSKey)
# hUSKey : INT_PTR -> Int
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t SHRegCloseUSKey(
    intptr_t hUSKey);
]]
local shlwapi = ffi.load("shlwapi")
-- shlwapi.SHRegCloseUSKey(hUSKey)
-- hUSKey : INT_PTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SHLWAPI.dll');
const SHRegCloseUSKey = lib.func('__stdcall', 'SHRegCloseUSKey', 'uint32_t', ['intptr_t']);
// SHRegCloseUSKey(hUSKey)
// hUSKey : INT_PTR -> 'intptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SHLWAPI.dll", {
  SHRegCloseUSKey: { parameters: ["isize"], result: "u32" },
});
// lib.symbols.SHRegCloseUSKey(hUSKey)
// hUSKey : INT_PTR -> "isize"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t SHRegCloseUSKey(
    intptr_t hUSKey);
C, "SHLWAPI.dll");
// $ffi->SHRegCloseUSKey(hUSKey);
// hUSKey : INT_PTR
// 構造体/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 Shlwapi extends StdCallLibrary {
    Shlwapi INSTANCE = Native.load("shlwapi", Shlwapi.class);
    int SHRegCloseUSKey(
        long hUSKey   // INT_PTR
    );
}
@[Link("shlwapi")]
lib LibSHLWAPI
  fun SHRegCloseUSKey = SHRegCloseUSKey(
    hUSKey : LibC::SSizeT   # INT_PTR
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SHRegCloseUSKeyNative = Uint32 Function(IntPtr);
typedef SHRegCloseUSKeyDart = int Function(int);
final SHRegCloseUSKey = DynamicLibrary.open('SHLWAPI.dll')
    .lookupFunction<SHRegCloseUSKeyNative, SHRegCloseUSKeyDart>('SHRegCloseUSKey');
// hUSKey : INT_PTR -> IntPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SHRegCloseUSKey(
  hUSKey: NativeInt   // INT_PTR
): DWORD; stdcall;
  external 'SHLWAPI.dll' name 'SHRegCloseUSKey';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SHRegCloseUSKey"
  c_SHRegCloseUSKey :: CIntPtr -> IO Word32
-- hUSKey : INT_PTR -> CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let shregcloseuskey =
  foreign "SHRegCloseUSKey"
    (intptr_t @-> returning uint32_t)
(* hUSKey : INT_PTR -> intptr_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library shlwapi (t "SHLWAPI.dll"))
(cffi:use-foreign-library shlwapi)

(cffi:defcfun ("SHRegCloseUSKey" shreg-close-uskey :convention :stdcall) :uint32
  (h-uskey :int64))   ; INT_PTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SHRegCloseUSKey = Win32::API::More->new('SHLWAPI',
    'DWORD SHRegCloseUSKey(LPARAM hUSKey)');
# my $ret = $SHRegCloseUSKey->Call($hUSKey);
# hUSKey : INT_PTR -> LPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型