Win32 API 日本語リファレンス
ホームNetworkManagement.P2P › PeerGroupOpenDirectConnection

PeerGroupOpenDirectConnection

関数
グループ内メンバーへの直接接続を開く。
DLLP2P.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

// P2P.dll
#include <windows.h>

HRESULT PeerGroupOpenDirectConnection(
    void* hGroup,
    LPCWSTR pwzIdentity,
    PEER_ADDRESS* pAddress,
    ULONGLONG* pullConnectionId
);

パラメーター

名前方向
hGroupvoid*in
pwzIdentityLPCWSTRin
pAddressPEER_ADDRESS*in
pullConnectionIdULONGLONG*out

戻り値の型: HRESULT

各言語での呼び出し定義

// P2P.dll
#include <windows.h>

HRESULT PeerGroupOpenDirectConnection(
    void* hGroup,
    LPCWSTR pwzIdentity,
    PEER_ADDRESS* pAddress,
    ULONGLONG* pullConnectionId
);
[DllImport("P2P.dll", ExactSpelling = true)]
static extern int PeerGroupOpenDirectConnection(
    IntPtr hGroup,   // void*
    [MarshalAs(UnmanagedType.LPWStr)] string pwzIdentity,   // LPCWSTR
    IntPtr pAddress,   // PEER_ADDRESS*
    out ulong pullConnectionId   // ULONGLONG* out
);
<DllImport("P2P.dll", ExactSpelling:=True)>
Public Shared Function PeerGroupOpenDirectConnection(
    hGroup As IntPtr,   ' void*
    <MarshalAs(UnmanagedType.LPWStr)> pwzIdentity As String,   ' LPCWSTR
    pAddress As IntPtr,   ' PEER_ADDRESS*
    <Out> ByRef pullConnectionId As ULong   ' ULONGLONG* out
) As Integer
End Function
' hGroup : void*
' pwzIdentity : LPCWSTR
' pAddress : PEER_ADDRESS*
' pullConnectionId : ULONGLONG* out
Declare PtrSafe Function PeerGroupOpenDirectConnection Lib "p2p" ( _
    ByVal hGroup As LongPtr, _
    ByVal pwzIdentity As LongPtr, _
    ByVal pAddress As LongPtr, _
    ByRef pullConnectionId As LongLong) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PeerGroupOpenDirectConnection = ctypes.windll.p2p.PeerGroupOpenDirectConnection
PeerGroupOpenDirectConnection.restype = ctypes.c_int
PeerGroupOpenDirectConnection.argtypes = [
    ctypes.POINTER(None),  # hGroup : void*
    wintypes.LPCWSTR,  # pwzIdentity : LPCWSTR
    ctypes.c_void_p,  # pAddress : PEER_ADDRESS*
    ctypes.POINTER(ctypes.c_ulonglong),  # pullConnectionId : ULONGLONG* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('P2P.dll')
PeerGroupOpenDirectConnection = Fiddle::Function.new(
  lib['PeerGroupOpenDirectConnection'],
  [
    Fiddle::TYPE_VOIDP,  # hGroup : void*
    Fiddle::TYPE_VOIDP,  # pwzIdentity : LPCWSTR
    Fiddle::TYPE_VOIDP,  # pAddress : PEER_ADDRESS*
    Fiddle::TYPE_VOIDP,  # pullConnectionId : ULONGLONG* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "p2p")]
extern "system" {
    fn PeerGroupOpenDirectConnection(
        hGroup: *mut (),  // void*
        pwzIdentity: *const u16,  // LPCWSTR
        pAddress: *mut PEER_ADDRESS,  // PEER_ADDRESS*
        pullConnectionId: *mut u64  // ULONGLONG* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("P2P.dll")]
public static extern int PeerGroupOpenDirectConnection(IntPtr hGroup, [MarshalAs(UnmanagedType.LPWStr)] string pwzIdentity, IntPtr pAddress, out ulong pullConnectionId);
"@
$api = Add-Type -MemberDefinition $sig -Name 'P2P_PeerGroupOpenDirectConnection' -Namespace Win32 -PassThru
# $api::PeerGroupOpenDirectConnection(hGroup, pwzIdentity, pAddress, pullConnectionId)
#uselib "P2P.dll"
#func global PeerGroupOpenDirectConnection "PeerGroupOpenDirectConnection" sptr, sptr, sptr, sptr
; PeerGroupOpenDirectConnection hGroup, pwzIdentity, varptr(pAddress), varptr(pullConnectionId)   ; 戻り値は stat
; hGroup : void* -> "sptr"
; pwzIdentity : LPCWSTR -> "sptr"
; pAddress : PEER_ADDRESS* -> "sptr"
; pullConnectionId : ULONGLONG* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "P2P.dll"
#cfunc global PeerGroupOpenDirectConnection "PeerGroupOpenDirectConnection" sptr, wstr, var, var
; res = PeerGroupOpenDirectConnection(hGroup, pwzIdentity, pAddress, pullConnectionId)
; hGroup : void* -> "sptr"
; pwzIdentity : LPCWSTR -> "wstr"
; pAddress : PEER_ADDRESS* -> "var"
; pullConnectionId : ULONGLONG* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT PeerGroupOpenDirectConnection(void* hGroup, LPCWSTR pwzIdentity, PEER_ADDRESS* pAddress, ULONGLONG* pullConnectionId)
#uselib "P2P.dll"
#cfunc global PeerGroupOpenDirectConnection "PeerGroupOpenDirectConnection" intptr, wstr, var, var
; res = PeerGroupOpenDirectConnection(hGroup, pwzIdentity, pAddress, pullConnectionId)
; hGroup : void* -> "intptr"
; pwzIdentity : LPCWSTR -> "wstr"
; pAddress : PEER_ADDRESS* -> "var"
; pullConnectionId : ULONGLONG* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	p2p = windows.NewLazySystemDLL("P2P.dll")
	procPeerGroupOpenDirectConnection = p2p.NewProc("PeerGroupOpenDirectConnection")
)

// hGroup (void*), pwzIdentity (LPCWSTR), pAddress (PEER_ADDRESS*), pullConnectionId (ULONGLONG* out)
r1, _, err := procPeerGroupOpenDirectConnection.Call(
	uintptr(hGroup),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwzIdentity))),
	uintptr(pAddress),
	uintptr(pullConnectionId),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function PeerGroupOpenDirectConnection(
  hGroup: Pointer;   // void*
  pwzIdentity: PWideChar;   // LPCWSTR
  pAddress: Pointer;   // PEER_ADDRESS*
  pullConnectionId: Pointer   // ULONGLONG* out
): Integer; stdcall;
  external 'P2P.dll' name 'PeerGroupOpenDirectConnection';
result := DllCall("P2P\PeerGroupOpenDirectConnection"
    , "Ptr", hGroup   ; void*
    , "WStr", pwzIdentity   ; LPCWSTR
    , "Ptr", pAddress   ; PEER_ADDRESS*
    , "Ptr", pullConnectionId   ; ULONGLONG* out
    , "Int")   ; return: HRESULT
●PeerGroupOpenDirectConnection(hGroup, pwzIdentity, pAddress, pullConnectionId) = DLL("P2P.dll", "int PeerGroupOpenDirectConnection(void*, char*, void*, void*)")
# 呼び出し: PeerGroupOpenDirectConnection(hGroup, pwzIdentity, pAddress, pullConnectionId)
# hGroup : void* -> "void*"
# pwzIdentity : LPCWSTR -> "char*"
# pAddress : PEER_ADDRESS* -> "void*"
# pullConnectionId : ULONGLONG* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。