ホーム › NetworkManagement.P2P › PeerPnrpResolve
PeerPnrpResolve
関数ピア名をPNRPで解決しエンドポイントを取得する。
シグネチャ
// P2P.dll
#include <windows.h>
HRESULT PeerPnrpResolve(
LPCWSTR pcwzPeerName,
LPCWSTR pcwzCloudName, // optional
DWORD* pcEndpoints,
PEER_PNRP_ENDPOINT_INFO** ppEndpoints
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pcwzPeerName | LPCWSTR | in | 解決するピア名を指すワイド文字列。NULL不可。 |
| pcwzCloudName | LPCWSTR | inoptional | 検索対象のクラウド名。NULLで利用可能な全クラウドを対象とする。 |
| pcEndpoints | DWORD* | inout | 入力で取得希望エンドポイント数、出力で実際に取得した数を格納するポインタ。 |
| ppEndpoints | PEER_PNRP_ENDPOINT_INFO** | out | 解決されたエンドポイント情報の配列を受け取るポインタ。PeerFreeDataで解放する。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// P2P.dll
#include <windows.h>
HRESULT PeerPnrpResolve(
LPCWSTR pcwzPeerName,
LPCWSTR pcwzCloudName, // optional
DWORD* pcEndpoints,
PEER_PNRP_ENDPOINT_INFO** ppEndpoints
);[DllImport("P2P.dll", ExactSpelling = true)]
static extern int PeerPnrpResolve(
[MarshalAs(UnmanagedType.LPWStr)] string pcwzPeerName, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string pcwzCloudName, // LPCWSTR optional
ref uint pcEndpoints, // DWORD* in/out
IntPtr ppEndpoints // PEER_PNRP_ENDPOINT_INFO** out
);<DllImport("P2P.dll", ExactSpelling:=True)>
Public Shared Function PeerPnrpResolve(
<MarshalAs(UnmanagedType.LPWStr)> pcwzPeerName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> pcwzCloudName As String, ' LPCWSTR optional
ByRef pcEndpoints As UInteger, ' DWORD* in/out
ppEndpoints As IntPtr ' PEER_PNRP_ENDPOINT_INFO** out
) As Integer
End Function' pcwzPeerName : LPCWSTR
' pcwzCloudName : LPCWSTR optional
' pcEndpoints : DWORD* in/out
' ppEndpoints : PEER_PNRP_ENDPOINT_INFO** out
Declare PtrSafe Function PeerPnrpResolve Lib "p2p" ( _
ByVal pcwzPeerName As LongPtr, _
ByVal pcwzCloudName As LongPtr, _
ByRef pcEndpoints As Long, _
ByVal ppEndpoints As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PeerPnrpResolve = ctypes.windll.p2p.PeerPnrpResolve
PeerPnrpResolve.restype = ctypes.c_int
PeerPnrpResolve.argtypes = [
wintypes.LPCWSTR, # pcwzPeerName : LPCWSTR
wintypes.LPCWSTR, # pcwzCloudName : LPCWSTR optional
ctypes.POINTER(wintypes.DWORD), # pcEndpoints : DWORD* in/out
ctypes.c_void_p, # ppEndpoints : PEER_PNRP_ENDPOINT_INFO** out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('P2P.dll')
PeerPnrpResolve = Fiddle::Function.new(
lib['PeerPnrpResolve'],
[
Fiddle::TYPE_VOIDP, # pcwzPeerName : LPCWSTR
Fiddle::TYPE_VOIDP, # pcwzCloudName : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pcEndpoints : DWORD* in/out
Fiddle::TYPE_VOIDP, # ppEndpoints : PEER_PNRP_ENDPOINT_INFO** out
],
Fiddle::TYPE_INT)#[link(name = "p2p")]
extern "system" {
fn PeerPnrpResolve(
pcwzPeerName: *const u16, // LPCWSTR
pcwzCloudName: *const u16, // LPCWSTR optional
pcEndpoints: *mut u32, // DWORD* in/out
ppEndpoints: *mut *mut PEER_PNRP_ENDPOINT_INFO // PEER_PNRP_ENDPOINT_INFO** out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("P2P.dll")]
public static extern int PeerPnrpResolve([MarshalAs(UnmanagedType.LPWStr)] string pcwzPeerName, [MarshalAs(UnmanagedType.LPWStr)] string pcwzCloudName, ref uint pcEndpoints, IntPtr ppEndpoints);
"@
$api = Add-Type -MemberDefinition $sig -Name 'P2P_PeerPnrpResolve' -Namespace Win32 -PassThru
# $api::PeerPnrpResolve(pcwzPeerName, pcwzCloudName, pcEndpoints, ppEndpoints)#uselib "P2P.dll"
#func global PeerPnrpResolve "PeerPnrpResolve" sptr, sptr, sptr, sptr
; PeerPnrpResolve pcwzPeerName, pcwzCloudName, varptr(pcEndpoints), varptr(ppEndpoints) ; 戻り値は stat
; pcwzPeerName : LPCWSTR -> "sptr"
; pcwzCloudName : LPCWSTR optional -> "sptr"
; pcEndpoints : DWORD* in/out -> "sptr"
; ppEndpoints : PEER_PNRP_ENDPOINT_INFO** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "P2P.dll" #cfunc global PeerPnrpResolve "PeerPnrpResolve" wstr, wstr, var, var ; res = PeerPnrpResolve(pcwzPeerName, pcwzCloudName, pcEndpoints, ppEndpoints) ; pcwzPeerName : LPCWSTR -> "wstr" ; pcwzCloudName : LPCWSTR optional -> "wstr" ; pcEndpoints : DWORD* in/out -> "var" ; ppEndpoints : PEER_PNRP_ENDPOINT_INFO** out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "P2P.dll" #cfunc global PeerPnrpResolve "PeerPnrpResolve" wstr, wstr, sptr, sptr ; res = PeerPnrpResolve(pcwzPeerName, pcwzCloudName, varptr(pcEndpoints), varptr(ppEndpoints)) ; pcwzPeerName : LPCWSTR -> "wstr" ; pcwzCloudName : LPCWSTR optional -> "wstr" ; pcEndpoints : DWORD* in/out -> "sptr" ; ppEndpoints : PEER_PNRP_ENDPOINT_INFO** out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT PeerPnrpResolve(LPCWSTR pcwzPeerName, LPCWSTR pcwzCloudName, DWORD* pcEndpoints, PEER_PNRP_ENDPOINT_INFO** ppEndpoints) #uselib "P2P.dll" #cfunc global PeerPnrpResolve "PeerPnrpResolve" wstr, wstr, var, var ; res = PeerPnrpResolve(pcwzPeerName, pcwzCloudName, pcEndpoints, ppEndpoints) ; pcwzPeerName : LPCWSTR -> "wstr" ; pcwzCloudName : LPCWSTR optional -> "wstr" ; pcEndpoints : DWORD* in/out -> "var" ; ppEndpoints : PEER_PNRP_ENDPOINT_INFO** out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT PeerPnrpResolve(LPCWSTR pcwzPeerName, LPCWSTR pcwzCloudName, DWORD* pcEndpoints, PEER_PNRP_ENDPOINT_INFO** ppEndpoints) #uselib "P2P.dll" #cfunc global PeerPnrpResolve "PeerPnrpResolve" wstr, wstr, intptr, intptr ; res = PeerPnrpResolve(pcwzPeerName, pcwzCloudName, varptr(pcEndpoints), varptr(ppEndpoints)) ; pcwzPeerName : LPCWSTR -> "wstr" ; pcwzCloudName : LPCWSTR optional -> "wstr" ; pcEndpoints : DWORD* in/out -> "intptr" ; ppEndpoints : PEER_PNRP_ENDPOINT_INFO** out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
p2p = windows.NewLazySystemDLL("P2P.dll")
procPeerPnrpResolve = p2p.NewProc("PeerPnrpResolve")
)
// pcwzPeerName (LPCWSTR), pcwzCloudName (LPCWSTR optional), pcEndpoints (DWORD* in/out), ppEndpoints (PEER_PNRP_ENDPOINT_INFO** out)
r1, _, err := procPeerPnrpResolve.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pcwzPeerName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pcwzCloudName))),
uintptr(pcEndpoints),
uintptr(ppEndpoints),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction PeerPnrpResolve(
pcwzPeerName: PWideChar; // LPCWSTR
pcwzCloudName: PWideChar; // LPCWSTR optional
pcEndpoints: Pointer; // DWORD* in/out
ppEndpoints: Pointer // PEER_PNRP_ENDPOINT_INFO** out
): Integer; stdcall;
external 'P2P.dll' name 'PeerPnrpResolve';result := DllCall("P2P\PeerPnrpResolve"
, "WStr", pcwzPeerName ; LPCWSTR
, "WStr", pcwzCloudName ; LPCWSTR optional
, "Ptr", pcEndpoints ; DWORD* in/out
, "Ptr", ppEndpoints ; PEER_PNRP_ENDPOINT_INFO** out
, "Int") ; return: HRESULT●PeerPnrpResolve(pcwzPeerName, pcwzCloudName, pcEndpoints, ppEndpoints) = DLL("P2P.dll", "int PeerPnrpResolve(char*, char*, void*, void*)")
# 呼び出し: PeerPnrpResolve(pcwzPeerName, pcwzCloudName, pcEndpoints, ppEndpoints)
# pcwzPeerName : LPCWSTR -> "char*"
# pcwzCloudName : LPCWSTR optional -> "char*"
# pcEndpoints : DWORD* in/out -> "void*"
# ppEndpoints : PEER_PNRP_ENDPOINT_INFO** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "p2p" fn PeerPnrpResolve(
pcwzPeerName: [*c]const u16, // LPCWSTR
pcwzCloudName: [*c]const u16, // LPCWSTR optional
pcEndpoints: [*c]u32, // DWORD* in/out
ppEndpoints: [*c][*c]PEER_PNRP_ENDPOINT_INFO // PEER_PNRP_ENDPOINT_INFO** out
) callconv(std.os.windows.WINAPI) i32;proc PeerPnrpResolve(
pcwzPeerName: WideCString, # LPCWSTR
pcwzCloudName: WideCString, # LPCWSTR optional
pcEndpoints: ptr uint32, # DWORD* in/out
ppEndpoints: ptr PEER_PNRP_ENDPOINT_INFO # PEER_PNRP_ENDPOINT_INFO** out
): int32 {.importc: "PeerPnrpResolve", stdcall, dynlib: "P2P.dll".}pragma(lib, "p2p");
extern(Windows)
int PeerPnrpResolve(
const(wchar)* pcwzPeerName, // LPCWSTR
const(wchar)* pcwzCloudName, // LPCWSTR optional
uint* pcEndpoints, // DWORD* in/out
PEER_PNRP_ENDPOINT_INFO** ppEndpoints // PEER_PNRP_ENDPOINT_INFO** out
);ccall((:PeerPnrpResolve, "P2P.dll"), stdcall, Int32,
(Cwstring, Cwstring, Ptr{UInt32}, Ptr{PEER_PNRP_ENDPOINT_INFO}),
pcwzPeerName, pcwzCloudName, pcEndpoints, ppEndpoints)
# pcwzPeerName : LPCWSTR -> Cwstring
# pcwzCloudName : LPCWSTR optional -> Cwstring
# pcEndpoints : DWORD* in/out -> Ptr{UInt32}
# ppEndpoints : PEER_PNRP_ENDPOINT_INFO** out -> Ptr{PEER_PNRP_ENDPOINT_INFO}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t PeerPnrpResolve(
const uint16_t* pcwzPeerName,
const uint16_t* pcwzCloudName,
uint32_t* pcEndpoints,
void* ppEndpoints);
]]
local p2p = ffi.load("p2p")
-- p2p.PeerPnrpResolve(pcwzPeerName, pcwzCloudName, pcEndpoints, ppEndpoints)
-- pcwzPeerName : LPCWSTR
-- pcwzCloudName : LPCWSTR optional
-- pcEndpoints : DWORD* in/out
-- ppEndpoints : PEER_PNRP_ENDPOINT_INFO** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('P2P.dll');
const PeerPnrpResolve = lib.func('__stdcall', 'PeerPnrpResolve', 'int32_t', ['str16', 'str16', 'uint32_t *', 'void *']);
// PeerPnrpResolve(pcwzPeerName, pcwzCloudName, pcEndpoints, ppEndpoints)
// pcwzPeerName : LPCWSTR -> 'str16'
// pcwzCloudName : LPCWSTR optional -> 'str16'
// pcEndpoints : DWORD* in/out -> 'uint32_t *'
// ppEndpoints : PEER_PNRP_ENDPOINT_INFO** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("P2P.dll", {
PeerPnrpResolve: { parameters: ["buffer", "buffer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.PeerPnrpResolve(pcwzPeerName, pcwzCloudName, pcEndpoints, ppEndpoints)
// pcwzPeerName : LPCWSTR -> "buffer"
// pcwzCloudName : LPCWSTR optional -> "buffer"
// pcEndpoints : DWORD* in/out -> "pointer"
// ppEndpoints : PEER_PNRP_ENDPOINT_INFO** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t PeerPnrpResolve(
const uint16_t* pcwzPeerName,
const uint16_t* pcwzCloudName,
uint32_t* pcEndpoints,
void* ppEndpoints);
C, "P2P.dll");
// $ffi->PeerPnrpResolve(pcwzPeerName, pcwzCloudName, pcEndpoints, ppEndpoints);
// pcwzPeerName : LPCWSTR
// pcwzCloudName : LPCWSTR optional
// pcEndpoints : DWORD* in/out
// ppEndpoints : PEER_PNRP_ENDPOINT_INFO** 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 PeerPnrpResolve(
WString pcwzPeerName, // LPCWSTR
WString pcwzCloudName, // LPCWSTR optional
IntByReference pcEndpoints, // DWORD* in/out
Pointer ppEndpoints // PEER_PNRP_ENDPOINT_INFO** out
);
}@[Link("p2p")]
lib LibP2P
fun PeerPnrpResolve = PeerPnrpResolve(
pcwzPeerName : UInt16*, # LPCWSTR
pcwzCloudName : UInt16*, # LPCWSTR optional
pcEndpoints : UInt32*, # DWORD* in/out
ppEndpoints : PEER_PNRP_ENDPOINT_INFO** # PEER_PNRP_ENDPOINT_INFO** out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PeerPnrpResolveNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>, Pointer<Void>);
typedef PeerPnrpResolveDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>, Pointer<Void>);
final PeerPnrpResolve = DynamicLibrary.open('P2P.dll')
.lookupFunction<PeerPnrpResolveNative, PeerPnrpResolveDart>('PeerPnrpResolve');
// pcwzPeerName : LPCWSTR -> Pointer<Utf16>
// pcwzCloudName : LPCWSTR optional -> Pointer<Utf16>
// pcEndpoints : DWORD* in/out -> Pointer<Uint32>
// ppEndpoints : PEER_PNRP_ENDPOINT_INFO** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PeerPnrpResolve(
pcwzPeerName: PWideChar; // LPCWSTR
pcwzCloudName: PWideChar; // LPCWSTR optional
pcEndpoints: Pointer; // DWORD* in/out
ppEndpoints: Pointer // PEER_PNRP_ENDPOINT_INFO** out
): Integer; stdcall;
external 'P2P.dll' name 'PeerPnrpResolve';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PeerPnrpResolve"
c_PeerPnrpResolve :: CWString -> CWString -> Ptr Word32 -> Ptr () -> IO Int32
-- pcwzPeerName : LPCWSTR -> CWString
-- pcwzCloudName : LPCWSTR optional -> CWString
-- pcEndpoints : DWORD* in/out -> Ptr Word32
-- ppEndpoints : PEER_PNRP_ENDPOINT_INFO** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let peerpnrpresolve =
foreign "PeerPnrpResolve"
((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> (ptr void) @-> returning int32_t)
(* pcwzPeerName : LPCWSTR -> (ptr uint16_t) *)
(* pcwzCloudName : LPCWSTR optional -> (ptr uint16_t) *)
(* pcEndpoints : DWORD* in/out -> (ptr uint32_t) *)
(* ppEndpoints : PEER_PNRP_ENDPOINT_INFO** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library p2p (t "P2P.dll"))
(cffi:use-foreign-library p2p)
(cffi:defcfun ("PeerPnrpResolve" peer-pnrp-resolve :convention :stdcall) :int32
(pcwz-peer-name (:string :encoding :utf-16le)) ; LPCWSTR
(pcwz-cloud-name (:string :encoding :utf-16le)) ; LPCWSTR optional
(pc-endpoints :pointer) ; DWORD* in/out
(pp-endpoints :pointer)) ; PEER_PNRP_ENDPOINT_INFO** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PeerPnrpResolve = Win32::API::More->new('P2P',
'int PeerPnrpResolve(LPCWSTR pcwzPeerName, LPCWSTR pcwzCloudName, LPVOID pcEndpoints, LPVOID ppEndpoints)');
# my $ret = $PeerPnrpResolve->Call($pcwzPeerName, $pcwzCloudName, $pcEndpoints, $ppEndpoints);
# pcwzPeerName : LPCWSTR -> LPCWSTR
# pcwzCloudName : LPCWSTR optional -> LPCWSTR
# pcEndpoints : DWORD* in/out -> LPVOID
# ppEndpoints : PEER_PNRP_ENDPOINT_INFO** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。