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