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

RegCopyTreeW

関数
指定キーのサブツリー全体を別のキーへコピーする。
DLLADVAPI32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

WIN32_ERROR RegCopyTreeW(
    HKEY hKeySrc,
    LPCWSTR lpSubKey,   // optional
    HKEY hKeyDest
);

パラメーター

名前方向
hKeySrcHKEYin
lpSubKeyLPCWSTRinoptional
hKeyDestHKEYin

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR RegCopyTreeW(
    HKEY hKeySrc,
    LPCWSTR lpSubKey,   // optional
    HKEY hKeyDest
);
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint RegCopyTreeW(
    IntPtr hKeySrc,   // HKEY
    [MarshalAs(UnmanagedType.LPWStr)] string lpSubKey,   // LPCWSTR optional
    IntPtr hKeyDest   // HKEY
);
<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RegCopyTreeW(
    hKeySrc As IntPtr,   ' HKEY
    <MarshalAs(UnmanagedType.LPWStr)> lpSubKey As String,   ' LPCWSTR optional
    hKeyDest As IntPtr   ' HKEY
) As UInteger
End Function
' hKeySrc : HKEY
' lpSubKey : LPCWSTR optional
' hKeyDest : HKEY
Declare PtrSafe Function RegCopyTreeW Lib "advapi32" ( _
    ByVal hKeySrc As LongPtr, _
    ByVal lpSubKey As LongPtr, _
    ByVal hKeyDest As LongPtr) 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

RegCopyTreeW = ctypes.windll.advapi32.RegCopyTreeW
RegCopyTreeW.restype = wintypes.DWORD
RegCopyTreeW.argtypes = [
    wintypes.HANDLE,  # hKeySrc : HKEY
    wintypes.LPCWSTR,  # lpSubKey : LPCWSTR optional
    wintypes.HANDLE,  # hKeyDest : HKEY
]
require 'fiddle'
require 'fiddle/import'

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

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procRegCopyTreeW = advapi32.NewProc("RegCopyTreeW")
)

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