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

RegCopyTreeA

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

シグネチャ

// ADVAPI32.dll  (ANSI / -A)
#include <windows.h>

WIN32_ERROR RegCopyTreeA(
    HKEY hKeySrc,
    LPCSTR lpSubKey,   // optional
    HKEY hKeyDest
);

パラメーター

名前方向
hKeySrcHKEYin
lpSubKeyLPCSTRinoptional
hKeyDestHKEYin

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

// ADVAPI32.dll  (ANSI / -A)
#include <windows.h>

WIN32_ERROR RegCopyTreeA(
    HKEY hKeySrc,
    LPCSTR lpSubKey,   // optional
    HKEY hKeyDest
);
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint RegCopyTreeA(
    IntPtr hKeySrc,   // HKEY
    [MarshalAs(UnmanagedType.LPStr)] string lpSubKey,   // LPCSTR optional
    IntPtr hKeyDest   // HKEY
);
<DllImport("ADVAPI32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function RegCopyTreeA(
    hKeySrc As IntPtr,   ' HKEY
    <MarshalAs(UnmanagedType.LPStr)> lpSubKey As String,   ' LPCSTR optional
    hKeyDest As IntPtr   ' HKEY
) As UInteger
End Function
' hKeySrc : HKEY
' lpSubKey : LPCSTR optional
' hKeyDest : HKEY
Declare PtrSafe Function RegCopyTreeA Lib "advapi32" ( _
    ByVal hKeySrc As LongPtr, _
    ByVal lpSubKey As String, _
    ByVal hKeyDest As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

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

lib = Fiddle.dlopen('ADVAPI32.dll')
RegCopyTreeA = Fiddle::Function.new(
  lib['RegCopyTreeA'],
  [
    Fiddle::TYPE_VOIDP,  # hKeySrc : HKEY
    Fiddle::TYPE_VOIDP,  # lpSubKey : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # hKeyDest : HKEY
  ],
  -Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn RegCopyTreeA(
        hKeySrc: *mut core::ffi::c_void,  // HKEY
        lpSubKey: *const u8,  // LPCSTR 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.Ansi)]
public static extern uint RegCopyTreeA(IntPtr hKeySrc, [MarshalAs(UnmanagedType.LPStr)] string lpSubKey, IntPtr hKeyDest);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_RegCopyTreeA' -Namespace Win32 -PassThru
# $api::RegCopyTreeA(hKeySrc, lpSubKey, hKeyDest)
#uselib "ADVAPI32.dll"
#func global RegCopyTreeA "RegCopyTreeA" sptr, sptr, sptr
; RegCopyTreeA hKeySrc, lpSubKey, hKeyDest   ; 戻り値は stat
; hKeySrc : HKEY -> "sptr"
; lpSubKey : LPCSTR optional -> "sptr"
; hKeyDest : HKEY -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ADVAPI32.dll"
#cfunc global RegCopyTreeA "RegCopyTreeA" sptr, str, sptr
; res = RegCopyTreeA(hKeySrc, lpSubKey, hKeyDest)
; hKeySrc : HKEY -> "sptr"
; lpSubKey : LPCSTR optional -> "str"
; hKeyDest : HKEY -> "sptr"
; WIN32_ERROR RegCopyTreeA(HKEY hKeySrc, LPCSTR lpSubKey, HKEY hKeyDest)
#uselib "ADVAPI32.dll"
#cfunc global RegCopyTreeA "RegCopyTreeA" intptr, str, intptr
; res = RegCopyTreeA(hKeySrc, lpSubKey, hKeyDest)
; hKeySrc : HKEY -> "intptr"
; lpSubKey : LPCSTR optional -> "str"
; hKeyDest : HKEY -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procRegCopyTreeA = advapi32.NewProc("RegCopyTreeA")
)

// hKeySrc (HKEY), lpSubKey (LPCSTR optional), hKeyDest (HKEY)
r1, _, err := procRegCopyTreeA.Call(
	uintptr(hKeySrc),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpSubKey))),
	uintptr(hKeyDest),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function RegCopyTreeA(
  hKeySrc: THandle;   // HKEY
  lpSubKey: PAnsiChar;   // LPCSTR optional
  hKeyDest: THandle   // HKEY
): DWORD; stdcall;
  external 'ADVAPI32.dll' name 'RegCopyTreeA';
result := DllCall("ADVAPI32\RegCopyTreeA"
    , "Ptr", hKeySrc   ; HKEY
    , "AStr", lpSubKey   ; LPCSTR optional
    , "Ptr", hKeyDest   ; HKEY
    , "UInt")   ; return: WIN32_ERROR
●RegCopyTreeA(hKeySrc, lpSubKey, hKeyDest) = DLL("ADVAPI32.dll", "dword RegCopyTreeA(void*, char*, void*)")
# 呼び出し: RegCopyTreeA(hKeySrc, lpSubKey, hKeyDest)
# hKeySrc : HKEY -> "void*"
# lpSubKey : LPCSTR optional -> "char*"
# hKeyDest : HKEY -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。