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

CreatePersistentUdpPortReservation

関数
永続的なUDPポート予約ブロックを作成する。
DLLIPHLPAPI.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

DWORD CreatePersistentUdpPortReservation(
    WORD StartPort,
    WORD NumberOfPorts,
    ULONGLONG* Token
);

パラメーター

名前方向
StartPortWORDin
NumberOfPortsWORDin
TokenULONGLONG*out

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD CreatePersistentUdpPortReservation(
    WORD StartPort,
    WORD NumberOfPorts,
    ULONGLONG* Token
);
[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint CreatePersistentUdpPortReservation(
    ushort StartPort,   // WORD
    ushort NumberOfPorts,   // WORD
    out ulong Token   // ULONGLONG* out
);
<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function CreatePersistentUdpPortReservation(
    StartPort As UShort,   ' WORD
    NumberOfPorts As UShort,   ' WORD
    <Out> ByRef Token As ULong   ' ULONGLONG* out
) As UInteger
End Function
' StartPort : WORD
' NumberOfPorts : WORD
' Token : ULONGLONG* out
Declare PtrSafe Function CreatePersistentUdpPortReservation Lib "iphlpapi" ( _
    ByVal StartPort As Integer, _
    ByVal NumberOfPorts As Integer, _
    ByRef Token As LongLong) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreatePersistentUdpPortReservation = ctypes.windll.iphlpapi.CreatePersistentUdpPortReservation
CreatePersistentUdpPortReservation.restype = wintypes.DWORD
CreatePersistentUdpPortReservation.argtypes = [
    ctypes.c_ushort,  # StartPort : WORD
    ctypes.c_ushort,  # NumberOfPorts : WORD
    ctypes.POINTER(ctypes.c_ulonglong),  # Token : ULONGLONG* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('IPHLPAPI.dll')
CreatePersistentUdpPortReservation = Fiddle::Function.new(
  lib['CreatePersistentUdpPortReservation'],
  [
    -Fiddle::TYPE_SHORT,  # StartPort : WORD
    -Fiddle::TYPE_SHORT,  # NumberOfPorts : WORD
    Fiddle::TYPE_VOIDP,  # Token : ULONGLONG* out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "iphlpapi")]
extern "system" {
    fn CreatePersistentUdpPortReservation(
        StartPort: u16,  // WORD
        NumberOfPorts: u16,  // WORD
        Token: *mut u64  // ULONGLONG* out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("IPHLPAPI.dll")]
public static extern uint CreatePersistentUdpPortReservation(ushort StartPort, ushort NumberOfPorts, out ulong Token);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_CreatePersistentUdpPortReservation' -Namespace Win32 -PassThru
# $api::CreatePersistentUdpPortReservation(StartPort, NumberOfPorts, Token)
#uselib "IPHLPAPI.dll"
#func global CreatePersistentUdpPortReservation "CreatePersistentUdpPortReservation" sptr, sptr, sptr
; CreatePersistentUdpPortReservation StartPort, NumberOfPorts, varptr(Token)   ; 戻り値は stat
; StartPort : WORD -> "sptr"
; NumberOfPorts : WORD -> "sptr"
; Token : ULONGLONG* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "IPHLPAPI.dll"
#cfunc global CreatePersistentUdpPortReservation "CreatePersistentUdpPortReservation" int, int, var
; res = CreatePersistentUdpPortReservation(StartPort, NumberOfPorts, Token)
; StartPort : WORD -> "int"
; NumberOfPorts : WORD -> "int"
; Token : ULONGLONG* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD CreatePersistentUdpPortReservation(WORD StartPort, WORD NumberOfPorts, ULONGLONG* Token)
#uselib "IPHLPAPI.dll"
#cfunc global CreatePersistentUdpPortReservation "CreatePersistentUdpPortReservation" int, int, var
; res = CreatePersistentUdpPortReservation(StartPort, NumberOfPorts, Token)
; StartPort : WORD -> "int"
; NumberOfPorts : WORD -> "int"
; Token : ULONGLONG* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
	procCreatePersistentUdpPortReservation = iphlpapi.NewProc("CreatePersistentUdpPortReservation")
)

// StartPort (WORD), NumberOfPorts (WORD), Token (ULONGLONG* out)
r1, _, err := procCreatePersistentUdpPortReservation.Call(
	uintptr(StartPort),
	uintptr(NumberOfPorts),
	uintptr(Token),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function CreatePersistentUdpPortReservation(
  StartPort: Word;   // WORD
  NumberOfPorts: Word;   // WORD
  Token: Pointer   // ULONGLONG* out
): DWORD; stdcall;
  external 'IPHLPAPI.dll' name 'CreatePersistentUdpPortReservation';
result := DllCall("IPHLPAPI\CreatePersistentUdpPortReservation"
    , "UShort", StartPort   ; WORD
    , "UShort", NumberOfPorts   ; WORD
    , "Ptr", Token   ; ULONGLONG* out
    , "UInt")   ; return: DWORD
●CreatePersistentUdpPortReservation(StartPort, NumberOfPorts, Token) = DLL("IPHLPAPI.dll", "dword CreatePersistentUdpPortReservation(int, int, void*)")
# 呼び出し: CreatePersistentUdpPortReservation(StartPort, NumberOfPorts, Token)
# StartPort : WORD -> "int"
# NumberOfPorts : WORD -> "int"
# Token : ULONGLONG* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。