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

RegConnectRegistryA

関数
リモートコンピューターの定義済みレジストリキーに接続する。
DLLADVAPI32.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

WIN32_ERROR RegConnectRegistryA(
    LPCSTR lpMachineName,   // optional
    HKEY hKey,
    HKEY* phkResult
);

パラメーター

名前方向説明
lpMachineNameLPCSTRinoptional接続先リモートコンピュータ名(ANSI文字列)。NULLでローカルコンピュータを指す。
hKeyHKEYinリモートで開く事前定義キー。HKEY_LOCAL_MACHINEまたはHKEY_USERSのみ可。
phkResultHKEY*out開いたリモートキーのハンドルを受け取るHKEYへのポインタ。出力。

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

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

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

lib = Fiddle.dlopen('ADVAPI32.dll')
RegConnectRegistryA = Fiddle::Function.new(
  lib['RegConnectRegistryA'],
  [
    Fiddle::TYPE_VOIDP,  # lpMachineName : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # hKey : HKEY
    Fiddle::TYPE_VOIDP,  # phkResult : HKEY* out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn RegConnectRegistryA(
        lpMachineName: *const u8,  // LPCSTR optional
        hKey: *mut core::ffi::c_void,  // HKEY
        phkResult: *mut *mut core::ffi::c_void  // HKEY* out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi)]
public static extern uint RegConnectRegistryA([MarshalAs(UnmanagedType.LPStr)] string lpMachineName, IntPtr hKey, IntPtr phkResult);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_RegConnectRegistryA' -Namespace Win32 -PassThru
# $api::RegConnectRegistryA(lpMachineName, hKey, phkResult)
#uselib "ADVAPI32.dll"
#func global RegConnectRegistryA "RegConnectRegistryA" sptr, sptr, sptr
; RegConnectRegistryA lpMachineName, hKey, phkResult   ; 戻り値は stat
; lpMachineName : LPCSTR optional -> "sptr"
; hKey : HKEY -> "sptr"
; phkResult : HKEY* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ADVAPI32.dll"
#cfunc global RegConnectRegistryA "RegConnectRegistryA" str, sptr, sptr
; res = RegConnectRegistryA(lpMachineName, hKey, phkResult)
; lpMachineName : LPCSTR optional -> "str"
; hKey : HKEY -> "sptr"
; phkResult : HKEY* out -> "sptr"
; WIN32_ERROR RegConnectRegistryA(LPCSTR lpMachineName, HKEY hKey, HKEY* phkResult)
#uselib "ADVAPI32.dll"
#cfunc global RegConnectRegistryA "RegConnectRegistryA" str, intptr, intptr
; res = RegConnectRegistryA(lpMachineName, hKey, phkResult)
; lpMachineName : LPCSTR optional -> "str"
; hKey : HKEY -> "intptr"
; phkResult : HKEY* out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procRegConnectRegistryA = advapi32.NewProc("RegConnectRegistryA")
)

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