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

RegSaveKeyExA

関数
形式を指定して指定キーをファイルに保存する。
DLLADVAPI32.dll文字セットANSI (-A)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

WIN32_ERROR RegSaveKeyExA(
    HKEY hKey,
    LPCSTR lpFile,
    const SECURITY_ATTRIBUTES* lpSecurityAttributes,   // optional
    REG_SAVE_FORMAT Flags
);

パラメーター

名前方向
hKeyHKEYin
lpFileLPCSTRin
lpSecurityAttributesSECURITY_ATTRIBUTES*inoptional
FlagsREG_SAVE_FORMATin

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

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

RegSaveKeyExA = ctypes.windll.advapi32.RegSaveKeyExA
RegSaveKeyExA.restype = wintypes.DWORD
RegSaveKeyExA.argtypes = [
    wintypes.HANDLE,  # hKey : HKEY
    wintypes.LPCSTR,  # lpFile : LPCSTR
    ctypes.c_void_p,  # lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
    wintypes.DWORD,  # Flags : REG_SAVE_FORMAT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
RegSaveKeyExA = Fiddle::Function.new(
  lib['RegSaveKeyExA'],
  [
    Fiddle::TYPE_VOIDP,  # hKey : HKEY
    Fiddle::TYPE_VOIDP,  # lpFile : LPCSTR
    Fiddle::TYPE_VOIDP,  # lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
    -Fiddle::TYPE_INT,  # Flags : REG_SAVE_FORMAT
  ],
  -Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn RegSaveKeyExA(
        hKey: *mut core::ffi::c_void,  // HKEY
        lpFile: *const u8,  // LPCSTR
        lpSecurityAttributes: *const SECURITY_ATTRIBUTES,  // SECURITY_ATTRIBUTES* optional
        Flags: u32  // REG_SAVE_FORMAT
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi)]
public static extern uint RegSaveKeyExA(IntPtr hKey, [MarshalAs(UnmanagedType.LPStr)] string lpFile, IntPtr lpSecurityAttributes, uint Flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_RegSaveKeyExA' -Namespace Win32 -PassThru
# $api::RegSaveKeyExA(hKey, lpFile, lpSecurityAttributes, Flags)
#uselib "ADVAPI32.dll"
#func global RegSaveKeyExA "RegSaveKeyExA" sptr, sptr, sptr, sptr
; RegSaveKeyExA hKey, lpFile, varptr(lpSecurityAttributes), Flags   ; 戻り値は stat
; hKey : HKEY -> "sptr"
; lpFile : LPCSTR -> "sptr"
; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "sptr"
; Flags : REG_SAVE_FORMAT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global RegSaveKeyExA "RegSaveKeyExA" sptr, str, var, int
; res = RegSaveKeyExA(hKey, lpFile, lpSecurityAttributes, Flags)
; hKey : HKEY -> "sptr"
; lpFile : LPCSTR -> "str"
; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "var"
; Flags : REG_SAVE_FORMAT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WIN32_ERROR RegSaveKeyExA(HKEY hKey, LPCSTR lpFile, SECURITY_ATTRIBUTES* lpSecurityAttributes, REG_SAVE_FORMAT Flags)
#uselib "ADVAPI32.dll"
#cfunc global RegSaveKeyExA "RegSaveKeyExA" intptr, str, var, int
; res = RegSaveKeyExA(hKey, lpFile, lpSecurityAttributes, Flags)
; hKey : HKEY -> "intptr"
; lpFile : LPCSTR -> "str"
; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "var"
; Flags : REG_SAVE_FORMAT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procRegSaveKeyExA = advapi32.NewProc("RegSaveKeyExA")
)

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