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

SHRegDuplicateHKey

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

シグネチャ

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

HKEY SHRegDuplicateHKey(
    HKEY hkey
);

パラメーター

名前方向説明
hkeyHKEYin複製する HKEY ハンドル。

戻り値の型: HKEY

公式ドキュメント

レジストリキーの HKEY ハンドルを複製します。

戻り値

型: HKEY

hkey で指定されたハンドルの複製を返します。

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

各言語での呼び出し定義

// 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)。
const std = @import("std");

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

typedef SHRegDuplicateHKeyNative = Pointer<Void> Function(Pointer<Void>);
typedef SHRegDuplicateHKeyDart = Pointer<Void> Function(Pointer<Void>);
final SHRegDuplicateHKey = DynamicLibrary.open('SHLWAPI.dll')
    .lookupFunction<SHRegDuplicateHKeyNative, SHRegDuplicateHKeyDart>('SHRegDuplicateHKey');
// hkey : HKEY -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SHRegDuplicateHKey(
  hkey: THandle   // HKEY
): THandle; stdcall;
  external 'SHLWAPI.dll' name 'SHRegDuplicateHKey';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SHRegDuplicateHKey"
  c_SHRegDuplicateHKey :: Ptr () -> IO (Ptr ())
-- hkey : HKEY -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let shregduplicatehkey =
  foreign "SHRegDuplicateHKey"
    ((ptr void) @-> returning (ptr void))
(* hkey : HKEY -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library shlwapi (t "SHLWAPI.dll"))
(cffi:use-foreign-library shlwapi)

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