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

DeletePersistentUdpPortReservation

関数
永続的なUDPポート予約を削除する。
DLLIPHLPAPI.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

DWORD DeletePersistentUdpPortReservation(
    WORD StartPort,
    WORD NumberOfPorts
);

パラメーター

名前方向説明
StartPortWORDin開始する UDP ポート番号。ネットワークバイトオーダーで指定します。
NumberOfPortsWORDin削除する UDP ポート番号の個数。

戻り値の型: DWORD

公式ドキュメント

ローカルコンピューター上の連続した UDP ポートのブロックに対する永続的な UDP ポート予約を削除します。(DeletePersistentUdpPortReservation)

戻り値

関数が成功した場合、戻り値は NO_ERROR です。

関数が失敗した場合、戻り値は次のいずれかのエラーコードになります。

戻り値 説明
ERROR_ACCESS_DENIED
アクセスが拒否されました。このエラーは、次のような複数の条件で返されます。ユーザーがローカルコンピューター上で必要な管理者権限を持っていない場合、またはアプリケーションが組み込みの Administrator(管理者として実行)として昇格されたシェルで実行されていない場合などです。
ERROR_INVALID_PARAMETER
無効なパラメーターが関数に渡されました。このエラーは、StartPort または NumberOfPorts パラメーターにゼロが渡された場合に返されます。
ERROR_NOT_FOUND
要素が見つかりませんでした。このエラーは、StartPort および NumberOfPorts パラメーターで指定された永続的なポートブロックが見つからなかった場合に返されます。
その他
返されたエラーに対応するメッセージ文字列を取得するには、 FormatMessage を使用してください。

解説(Remarks)

DeletePersistentUdpPortReservation 関数は Windows Vista 以降で定義されています。

DeletePersistentUdpPortReservation 関数は、UDP ポートのブロックに対する永続的な予約を削除するために使用します。

DeletePersistentUdpPortReservation 関数は、Administrators グループのメンバーとしてログオンしているユーザーのみが呼び出すことができます。Administrators グループのメンバーでないユーザーが DeletePersistentUdpPortReservation を呼び出した場合、関数の呼び出しは失敗し、ERROR_ACCESS_DENIED が返されます。この関数は、Windows Vista 以降のユーザーアカウント制御(UAC)が原因で失敗することもあります。この関数を含むアプリケーションが、組み込みの Administrator 以外の Administrators グループのメンバーとしてログオンしているユーザーによって実行された場合、マニフェストファイル内で requestedExecutionLevel が requireAdministrator に設定されていない限り、この呼び出しは失敗します。アプリケーションにこのマニフェストファイルがない場合、組み込みの Administrator 以外の Administrators グループのメンバーとしてログオンしているユーザーは、この関数を成功させるために、組み込みの Administrator(管理者として実行)として昇格されたシェルでアプリケーションを実行する必要があります。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

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

DeletePersistentUdpPortReservation = ctypes.windll.iphlpapi.DeletePersistentUdpPortReservation
DeletePersistentUdpPortReservation.restype = wintypes.DWORD
DeletePersistentUdpPortReservation.argtypes = [
    ctypes.c_ushort,  # StartPort : WORD
    ctypes.c_ushort,  # NumberOfPorts : WORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
	procDeletePersistentUdpPortReservation = iphlpapi.NewProc("DeletePersistentUdpPortReservation")
)

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

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

typedef DeletePersistentUdpPortReservationNative = Uint32 Function(Uint16, Uint16);
typedef DeletePersistentUdpPortReservationDart = int Function(int, int);
final DeletePersistentUdpPortReservation = DynamicLibrary.open('IPHLPAPI.dll')
    .lookupFunction<DeletePersistentUdpPortReservationNative, DeletePersistentUdpPortReservationDart>('DeletePersistentUdpPortReservation');
// StartPort : WORD -> Uint16
// NumberOfPorts : WORD -> Uint16
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DeletePersistentUdpPortReservation(
  StartPort: Word;   // WORD
  NumberOfPorts: Word   // WORD
): DWORD; stdcall;
  external 'IPHLPAPI.dll' name 'DeletePersistentUdpPortReservation';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DeletePersistentUdpPortReservation"
  c_DeletePersistentUdpPortReservation :: Word16 -> Word16 -> IO Word32
-- StartPort : WORD -> Word16
-- NumberOfPorts : WORD -> Word16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let deletepersistentudpportreservation =
  foreign "DeletePersistentUdpPortReservation"
    (uint16_t @-> uint16_t @-> returning uint32_t)
(* StartPort : WORD -> uint16_t *)
(* NumberOfPorts : WORD -> uint16_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library iphlpapi (t "IPHLPAPI.dll"))
(cffi:use-foreign-library iphlpapi)

(cffi:defcfun ("DeletePersistentUdpPortReservation" delete-persistent-udp-port-reservation :convention :stdcall) :uint32
  (start-port :uint16)   ; WORD
  (number-of-ports :uint16))   ; WORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DeletePersistentUdpPortReservation = Win32::API::More->new('IPHLPAPI',
    'DWORD DeletePersistentUdpPortReservation(WORD StartPort, WORD NumberOfPorts)');
# my $ret = $DeletePersistentUdpPortReservation->Call($StartPort, $NumberOfPorts);
# StartPort : WORD -> WORD
# NumberOfPorts : WORD -> WORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目