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