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

RegLoadKeyW

関数
ハイブファイルをレジストリのサブキーとして読み込む。
DLLADVAPI32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

WIN32_ERROR RegLoadKeyW(
    HKEY hKey,
    LPCWSTR lpSubKey,   // optional
    LPCWSTR lpFile
);

パラメーター

名前方向
hKeyHKEYin
lpSubKeyLPCWSTRinoptional
lpFileLPCWSTRin

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

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

RegLoadKeyW = ctypes.windll.advapi32.RegLoadKeyW
RegLoadKeyW.restype = wintypes.DWORD
RegLoadKeyW.argtypes = [
    wintypes.HANDLE,  # hKey : HKEY
    wintypes.LPCWSTR,  # lpSubKey : LPCWSTR optional
    wintypes.LPCWSTR,  # lpFile : LPCWSTR
]
require 'fiddle'
require 'fiddle/import'

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

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procRegLoadKeyW = advapi32.NewProc("RegLoadKeyW")
)

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