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