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

SHRegDuplicateHKey

関数
レジストリキーのハンドルを複製して新しいハンドルを返す。
DLLSHLWAPI.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HKEY SHRegDuplicateHKey(
    HKEY hkey
);

パラメーター

名前方向説明
hkeyHKEYin複製する元のレジストリキーハンドル。新しい独立したハンドルが返る。

戻り値の型: HKEY

各言語での呼び出し定義

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

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

SHRegDuplicateHKey = ctypes.windll.shlwapi.SHRegDuplicateHKey
SHRegDuplicateHKey.restype = ctypes.c_void_p
SHRegDuplicateHKey.argtypes = [
    wintypes.HANDLE,  # hkey : HKEY
]
require 'fiddle'
require 'fiddle/import'

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

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procSHRegDuplicateHKey = shlwapi.NewProc("SHRegDuplicateHKey")
)

// hkey (HKEY)
r1, _, err := procSHRegDuplicateHKey.Call(
	uintptr(hkey),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HKEY
function SHRegDuplicateHKey(
  hkey: THandle   // HKEY
): THandle; stdcall;
  external 'SHLWAPI.dll' name 'SHRegDuplicateHKey';
result := DllCall("SHLWAPI\SHRegDuplicateHKey"
    , "Ptr", hkey   ; HKEY
    , "Ptr")   ; return: HKEY
●SHRegDuplicateHKey(hkey) = DLL("SHLWAPI.dll", "void* SHRegDuplicateHKey(void*)")
# 呼び出し: SHRegDuplicateHKey(hkey)
# hkey : HKEY -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。