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

RegSaveKeyW

関数
指定キーとサブキーをファイルに保存する。
DLLADVAPI32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// ADVAPI32.dll  (Unicode / -W)
#include <windows.h>

WIN32_ERROR RegSaveKeyW(
    HKEY hKey,
    LPCWSTR lpFile,
    const SECURITY_ATTRIBUTES* lpSecurityAttributes   // optional
);

パラメーター

名前方向
hKeyHKEYin
lpFileLPCWSTRin
lpSecurityAttributesSECURITY_ATTRIBUTES*inoptional

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

// ADVAPI32.dll  (Unicode / -W)
#include <windows.h>

WIN32_ERROR RegSaveKeyW(
    HKEY hKey,
    LPCWSTR lpFile,
    const SECURITY_ATTRIBUTES* lpSecurityAttributes   // optional
);
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint RegSaveKeyW(
    IntPtr hKey,   // HKEY
    [MarshalAs(UnmanagedType.LPWStr)] string lpFile,   // LPCWSTR
    IntPtr lpSecurityAttributes   // SECURITY_ATTRIBUTES* optional
);
<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RegSaveKeyW(
    hKey As IntPtr,   ' HKEY
    <MarshalAs(UnmanagedType.LPWStr)> lpFile As String,   ' LPCWSTR
    lpSecurityAttributes As IntPtr   ' SECURITY_ATTRIBUTES* optional
) As UInteger
End Function
' hKey : HKEY
' lpFile : LPCWSTR
' lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
Declare PtrSafe Function RegSaveKeyW Lib "advapi32" ( _
    ByVal hKey As LongPtr, _
    ByVal lpFile As LongPtr, _
    ByVal lpSecurityAttributes 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

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

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

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procRegSaveKeyW = advapi32.NewProc("RegSaveKeyW")
)

// hKey (HKEY), lpFile (LPCWSTR), lpSecurityAttributes (SECURITY_ATTRIBUTES* optional)
r1, _, err := procRegSaveKeyW.Call(
	uintptr(hKey),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpFile))),
	uintptr(lpSecurityAttributes),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function RegSaveKeyW(
  hKey: THandle;   // HKEY
  lpFile: PWideChar;   // LPCWSTR
  lpSecurityAttributes: Pointer   // SECURITY_ATTRIBUTES* optional
): DWORD; stdcall;
  external 'ADVAPI32.dll' name 'RegSaveKeyW';
result := DllCall("ADVAPI32\RegSaveKeyW"
    , "Ptr", hKey   ; HKEY
    , "WStr", lpFile   ; LPCWSTR
    , "Ptr", lpSecurityAttributes   ; SECURITY_ATTRIBUTES* optional
    , "UInt")   ; return: WIN32_ERROR
●RegSaveKeyW(hKey, lpFile, lpSecurityAttributes) = DLL("ADVAPI32.dll", "dword RegSaveKeyW(void*, char*, void*)")
# 呼び出し: RegSaveKeyW(hKey, lpFile, lpSecurityAttributes)
# hKey : HKEY -> "void*"
# lpFile : LPCWSTR -> "char*"
# lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。