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

PeerGraphListen

関数
ピアグラフで着信接続の待ち受けを開始する。
DLLP2PGRAPH.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

HRESULT PeerGraphListen(
    void* hGraph,
    DWORD dwScope,   // optional
    DWORD dwScopeId,   // optional
    WORD wPort   // optional
);

パラメーター

名前方向説明
hGraphvoid*in対象グラフのハンドルを指定する。
dwScopeDWORDinoptionalリッスンするアドレススコープ(グローバル/サイトローカル等)を指定する。
dwScopeIdDWORDinoptionalスコープを識別するID(リンクローカル時のインターフェイス等)を指定する。
wPortWORDinoptional受信接続を待ち受けるポート番号を指定する。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT PeerGraphListen(
    void* hGraph,
    DWORD dwScope,   // optional
    DWORD dwScopeId,   // optional
    WORD wPort   // optional
);
[DllImport("P2PGRAPH.dll", ExactSpelling = true)]
static extern int PeerGraphListen(
    IntPtr hGraph,   // void*
    uint dwScope,   // DWORD optional
    uint dwScopeId,   // DWORD optional
    ushort wPort   // WORD optional
);
<DllImport("P2PGRAPH.dll", ExactSpelling:=True)>
Public Shared Function PeerGraphListen(
    hGraph As IntPtr,   ' void*
    dwScope As UInteger,   ' DWORD optional
    dwScopeId As UInteger,   ' DWORD optional
    wPort As UShort   ' WORD optional
) As Integer
End Function
' hGraph : void*
' dwScope : DWORD optional
' dwScopeId : DWORD optional
' wPort : WORD optional
Declare PtrSafe Function PeerGraphListen Lib "p2pgraph" ( _
    ByVal hGraph As LongPtr, _
    ByVal dwScope As Long, _
    ByVal dwScopeId As Long, _
    ByVal wPort As Integer) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PeerGraphListen = ctypes.windll.p2pgraph.PeerGraphListen
PeerGraphListen.restype = ctypes.c_int
PeerGraphListen.argtypes = [
    ctypes.POINTER(None),  # hGraph : void*
    wintypes.DWORD,  # dwScope : DWORD optional
    wintypes.DWORD,  # dwScopeId : DWORD optional
    ctypes.c_ushort,  # wPort : WORD optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('P2PGRAPH.dll')
PeerGraphListen = Fiddle::Function.new(
  lib['PeerGraphListen'],
  [
    Fiddle::TYPE_VOIDP,  # hGraph : void*
    -Fiddle::TYPE_INT,  # dwScope : DWORD optional
    -Fiddle::TYPE_INT,  # dwScopeId : DWORD optional
    -Fiddle::TYPE_SHORT,  # wPort : WORD optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "p2pgraph")]
extern "system" {
    fn PeerGraphListen(
        hGraph: *mut (),  // void*
        dwScope: u32,  // DWORD optional
        dwScopeId: u32,  // DWORD optional
        wPort: u16  // WORD optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("P2PGRAPH.dll")]
public static extern int PeerGraphListen(IntPtr hGraph, uint dwScope, uint dwScopeId, ushort wPort);
"@
$api = Add-Type -MemberDefinition $sig -Name 'P2PGRAPH_PeerGraphListen' -Namespace Win32 -PassThru
# $api::PeerGraphListen(hGraph, dwScope, dwScopeId, wPort)
#uselib "P2PGRAPH.dll"
#func global PeerGraphListen "PeerGraphListen" sptr, sptr, sptr, sptr
; PeerGraphListen hGraph, dwScope, dwScopeId, wPort   ; 戻り値は stat
; hGraph : void* -> "sptr"
; dwScope : DWORD optional -> "sptr"
; dwScopeId : DWORD optional -> "sptr"
; wPort : WORD optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "P2PGRAPH.dll"
#cfunc global PeerGraphListen "PeerGraphListen" sptr, int, int, int
; res = PeerGraphListen(hGraph, dwScope, dwScopeId, wPort)
; hGraph : void* -> "sptr"
; dwScope : DWORD optional -> "int"
; dwScopeId : DWORD optional -> "int"
; wPort : WORD optional -> "int"
; HRESULT PeerGraphListen(void* hGraph, DWORD dwScope, DWORD dwScopeId, WORD wPort)
#uselib "P2PGRAPH.dll"
#cfunc global PeerGraphListen "PeerGraphListen" intptr, int, int, int
; res = PeerGraphListen(hGraph, dwScope, dwScopeId, wPort)
; hGraph : void* -> "intptr"
; dwScope : DWORD optional -> "int"
; dwScopeId : DWORD optional -> "int"
; wPort : WORD optional -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	p2pgraph = windows.NewLazySystemDLL("P2PGRAPH.dll")
	procPeerGraphListen = p2pgraph.NewProc("PeerGraphListen")
)

// hGraph (void*), dwScope (DWORD optional), dwScopeId (DWORD optional), wPort (WORD optional)
r1, _, err := procPeerGraphListen.Call(
	uintptr(hGraph),
	uintptr(dwScope),
	uintptr(dwScopeId),
	uintptr(wPort),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function PeerGraphListen(
  hGraph: Pointer;   // void*
  dwScope: DWORD;   // DWORD optional
  dwScopeId: DWORD;   // DWORD optional
  wPort: Word   // WORD optional
): Integer; stdcall;
  external 'P2PGRAPH.dll' name 'PeerGraphListen';
result := DllCall("P2PGRAPH\PeerGraphListen"
    , "Ptr", hGraph   ; void*
    , "UInt", dwScope   ; DWORD optional
    , "UInt", dwScopeId   ; DWORD optional
    , "UShort", wPort   ; WORD optional
    , "Int")   ; return: HRESULT
●PeerGraphListen(hGraph, dwScope, dwScopeId, wPort) = DLL("P2PGRAPH.dll", "int PeerGraphListen(void*, dword, dword, int)")
# 呼び出し: PeerGraphListen(hGraph, dwScope, dwScopeId, wPort)
# hGraph : void* -> "void*"
# dwScope : DWORD optional -> "dword"
# dwScopeId : DWORD optional -> "dword"
# wPort : WORD optional -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "p2pgraph" fn PeerGraphListen(
    hGraph: ?*anyopaque, // void*
    dwScope: u32, // DWORD optional
    dwScopeId: u32, // DWORD optional
    wPort: u16 // WORD optional
) callconv(std.os.windows.WINAPI) i32;
proc PeerGraphListen(
    hGraph: pointer,  # void*
    dwScope: uint32,  # DWORD optional
    dwScopeId: uint32,  # DWORD optional
    wPort: uint16  # WORD optional
): int32 {.importc: "PeerGraphListen", stdcall, dynlib: "P2PGRAPH.dll".}
pragma(lib, "p2pgraph");
extern(Windows)
int PeerGraphListen(
    void* hGraph,   // void*
    uint dwScope,   // DWORD optional
    uint dwScopeId,   // DWORD optional
    ushort wPort   // WORD optional
);
ccall((:PeerGraphListen, "P2PGRAPH.dll"), stdcall, Int32,
      (Ptr{Cvoid}, UInt32, UInt32, UInt16),
      hGraph, dwScope, dwScopeId, wPort)
# hGraph : void* -> Ptr{Cvoid}
# dwScope : DWORD optional -> UInt32
# dwScopeId : DWORD optional -> UInt32
# wPort : WORD optional -> UInt16
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t PeerGraphListen(
    void* hGraph,
    uint32_t dwScope,
    uint32_t dwScopeId,
    uint16_t wPort);
]]
local p2pgraph = ffi.load("p2pgraph")
-- p2pgraph.PeerGraphListen(hGraph, dwScope, dwScopeId, wPort)
-- hGraph : void*
-- dwScope : DWORD optional
-- dwScopeId : DWORD optional
-- wPort : WORD optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('P2PGRAPH.dll');
const PeerGraphListen = lib.func('__stdcall', 'PeerGraphListen', 'int32_t', ['void *', 'uint32_t', 'uint32_t', 'uint16_t']);
// PeerGraphListen(hGraph, dwScope, dwScopeId, wPort)
// hGraph : void* -> 'void *'
// dwScope : DWORD optional -> 'uint32_t'
// dwScopeId : DWORD optional -> 'uint32_t'
// wPort : WORD optional -> 'uint16_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("P2PGRAPH.dll", {
  PeerGraphListen: { parameters: ["pointer", "u32", "u32", "u16"], result: "i32" },
});
// lib.symbols.PeerGraphListen(hGraph, dwScope, dwScopeId, wPort)
// hGraph : void* -> "pointer"
// dwScope : DWORD optional -> "u32"
// dwScopeId : DWORD optional -> "u32"
// wPort : WORD optional -> "u16"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t PeerGraphListen(
    void* hGraph,
    uint32_t dwScope,
    uint32_t dwScopeId,
    uint16_t wPort);
C, "P2PGRAPH.dll");
// $ffi->PeerGraphListen(hGraph, dwScope, dwScopeId, wPort);
// hGraph : void*
// dwScope : DWORD optional
// dwScopeId : DWORD optional
// wPort : WORD optional
// 構造体/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 P2pgraph extends StdCallLibrary {
    P2pgraph INSTANCE = Native.load("p2pgraph", P2pgraph.class);
    int PeerGraphListen(
        Pointer hGraph,   // void*
        int dwScope,   // DWORD optional
        int dwScopeId,   // DWORD optional
        short wPort   // WORD optional
    );
}
@[Link("p2pgraph")]
lib LibP2PGRAPH
  fun PeerGraphListen = PeerGraphListen(
    hGraph : Void*,   # void*
    dwScope : UInt32,   # DWORD optional
    dwScopeId : UInt32,   # DWORD optional
    wPort : UInt16   # WORD optional
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef PeerGraphListenNative = Int32 Function(Pointer<Void>, Uint32, Uint32, Uint16);
typedef PeerGraphListenDart = int Function(Pointer<Void>, int, int, int);
final PeerGraphListen = DynamicLibrary.open('P2PGRAPH.dll')
    .lookupFunction<PeerGraphListenNative, PeerGraphListenDart>('PeerGraphListen');
// hGraph : void* -> Pointer<Void>
// dwScope : DWORD optional -> Uint32
// dwScopeId : DWORD optional -> Uint32
// wPort : WORD optional -> Uint16
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function PeerGraphListen(
  hGraph: Pointer;   // void*
  dwScope: DWORD;   // DWORD optional
  dwScopeId: DWORD;   // DWORD optional
  wPort: Word   // WORD optional
): Integer; stdcall;
  external 'P2PGRAPH.dll' name 'PeerGraphListen';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "PeerGraphListen"
  c_PeerGraphListen :: Ptr () -> Word32 -> Word32 -> Word16 -> IO Int32
-- hGraph : void* -> Ptr ()
-- dwScope : DWORD optional -> Word32
-- dwScopeId : DWORD optional -> Word32
-- wPort : WORD optional -> Word16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let peergraphlisten =
  foreign "PeerGraphListen"
    ((ptr void) @-> uint32_t @-> uint32_t @-> uint16_t @-> returning int32_t)
(* hGraph : void* -> (ptr void) *)
(* dwScope : DWORD optional -> uint32_t *)
(* dwScopeId : DWORD optional -> uint32_t *)
(* wPort : WORD optional -> uint16_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library p2pgraph (t "P2PGRAPH.dll"))
(cffi:use-foreign-library p2pgraph)

(cffi:defcfun ("PeerGraphListen" peer-graph-listen :convention :stdcall) :int32
  (h-graph :pointer)   ; void*
  (dw-scope :uint32)   ; DWORD optional
  (dw-scope-id :uint32)   ; DWORD optional
  (w-port :uint16))   ; WORD optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $PeerGraphListen = Win32::API::More->new('P2PGRAPH',
    'int PeerGraphListen(LPVOID hGraph, DWORD dwScope, DWORD dwScopeId, WORD wPort)');
# my $ret = $PeerGraphListen->Call($hGraph, $dwScope, $dwScopeId, $wPort);
# hGraph : void* -> LPVOID
# dwScope : DWORD optional -> DWORD
# dwScopeId : DWORD optional -> DWORD
# wPort : WORD optional -> WORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。