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

RegConnectRegistryExW

関数
フラグ指定でリモートのレジストリキーに接続する。
DLLADVAPI32.dll文字セットUnicode (-W)呼出規約winapi

シグネチャ

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

INT RegConnectRegistryExW(
    LPCWSTR lpMachineName,   // optional
    HKEY hKey,
    DWORD Flags,
    HKEY* phkResult
);

パラメーター

名前方向
lpMachineNameLPCWSTRinoptional
hKeyHKEYin
FlagsDWORDin
phkResultHKEY*out

戻り値の型: INT

各言語での呼び出し定義

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

INT RegConnectRegistryExW(
    LPCWSTR lpMachineName,   // optional
    HKEY hKey,
    DWORD Flags,
    HKEY* phkResult
);
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int RegConnectRegistryExW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpMachineName,   // LPCWSTR optional
    IntPtr hKey,   // HKEY
    uint Flags,   // DWORD
    IntPtr phkResult   // HKEY* out
);
<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RegConnectRegistryExW(
    <MarshalAs(UnmanagedType.LPWStr)> lpMachineName As String,   ' LPCWSTR optional
    hKey As IntPtr,   ' HKEY
    Flags As UInteger,   ' DWORD
    phkResult As IntPtr   ' HKEY* out
) As Integer
End Function
' lpMachineName : LPCWSTR optional
' hKey : HKEY
' Flags : DWORD
' phkResult : HKEY* out
Declare PtrSafe Function RegConnectRegistryExW Lib "advapi32" ( _
    ByVal lpMachineName As LongPtr, _
    ByVal hKey As LongPtr, _
    ByVal Flags As Long, _
    ByVal phkResult 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

RegConnectRegistryExW = ctypes.windll.advapi32.RegConnectRegistryExW
RegConnectRegistryExW.restype = ctypes.c_int
RegConnectRegistryExW.argtypes = [
    wintypes.LPCWSTR,  # lpMachineName : LPCWSTR optional
    wintypes.HANDLE,  # hKey : HKEY
    wintypes.DWORD,  # Flags : DWORD
    ctypes.c_void_p,  # phkResult : HKEY* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procRegConnectRegistryExW = advapi32.NewProc("RegConnectRegistryExW")
)

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