ホーム › System.Registry › RegConnectRegistryExW
RegConnectRegistryExW
関数フラグ指定でリモートのレジストリキーに接続する。
シグネチャ
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
INT RegConnectRegistryExW(
LPCWSTR lpMachineName, // optional
HKEY hKey,
DWORD Flags,
HKEY* phkResult
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpMachineName | LPCWSTR | inoptional | 接続先リモートコンピュータ名(ワイド文字列)。NULLでローカルコンピュータを指す。 |
| hKey | HKEY | in | リモートで開く事前定義キー。HKEY_LOCAL_MACHINEまたはHKEY_USERSのみ可。 |
| Flags | DWORD | in | 接続時のオプションを示すフラグ。レジストリビュー(32/64ビット)選択等に用いる。 |
| phkResult | HKEY* | out | 開いたリモートキーのハンドルを受け取るHKEYへのポインタ。出力。 |
戻り値の型: 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 // INTfunction 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 版の利用を推奨。const std = @import("std");
extern "advapi32" fn RegConnectRegistryExW(
lpMachineName: [*c]const u16, // LPCWSTR optional
hKey: ?*anyopaque, // HKEY
Flags: u32, // DWORD
phkResult: ?*anyopaque // HKEY* out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc RegConnectRegistryExW(
lpMachineName: WideCString, # LPCWSTR optional
hKey: pointer, # HKEY
Flags: uint32, # DWORD
phkResult: pointer # HKEY* out
): int32 {.importc: "RegConnectRegistryExW", stdcall, dynlib: "ADVAPI32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "advapi32");
extern(Windows)
int RegConnectRegistryExW(
const(wchar)* lpMachineName, // LPCWSTR optional
void* hKey, // HKEY
uint Flags, // DWORD
void* phkResult // HKEY* out
);ccall((:RegConnectRegistryExW, "ADVAPI32.dll"), stdcall, Int32,
(Cwstring, Ptr{Cvoid}, UInt32, Ptr{Cvoid}),
lpMachineName, hKey, Flags, phkResult)
# lpMachineName : LPCWSTR optional -> Cwstring
# hKey : HKEY -> Ptr{Cvoid}
# Flags : DWORD -> UInt32
# phkResult : HKEY* out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t RegConnectRegistryExW(
const uint16_t* lpMachineName,
void* hKey,
uint32_t Flags,
void* phkResult);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.RegConnectRegistryExW(lpMachineName, hKey, Flags, phkResult)
-- lpMachineName : LPCWSTR optional
-- hKey : HKEY
-- Flags : DWORD
-- phkResult : HKEY* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const RegConnectRegistryExW = lib.func('__stdcall', 'RegConnectRegistryExW', 'int32_t', ['str16', 'void *', 'uint32_t', 'void *']);
// RegConnectRegistryExW(lpMachineName, hKey, Flags, phkResult)
// lpMachineName : LPCWSTR optional -> 'str16'
// hKey : HKEY -> 'void *'
// Flags : DWORD -> 'uint32_t'
// phkResult : HKEY* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
RegConnectRegistryExW: { parameters: ["buffer", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.RegConnectRegistryExW(lpMachineName, hKey, Flags, phkResult)
// lpMachineName : LPCWSTR optional -> "buffer"
// hKey : HKEY -> "pointer"
// Flags : DWORD -> "u32"
// phkResult : HKEY* out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t RegConnectRegistryExW(
const uint16_t* lpMachineName,
void* hKey,
uint32_t Flags,
void* phkResult);
C, "ADVAPI32.dll");
// $ffi->RegConnectRegistryExW(lpMachineName, hKey, Flags, phkResult);
// lpMachineName : LPCWSTR optional
// hKey : HKEY
// Flags : DWORD
// phkResult : HKEY* out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Advapi32 extends StdCallLibrary {
Advapi32 INSTANCE = Native.load("advapi32", Advapi32.class, W32APIOptions.UNICODE_OPTIONS);
int RegConnectRegistryExW(
WString lpMachineName, // LPCWSTR optional
Pointer hKey, // HKEY
int Flags, // DWORD
Pointer phkResult // HKEY* out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("advapi32")]
lib LibADVAPI32
fun RegConnectRegistryExW = RegConnectRegistryExW(
lpMachineName : UInt16*, # LPCWSTR optional
hKey : Void*, # HKEY
Flags : UInt32, # DWORD
phkResult : Void* # HKEY* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef RegConnectRegistryExWNative = Int32 Function(Pointer<Utf16>, Pointer<Void>, Uint32, Pointer<Void>);
typedef RegConnectRegistryExWDart = int Function(Pointer<Utf16>, Pointer<Void>, int, Pointer<Void>);
final RegConnectRegistryExW = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<RegConnectRegistryExWNative, RegConnectRegistryExWDart>('RegConnectRegistryExW');
// lpMachineName : LPCWSTR optional -> Pointer<Utf16>
// hKey : HKEY -> Pointer<Void>
// Flags : DWORD -> Uint32
// phkResult : HKEY* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function RegConnectRegistryExW(
lpMachineName: PWideChar; // LPCWSTR optional
hKey: THandle; // HKEY
Flags: DWORD; // DWORD
phkResult: Pointer // HKEY* out
): Integer; stdcall;
external 'ADVAPI32.dll' name 'RegConnectRegistryExW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "RegConnectRegistryExW"
c_RegConnectRegistryExW :: CWString -> Ptr () -> Word32 -> Ptr () -> IO Int32
-- lpMachineName : LPCWSTR optional -> CWString
-- hKey : HKEY -> Ptr ()
-- Flags : DWORD -> Word32
-- phkResult : HKEY* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let regconnectregistryexw =
foreign "RegConnectRegistryExW"
((ptr uint16_t) @-> (ptr void) @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* lpMachineName : LPCWSTR optional -> (ptr uint16_t) *)
(* hKey : HKEY -> (ptr void) *)
(* Flags : DWORD -> uint32_t *)
(* phkResult : HKEY* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)
(cffi:defcfun ("RegConnectRegistryExW" reg-connect-registry-ex-w :convention :stdcall) :int32
(lp-machine-name (:string :encoding :utf-16le)) ; LPCWSTR optional
(h-key :pointer) ; HKEY
(flags :uint32) ; DWORD
(phk-result :pointer)) ; HKEY* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $RegConnectRegistryExW = Win32::API::More->new('ADVAPI32',
'int RegConnectRegistryExW(LPCWSTR lpMachineName, HANDLE hKey, DWORD Flags, HANDLE phkResult)');
# my $ret = $RegConnectRegistryExW->Call($lpMachineName, $hKey, $Flags, $phkResult);
# lpMachineName : LPCWSTR optional -> LPCWSTR
# hKey : HKEY -> HANDLE
# Flags : DWORD -> DWORD
# phkResult : HKEY* out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f RegConnectRegistryExA (ANSI版) — フラグ指定でリモートのレジストリキーに接続する。
類似 API
- f RegConnectRegistryW — リモートコンピューターの定義済みレジストリキーに接続する。