ホーム › System.Registry › RegReplaceKeyW
RegReplaceKeyW
関数指定キーのバックアップ用ファイルを置き換える。
シグネチャ
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR RegReplaceKeyW(
HKEY hKey,
LPCWSTR lpSubKey, // optional
LPCWSTR lpNewFile,
LPCWSTR lpOldFile
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hKey | HKEY | in |
| lpSubKey | LPCWSTR | inoptional |
| lpNewFile | LPCWSTR | in |
| lpOldFile | LPCWSTR | in |
戻り値の型: WIN32_ERROR
各言語での呼び出し定義
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR RegReplaceKeyW(
HKEY hKey,
LPCWSTR lpSubKey, // optional
LPCWSTR lpNewFile,
LPCWSTR lpOldFile
);[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint RegReplaceKeyW(
IntPtr hKey, // HKEY
[MarshalAs(UnmanagedType.LPWStr)] string lpSubKey, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string lpNewFile, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string lpOldFile // LPCWSTR
);<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RegReplaceKeyW(
hKey As IntPtr, ' HKEY
<MarshalAs(UnmanagedType.LPWStr)> lpSubKey As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> lpNewFile As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> lpOldFile As String ' LPCWSTR
) As UInteger
End Function' hKey : HKEY
' lpSubKey : LPCWSTR optional
' lpNewFile : LPCWSTR
' lpOldFile : LPCWSTR
Declare PtrSafe Function RegReplaceKeyW Lib "advapi32" ( _
ByVal hKey As LongPtr, _
ByVal lpSubKey As LongPtr, _
ByVal lpNewFile As LongPtr, _
ByVal lpOldFile 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
RegReplaceKeyW = ctypes.windll.advapi32.RegReplaceKeyW
RegReplaceKeyW.restype = wintypes.DWORD
RegReplaceKeyW.argtypes = [
wintypes.HANDLE, # hKey : HKEY
wintypes.LPCWSTR, # lpSubKey : LPCWSTR optional
wintypes.LPCWSTR, # lpNewFile : LPCWSTR
wintypes.LPCWSTR, # lpOldFile : LPCWSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
RegReplaceKeyW = Fiddle::Function.new(
lib['RegReplaceKeyW'],
[
Fiddle::TYPE_VOIDP, # hKey : HKEY
Fiddle::TYPE_VOIDP, # lpSubKey : LPCWSTR optional
Fiddle::TYPE_VOIDP, # lpNewFile : LPCWSTR
Fiddle::TYPE_VOIDP, # lpOldFile : LPCWSTR
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "advapi32")]
extern "system" {
fn RegReplaceKeyW(
hKey: *mut core::ffi::c_void, // HKEY
lpSubKey: *const u16, // LPCWSTR optional
lpNewFile: *const u16, // LPCWSTR
lpOldFile: *const u16 // LPCWSTR
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode)]
public static extern uint RegReplaceKeyW(IntPtr hKey, [MarshalAs(UnmanagedType.LPWStr)] string lpSubKey, [MarshalAs(UnmanagedType.LPWStr)] string lpNewFile, [MarshalAs(UnmanagedType.LPWStr)] string lpOldFile);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_RegReplaceKeyW' -Namespace Win32 -PassThru
# $api::RegReplaceKeyW(hKey, lpSubKey, lpNewFile, lpOldFile)#uselib "ADVAPI32.dll"
#func global RegReplaceKeyW "RegReplaceKeyW" wptr, wptr, wptr, wptr
; RegReplaceKeyW hKey, lpSubKey, lpNewFile, lpOldFile ; 戻り値は stat
; hKey : HKEY -> "wptr"
; lpSubKey : LPCWSTR optional -> "wptr"
; lpNewFile : LPCWSTR -> "wptr"
; lpOldFile : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ADVAPI32.dll"
#cfunc global RegReplaceKeyW "RegReplaceKeyW" sptr, wstr, wstr, wstr
; res = RegReplaceKeyW(hKey, lpSubKey, lpNewFile, lpOldFile)
; hKey : HKEY -> "sptr"
; lpSubKey : LPCWSTR optional -> "wstr"
; lpNewFile : LPCWSTR -> "wstr"
; lpOldFile : LPCWSTR -> "wstr"; WIN32_ERROR RegReplaceKeyW(HKEY hKey, LPCWSTR lpSubKey, LPCWSTR lpNewFile, LPCWSTR lpOldFile)
#uselib "ADVAPI32.dll"
#cfunc global RegReplaceKeyW "RegReplaceKeyW" intptr, wstr, wstr, wstr
; res = RegReplaceKeyW(hKey, lpSubKey, lpNewFile, lpOldFile)
; hKey : HKEY -> "intptr"
; lpSubKey : LPCWSTR optional -> "wstr"
; lpNewFile : LPCWSTR -> "wstr"
; lpOldFile : LPCWSTR -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procRegReplaceKeyW = advapi32.NewProc("RegReplaceKeyW")
)
// hKey (HKEY), lpSubKey (LPCWSTR optional), lpNewFile (LPCWSTR), lpOldFile (LPCWSTR)
r1, _, err := procRegReplaceKeyW.Call(
uintptr(hKey),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpSubKey))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpNewFile))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpOldFile))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction RegReplaceKeyW(
hKey: THandle; // HKEY
lpSubKey: PWideChar; // LPCWSTR optional
lpNewFile: PWideChar; // LPCWSTR
lpOldFile: PWideChar // LPCWSTR
): DWORD; stdcall;
external 'ADVAPI32.dll' name 'RegReplaceKeyW';result := DllCall("ADVAPI32\RegReplaceKeyW"
, "Ptr", hKey ; HKEY
, "WStr", lpSubKey ; LPCWSTR optional
, "WStr", lpNewFile ; LPCWSTR
, "WStr", lpOldFile ; LPCWSTR
, "UInt") ; return: WIN32_ERROR●RegReplaceKeyW(hKey, lpSubKey, lpNewFile, lpOldFile) = DLL("ADVAPI32.dll", "dword RegReplaceKeyW(void*, char*, char*, char*)")
# 呼び出し: RegReplaceKeyW(hKey, lpSubKey, lpNewFile, lpOldFile)
# hKey : HKEY -> "void*"
# lpSubKey : LPCWSTR optional -> "char*"
# lpNewFile : LPCWSTR -> "char*"
# lpOldFile : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。