ホーム › NetworkManagement.P2P › PeerGroupOpenDirectConnection
PeerGroupOpenDirectConnection
関数グループ内メンバーへの直接接続を開く。
シグネチャ
// P2P.dll
#include <windows.h>
HRESULT PeerGroupOpenDirectConnection(
void* hGroup,
LPCWSTR pwzIdentity,
PEER_ADDRESS* pAddress,
ULONGLONG* pullConnectionId
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hGroup | void* | in | 直接接続を開く対象のグループを表すハンドル。 |
| pwzIdentity | LPCWSTR | in | 接続先メンバーの識別子を示すUnicode文字列へのポインター。 |
| pAddress | PEER_ADDRESS* | in | 接続先のネットワークアドレスを格納したPEER_ADDRESS構造体へのポインター。 |
| pullConnectionId | ULONGLONG* | out | 確立された接続を識別する接続IDを受け取るULONGLONGへの出力ポインター。 |
戻り値の型: 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 方式にも切替可。#uselib "P2P.dll" #cfunc global PeerGroupOpenDirectConnection "PeerGroupOpenDirectConnection" sptr, wstr, sptr, sptr ; res = PeerGroupOpenDirectConnection(hGroup, pwzIdentity, varptr(pAddress), varptr(pullConnectionId)) ; hGroup : void* -> "sptr" ; pwzIdentity : LPCWSTR -> "wstr" ; pAddress : PEER_ADDRESS* -> "sptr" ; pullConnectionId : ULONGLONG* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; HRESULT PeerGroupOpenDirectConnection(void* hGroup, LPCWSTR pwzIdentity, PEER_ADDRESS* pAddress, ULONGLONG* pullConnectionId) #uselib "P2P.dll" #cfunc global PeerGroupOpenDirectConnection "PeerGroupOpenDirectConnection" intptr, wstr, intptr, intptr ; res = PeerGroupOpenDirectConnection(hGroup, pwzIdentity, varptr(pAddress), varptr(pullConnectionId)) ; hGroup : void* -> "intptr" ; pwzIdentity : LPCWSTR -> "wstr" ; pAddress : PEER_ADDRESS* -> "intptr" ; pullConnectionId : ULONGLONG* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // HRESULTfunction 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)。const std = @import("std");
extern "p2p" fn PeerGroupOpenDirectConnection(
hGroup: ?*anyopaque, // void*
pwzIdentity: [*c]const u16, // LPCWSTR
pAddress: [*c]PEER_ADDRESS, // PEER_ADDRESS*
pullConnectionId: [*c]u64 // ULONGLONG* out
) callconv(std.os.windows.WINAPI) i32;proc PeerGroupOpenDirectConnection(
hGroup: pointer, # void*
pwzIdentity: WideCString, # LPCWSTR
pAddress: ptr PEER_ADDRESS, # PEER_ADDRESS*
pullConnectionId: ptr uint64 # ULONGLONG* out
): int32 {.importc: "PeerGroupOpenDirectConnection", stdcall, dynlib: "P2P.dll".}pragma(lib, "p2p");
extern(Windows)
int PeerGroupOpenDirectConnection(
void* hGroup, // void*
const(wchar)* pwzIdentity, // LPCWSTR
PEER_ADDRESS* pAddress, // PEER_ADDRESS*
ulong* pullConnectionId // ULONGLONG* out
);ccall((:PeerGroupOpenDirectConnection, "P2P.dll"), stdcall, Int32,
(Ptr{Cvoid}, Cwstring, Ptr{PEER_ADDRESS}, Ptr{UInt64}),
hGroup, pwzIdentity, pAddress, pullConnectionId)
# hGroup : void* -> Ptr{Cvoid}
# pwzIdentity : LPCWSTR -> Cwstring
# pAddress : PEER_ADDRESS* -> Ptr{PEER_ADDRESS}
# pullConnectionId : ULONGLONG* out -> Ptr{UInt64}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t PeerGroupOpenDirectConnection(
void* hGroup,
const uint16_t* pwzIdentity,
void* pAddress,
uint64_t* pullConnectionId);
]]
local p2p = ffi.load("p2p")
-- p2p.PeerGroupOpenDirectConnection(hGroup, pwzIdentity, pAddress, pullConnectionId)
-- hGroup : void*
-- pwzIdentity : LPCWSTR
-- pAddress : PEER_ADDRESS*
-- pullConnectionId : ULONGLONG* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('P2P.dll');
const PeerGroupOpenDirectConnection = lib.func('__stdcall', 'PeerGroupOpenDirectConnection', 'int32_t', ['void *', 'str16', 'void *', 'uint64_t *']);
// PeerGroupOpenDirectConnection(hGroup, pwzIdentity, pAddress, pullConnectionId)
// hGroup : void* -> 'void *'
// pwzIdentity : LPCWSTR -> 'str16'
// pAddress : PEER_ADDRESS* -> 'void *'
// pullConnectionId : ULONGLONG* out -> 'uint64_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("P2P.dll", {
PeerGroupOpenDirectConnection: { parameters: ["pointer", "buffer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.PeerGroupOpenDirectConnection(hGroup, pwzIdentity, pAddress, pullConnectionId)
// hGroup : void* -> "pointer"
// pwzIdentity : LPCWSTR -> "buffer"
// pAddress : PEER_ADDRESS* -> "pointer"
// pullConnectionId : ULONGLONG* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t PeerGroupOpenDirectConnection(
void* hGroup,
const uint16_t* pwzIdentity,
void* pAddress,
uint64_t* pullConnectionId);
C, "P2P.dll");
// $ffi->PeerGroupOpenDirectConnection(hGroup, pwzIdentity, pAddress, pullConnectionId);
// hGroup : void*
// pwzIdentity : LPCWSTR
// pAddress : PEER_ADDRESS*
// pullConnectionId : ULONGLONG* 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 P2p extends StdCallLibrary {
P2p INSTANCE = Native.load("p2p", P2p.class);
int PeerGroupOpenDirectConnection(
Pointer hGroup, // void*
WString pwzIdentity, // LPCWSTR
Pointer pAddress, // PEER_ADDRESS*
LongByReference pullConnectionId // ULONGLONG* out
);
}@[Link("p2p")]
lib LibP2P
fun PeerGroupOpenDirectConnection = PeerGroupOpenDirectConnection(
hGroup : Void*, # void*
pwzIdentity : UInt16*, # LPCWSTR
pAddress : PEER_ADDRESS*, # PEER_ADDRESS*
pullConnectionId : UInt64* # ULONGLONG* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PeerGroupOpenDirectConnectionNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Void>, Pointer<Uint64>);
typedef PeerGroupOpenDirectConnectionDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Void>, Pointer<Uint64>);
final PeerGroupOpenDirectConnection = DynamicLibrary.open('P2P.dll')
.lookupFunction<PeerGroupOpenDirectConnectionNative, PeerGroupOpenDirectConnectionDart>('PeerGroupOpenDirectConnection');
// hGroup : void* -> Pointer<Void>
// pwzIdentity : LPCWSTR -> Pointer<Utf16>
// pAddress : PEER_ADDRESS* -> Pointer<Void>
// pullConnectionId : ULONGLONG* out -> Pointer<Uint64>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PeerGroupOpenDirectConnection(
hGroup: Pointer; // void*
pwzIdentity: PWideChar; // LPCWSTR
pAddress: Pointer; // PEER_ADDRESS*
pullConnectionId: Pointer // ULONGLONG* out
): Integer; stdcall;
external 'P2P.dll' name 'PeerGroupOpenDirectConnection';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PeerGroupOpenDirectConnection"
c_PeerGroupOpenDirectConnection :: Ptr () -> CWString -> Ptr () -> Ptr Word64 -> IO Int32
-- hGroup : void* -> Ptr ()
-- pwzIdentity : LPCWSTR -> CWString
-- pAddress : PEER_ADDRESS* -> Ptr ()
-- pullConnectionId : ULONGLONG* out -> Ptr Word64
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let peergroupopendirectconnection =
foreign "PeerGroupOpenDirectConnection"
((ptr void) @-> (ptr uint16_t) @-> (ptr void) @-> (ptr uint64_t) @-> returning int32_t)
(* hGroup : void* -> (ptr void) *)
(* pwzIdentity : LPCWSTR -> (ptr uint16_t) *)
(* pAddress : PEER_ADDRESS* -> (ptr void) *)
(* pullConnectionId : ULONGLONG* out -> (ptr uint64_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library p2p (t "P2P.dll"))
(cffi:use-foreign-library p2p)
(cffi:defcfun ("PeerGroupOpenDirectConnection" peer-group-open-direct-connection :convention :stdcall) :int32
(h-group :pointer) ; void*
(pwz-identity (:string :encoding :utf-16le)) ; LPCWSTR
(p-address :pointer) ; PEER_ADDRESS*
(pull-connection-id :pointer)) ; ULONGLONG* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PeerGroupOpenDirectConnection = Win32::API::More->new('P2P',
'int PeerGroupOpenDirectConnection(LPVOID hGroup, LPCWSTR pwzIdentity, LPVOID pAddress, LPVOID pullConnectionId)');
# my $ret = $PeerGroupOpenDirectConnection->Call($hGroup, $pwzIdentity, $pAddress, $pullConnectionId);
# hGroup : void* -> LPVOID
# pwzIdentity : LPCWSTR -> LPCWSTR
# pAddress : PEER_ADDRESS* -> LPVOID
# pullConnectionId : ULONGLONG* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型