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

RegConnectRegistryExA

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

シグネチャ

// ADVAPI32.dll  (ANSI / -A)
#include <windows.h>

INT RegConnectRegistryExA(
    LPCSTR lpMachineName,   // optional
    HKEY hKey,
    DWORD Flags,
    HKEY* phkResult
);

パラメーター

名前方向
lpMachineNameLPCSTRinoptional
hKeyHKEYin
FlagsDWORDin
phkResultHKEY*out

戻り値の型: INT

各言語での呼び出し定義

// ADVAPI32.dll  (ANSI / -A)
#include <windows.h>

INT RegConnectRegistryExA(
    LPCSTR lpMachineName,   // optional
    HKEY hKey,
    DWORD Flags,
    HKEY* phkResult
);
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern int RegConnectRegistryExA(
    [MarshalAs(UnmanagedType.LPStr)] string lpMachineName,   // LPCSTR optional
    IntPtr hKey,   // HKEY
    uint Flags,   // DWORD
    IntPtr phkResult   // HKEY* out
);
<DllImport("ADVAPI32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function RegConnectRegistryExA(
    <MarshalAs(UnmanagedType.LPStr)> lpMachineName As String,   ' LPCSTR optional
    hKey As IntPtr,   ' HKEY
    Flags As UInteger,   ' DWORD
    phkResult As IntPtr   ' HKEY* out
) As Integer
End Function
' lpMachineName : LPCSTR optional
' hKey : HKEY
' Flags : DWORD
' phkResult : HKEY* out
Declare PtrSafe Function RegConnectRegistryExA Lib "advapi32" ( _
    ByVal lpMachineName As String, _
    ByVal hKey As LongPtr, _
    ByVal Flags As Long, _
    ByVal phkResult As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RegConnectRegistryExA = ctypes.windll.advapi32.RegConnectRegistryExA
RegConnectRegistryExA.restype = ctypes.c_int
RegConnectRegistryExA.argtypes = [
    wintypes.LPCSTR,  # lpMachineName : LPCSTR 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')
RegConnectRegistryExA = Fiddle::Function.new(
  lib['RegConnectRegistryExA'],
  [
    Fiddle::TYPE_VOIDP,  # lpMachineName : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # hKey : HKEY
    -Fiddle::TYPE_INT,  # Flags : DWORD
    Fiddle::TYPE_VOIDP,  # phkResult : HKEY* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn RegConnectRegistryExA(
        lpMachineName: *const u8,  // LPCSTR 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.Ansi)]
public static extern int RegConnectRegistryExA([MarshalAs(UnmanagedType.LPStr)] string lpMachineName, IntPtr hKey, uint Flags, IntPtr phkResult);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_RegConnectRegistryExA' -Namespace Win32 -PassThru
# $api::RegConnectRegistryExA(lpMachineName, hKey, Flags, phkResult)
#uselib "ADVAPI32.dll"
#func global RegConnectRegistryExA "RegConnectRegistryExA" sptr, sptr, sptr, sptr
; RegConnectRegistryExA lpMachineName, hKey, Flags, phkResult   ; 戻り値は stat
; lpMachineName : LPCSTR optional -> "sptr"
; hKey : HKEY -> "sptr"
; Flags : DWORD -> "sptr"
; phkResult : HKEY* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ADVAPI32.dll"
#cfunc global RegConnectRegistryExA "RegConnectRegistryExA" str, sptr, int, sptr
; res = RegConnectRegistryExA(lpMachineName, hKey, Flags, phkResult)
; lpMachineName : LPCSTR optional -> "str"
; hKey : HKEY -> "sptr"
; Flags : DWORD -> "int"
; phkResult : HKEY* out -> "sptr"
; INT RegConnectRegistryExA(LPCSTR lpMachineName, HKEY hKey, DWORD Flags, HKEY* phkResult)
#uselib "ADVAPI32.dll"
#cfunc global RegConnectRegistryExA "RegConnectRegistryExA" str, intptr, int, intptr
; res = RegConnectRegistryExA(lpMachineName, hKey, Flags, phkResult)
; lpMachineName : LPCSTR optional -> "str"
; hKey : HKEY -> "intptr"
; Flags : DWORD -> "int"
; phkResult : HKEY* out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procRegConnectRegistryExA = advapi32.NewProc("RegConnectRegistryExA")
)

// lpMachineName (LPCSTR optional), hKey (HKEY), Flags (DWORD), phkResult (HKEY* out)
r1, _, err := procRegConnectRegistryExA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpMachineName))),
	uintptr(hKey),
	uintptr(Flags),
	uintptr(phkResult),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function RegConnectRegistryExA(
  lpMachineName: PAnsiChar;   // LPCSTR optional
  hKey: THandle;   // HKEY
  Flags: DWORD;   // DWORD
  phkResult: Pointer   // HKEY* out
): Integer; stdcall;
  external 'ADVAPI32.dll' name 'RegConnectRegistryExA';
result := DllCall("ADVAPI32\RegConnectRegistryExA"
    , "AStr", lpMachineName   ; LPCSTR optional
    , "Ptr", hKey   ; HKEY
    , "UInt", Flags   ; DWORD
    , "Ptr", phkResult   ; HKEY* out
    , "Int")   ; return: INT
●RegConnectRegistryExA(lpMachineName, hKey, Flags, phkResult) = DLL("ADVAPI32.dll", "int RegConnectRegistryExA(char*, void*, dword, void*)")
# 呼び出し: RegConnectRegistryExA(lpMachineName, hKey, Flags, phkResult)
# lpMachineName : LPCSTR optional -> "char*"
# hKey : HKEY -> "void*"
# Flags : DWORD -> "dword"
# phkResult : HKEY* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。