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

SHCopyKeyW

関数
レジストリキーのサブキーと値を別のキーへ複製する。
DLLSHLWAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

WIN32_ERROR SHCopyKeyW(
    HKEY hkeySrc,
    LPCWSTR pszSrcSubKey,   // optional
    HKEY hkeyDest,
    DWORD fReserved   // optional
);

パラメーター

名前方向
hkeySrcHKEYin
pszSrcSubKeyLPCWSTRinoptional
hkeyDestHKEYin
fReservedDWORDoptional

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR SHCopyKeyW(
    HKEY hkeySrc,
    LPCWSTR pszSrcSubKey,   // optional
    HKEY hkeyDest,
    DWORD fReserved   // optional
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint SHCopyKeyW(
    IntPtr hkeySrc,   // HKEY
    [MarshalAs(UnmanagedType.LPWStr)] string pszSrcSubKey,   // LPCWSTR optional
    IntPtr hkeyDest,   // HKEY
    uint fReserved   // DWORD optional
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SHCopyKeyW(
    hkeySrc As IntPtr,   ' HKEY
    <MarshalAs(UnmanagedType.LPWStr)> pszSrcSubKey As String,   ' LPCWSTR optional
    hkeyDest As IntPtr,   ' HKEY
    fReserved As UInteger   ' DWORD optional
) As UInteger
End Function
' hkeySrc : HKEY
' pszSrcSubKey : LPCWSTR optional
' hkeyDest : HKEY
' fReserved : DWORD optional
Declare PtrSafe Function SHCopyKeyW Lib "shlwapi" ( _
    ByVal hkeySrc As LongPtr, _
    ByVal pszSrcSubKey As LongPtr, _
    ByVal hkeyDest As LongPtr, _
    ByVal fReserved As Long) 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

SHCopyKeyW = ctypes.windll.shlwapi.SHCopyKeyW
SHCopyKeyW.restype = wintypes.DWORD
SHCopyKeyW.argtypes = [
    wintypes.HANDLE,  # hkeySrc : HKEY
    wintypes.LPCWSTR,  # pszSrcSubKey : LPCWSTR optional
    wintypes.HANDLE,  # hkeyDest : HKEY
    wintypes.DWORD,  # fReserved : DWORD optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
SHCopyKeyW = Fiddle::Function.new(
  lib['SHCopyKeyW'],
  [
    Fiddle::TYPE_VOIDP,  # hkeySrc : HKEY
    Fiddle::TYPE_VOIDP,  # pszSrcSubKey : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # hkeyDest : HKEY
    -Fiddle::TYPE_INT,  # fReserved : DWORD optional
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "shlwapi")]
extern "system" {
    fn SHCopyKeyW(
        hkeySrc: *mut core::ffi::c_void,  // HKEY
        pszSrcSubKey: *const u16,  // LPCWSTR optional
        hkeyDest: *mut core::ffi::c_void,  // HKEY
        fReserved: u32  // DWORD optional
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode)]
public static extern uint SHCopyKeyW(IntPtr hkeySrc, [MarshalAs(UnmanagedType.LPWStr)] string pszSrcSubKey, IntPtr hkeyDest, uint fReserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_SHCopyKeyW' -Namespace Win32 -PassThru
# $api::SHCopyKeyW(hkeySrc, pszSrcSubKey, hkeyDest, fReserved)
#uselib "SHLWAPI.dll"
#func global SHCopyKeyW "SHCopyKeyW" wptr, wptr, wptr, wptr
; SHCopyKeyW hkeySrc, pszSrcSubKey, hkeyDest, fReserved   ; 戻り値は stat
; hkeySrc : HKEY -> "wptr"
; pszSrcSubKey : LPCWSTR optional -> "wptr"
; hkeyDest : HKEY -> "wptr"
; fReserved : DWORD optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHLWAPI.dll"
#cfunc global SHCopyKeyW "SHCopyKeyW" sptr, wstr, sptr, int
; res = SHCopyKeyW(hkeySrc, pszSrcSubKey, hkeyDest, fReserved)
; hkeySrc : HKEY -> "sptr"
; pszSrcSubKey : LPCWSTR optional -> "wstr"
; hkeyDest : HKEY -> "sptr"
; fReserved : DWORD optional -> "int"
; WIN32_ERROR SHCopyKeyW(HKEY hkeySrc, LPCWSTR pszSrcSubKey, HKEY hkeyDest, DWORD fReserved)
#uselib "SHLWAPI.dll"
#cfunc global SHCopyKeyW "SHCopyKeyW" intptr, wstr, intptr, int
; res = SHCopyKeyW(hkeySrc, pszSrcSubKey, hkeyDest, fReserved)
; hkeySrc : HKEY -> "intptr"
; pszSrcSubKey : LPCWSTR optional -> "wstr"
; hkeyDest : HKEY -> "intptr"
; fReserved : DWORD optional -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procSHCopyKeyW = shlwapi.NewProc("SHCopyKeyW")
)

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