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

PeerPnrpRegister

関数
ピア名をPNRPクラウドに登録する。
DLLP2P.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

HRESULT PeerPnrpRegister(
    LPCWSTR pcwzPeerName,
    PEER_PNRP_REGISTRATION_INFO* pRegistrationInfo,   // optional
    void** phRegistration
);

パラメーター

名前方向説明
pcwzPeerNameLPCWSTRin登録するピア名を指すワイド文字列。クラウド内で名前解決可能にする対象。
pRegistrationInfoPEER_PNRP_REGISTRATION_INFO*inoptional登録のエンドポイントやコメント等を格納した構造体へのポインタ。NULL可で既定動作となる。
phRegistrationvoid**out登録ハンドルを受け取るポインタ。後で更新や登録解除に使用する。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT PeerPnrpRegister(
    LPCWSTR pcwzPeerName,
    PEER_PNRP_REGISTRATION_INFO* pRegistrationInfo,   // optional
    void** phRegistration
);
[DllImport("P2P.dll", ExactSpelling = true)]
static extern int PeerPnrpRegister(
    [MarshalAs(UnmanagedType.LPWStr)] string pcwzPeerName,   // LPCWSTR
    IntPtr pRegistrationInfo,   // PEER_PNRP_REGISTRATION_INFO* optional
    IntPtr phRegistration   // void** out
);
<DllImport("P2P.dll", ExactSpelling:=True)>
Public Shared Function PeerPnrpRegister(
    <MarshalAs(UnmanagedType.LPWStr)> pcwzPeerName As String,   ' LPCWSTR
    pRegistrationInfo As IntPtr,   ' PEER_PNRP_REGISTRATION_INFO* optional
    phRegistration As IntPtr   ' void** out
) As Integer
End Function
' pcwzPeerName : LPCWSTR
' pRegistrationInfo : PEER_PNRP_REGISTRATION_INFO* optional
' phRegistration : void** out
Declare PtrSafe Function PeerPnrpRegister Lib "p2p" ( _
    ByVal pcwzPeerName As LongPtr, _
    ByVal pRegistrationInfo As LongPtr, _
    ByVal phRegistration As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PeerPnrpRegister = ctypes.windll.p2p.PeerPnrpRegister
PeerPnrpRegister.restype = ctypes.c_int
PeerPnrpRegister.argtypes = [
    wintypes.LPCWSTR,  # pcwzPeerName : LPCWSTR
    ctypes.c_void_p,  # pRegistrationInfo : PEER_PNRP_REGISTRATION_INFO* optional
    ctypes.c_void_p,  # phRegistration : void** out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	p2p = windows.NewLazySystemDLL("P2P.dll")
	procPeerPnrpRegister = p2p.NewProc("PeerPnrpRegister")
)

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

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

typedef PeerPnrpRegisterNative = Int32 Function(Pointer<Utf16>, Pointer<Void>, Pointer<Void>);
typedef PeerPnrpRegisterDart = int Function(Pointer<Utf16>, Pointer<Void>, Pointer<Void>);
final PeerPnrpRegister = DynamicLibrary.open('P2P.dll')
    .lookupFunction<PeerPnrpRegisterNative, PeerPnrpRegisterDart>('PeerPnrpRegister');
// pcwzPeerName : LPCWSTR -> Pointer<Utf16>
// pRegistrationInfo : PEER_PNRP_REGISTRATION_INFO* optional -> Pointer<Void>
// phRegistration : void** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function PeerPnrpRegister(
  pcwzPeerName: PWideChar;   // LPCWSTR
  pRegistrationInfo: Pointer;   // PEER_PNRP_REGISTRATION_INFO* optional
  phRegistration: Pointer   // void** out
): Integer; stdcall;
  external 'P2P.dll' name 'PeerPnrpRegister';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "PeerPnrpRegister"
  c_PeerPnrpRegister :: CWString -> Ptr () -> Ptr () -> IO Int32
-- pcwzPeerName : LPCWSTR -> CWString
-- pRegistrationInfo : PEER_PNRP_REGISTRATION_INFO* optional -> Ptr ()
-- phRegistration : void** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let peerpnrpregister =
  foreign "PeerPnrpRegister"
    ((ptr uint16_t) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* pcwzPeerName : LPCWSTR -> (ptr uint16_t) *)
(* pRegistrationInfo : PEER_PNRP_REGISTRATION_INFO* optional -> (ptr void) *)
(* phRegistration : void** 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 ("PeerPnrpRegister" peer-pnrp-register :convention :stdcall) :int32
  (pcwz-peer-name (:string :encoding :utf-16le))   ; LPCWSTR
  (p-registration-info :pointer)   ; PEER_PNRP_REGISTRATION_INFO* optional
  (ph-registration :pointer))   ; void** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $PeerPnrpRegister = Win32::API::More->new('P2P',
    'int PeerPnrpRegister(LPCWSTR pcwzPeerName, LPVOID pRegistrationInfo, LPVOID phRegistration)');
# my $ret = $PeerPnrpRegister->Call($pcwzPeerName, $pRegistrationInfo, $phRegistration);
# pcwzPeerName : LPCWSTR -> LPCWSTR
# pRegistrationInfo : PEER_PNRP_REGISTRATION_INFO* optional -> LPVOID
# phRegistration : void** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型