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

DhcpDeleteSubnet

関数
DHCPサーバーから指定したサブネットを削除する。
DLLDHCPSAPI.dll呼出規約winapi対応OSwindowsserver2000

シグネチャ

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

DWORD DhcpDeleteSubnet(
    LPCWSTR ServerIpAddress,   // optional
    DWORD SubnetAddress,
    DHCP_FORCE_FLAG ForceFlag
);

パラメーター

名前方向説明
ServerIpAddressLPCWSTRinoptional操作対象DHCPサーバのIPアドレスまたはホスト名(Unicode)。
SubnetAddressDWORDin削除する対象サブネットのアドレスをDWORDで指定する。
ForceFlagDHCP_FORCE_FLAGin削除の強制レベルを示すDHCP_FORCE_FLAG値(NoForce/Full等)。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD DhcpDeleteSubnet(
    LPCWSTR ServerIpAddress,   // optional
    DWORD SubnetAddress,
    DHCP_FORCE_FLAG ForceFlag
);
[DllImport("DHCPSAPI.dll", ExactSpelling = true)]
static extern uint DhcpDeleteSubnet(
    [MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress,   // LPCWSTR optional
    uint SubnetAddress,   // DWORD
    int ForceFlag   // DHCP_FORCE_FLAG
);
<DllImport("DHCPSAPI.dll", ExactSpelling:=True)>
Public Shared Function DhcpDeleteSubnet(
    <MarshalAs(UnmanagedType.LPWStr)> ServerIpAddress As String,   ' LPCWSTR optional
    SubnetAddress As UInteger,   ' DWORD
    ForceFlag As Integer   ' DHCP_FORCE_FLAG
) As UInteger
End Function
' ServerIpAddress : LPCWSTR optional
' SubnetAddress : DWORD
' ForceFlag : DHCP_FORCE_FLAG
Declare PtrSafe Function DhcpDeleteSubnet Lib "dhcpsapi" ( _
    ByVal ServerIpAddress As LongPtr, _
    ByVal SubnetAddress As Long, _
    ByVal ForceFlag As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DhcpDeleteSubnet = ctypes.windll.dhcpsapi.DhcpDeleteSubnet
DhcpDeleteSubnet.restype = wintypes.DWORD
DhcpDeleteSubnet.argtypes = [
    wintypes.LPCWSTR,  # ServerIpAddress : LPCWSTR optional
    wintypes.DWORD,  # SubnetAddress : DWORD
    ctypes.c_int,  # ForceFlag : DHCP_FORCE_FLAG
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('DHCPSAPI.dll')
DhcpDeleteSubnet = Fiddle::Function.new(
  lib['DhcpDeleteSubnet'],
  [
    Fiddle::TYPE_VOIDP,  # ServerIpAddress : LPCWSTR optional
    -Fiddle::TYPE_INT,  # SubnetAddress : DWORD
    Fiddle::TYPE_INT,  # ForceFlag : DHCP_FORCE_FLAG
  ],
  -Fiddle::TYPE_INT)
#[link(name = "dhcpsapi")]
extern "system" {
    fn DhcpDeleteSubnet(
        ServerIpAddress: *const u16,  // LPCWSTR optional
        SubnetAddress: u32,  // DWORD
        ForceFlag: i32  // DHCP_FORCE_FLAG
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("DHCPSAPI.dll")]
public static extern uint DhcpDeleteSubnet([MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress, uint SubnetAddress, int ForceFlag);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DHCPSAPI_DhcpDeleteSubnet' -Namespace Win32 -PassThru
# $api::DhcpDeleteSubnet(ServerIpAddress, SubnetAddress, ForceFlag)
#uselib "DHCPSAPI.dll"
#func global DhcpDeleteSubnet "DhcpDeleteSubnet" sptr, sptr, sptr
; DhcpDeleteSubnet ServerIpAddress, SubnetAddress, ForceFlag   ; 戻り値は stat
; ServerIpAddress : LPCWSTR optional -> "sptr"
; SubnetAddress : DWORD -> "sptr"
; ForceFlag : DHCP_FORCE_FLAG -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "DHCPSAPI.dll"
#cfunc global DhcpDeleteSubnet "DhcpDeleteSubnet" wstr, int, int
; res = DhcpDeleteSubnet(ServerIpAddress, SubnetAddress, ForceFlag)
; ServerIpAddress : LPCWSTR optional -> "wstr"
; SubnetAddress : DWORD -> "int"
; ForceFlag : DHCP_FORCE_FLAG -> "int"
; DWORD DhcpDeleteSubnet(LPCWSTR ServerIpAddress, DWORD SubnetAddress, DHCP_FORCE_FLAG ForceFlag)
#uselib "DHCPSAPI.dll"
#cfunc global DhcpDeleteSubnet "DhcpDeleteSubnet" wstr, int, int
; res = DhcpDeleteSubnet(ServerIpAddress, SubnetAddress, ForceFlag)
; ServerIpAddress : LPCWSTR optional -> "wstr"
; SubnetAddress : DWORD -> "int"
; ForceFlag : DHCP_FORCE_FLAG -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
	procDhcpDeleteSubnet = dhcpsapi.NewProc("DhcpDeleteSubnet")
)

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

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

typedef DhcpDeleteSubnetNative = Uint32 Function(Pointer<Utf16>, Uint32, Int32);
typedef DhcpDeleteSubnetDart = int Function(Pointer<Utf16>, int, int);
final DhcpDeleteSubnet = DynamicLibrary.open('DHCPSAPI.dll')
    .lookupFunction<DhcpDeleteSubnetNative, DhcpDeleteSubnetDart>('DhcpDeleteSubnet');
// ServerIpAddress : LPCWSTR optional -> Pointer<Utf16>
// SubnetAddress : DWORD -> Uint32
// ForceFlag : DHCP_FORCE_FLAG -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DhcpDeleteSubnet(
  ServerIpAddress: PWideChar;   // LPCWSTR optional
  SubnetAddress: DWORD;   // DWORD
  ForceFlag: Integer   // DHCP_FORCE_FLAG
): DWORD; stdcall;
  external 'DHCPSAPI.dll' name 'DhcpDeleteSubnet';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DhcpDeleteSubnet"
  c_DhcpDeleteSubnet :: CWString -> Word32 -> Int32 -> IO Word32
-- ServerIpAddress : LPCWSTR optional -> CWString
-- SubnetAddress : DWORD -> Word32
-- ForceFlag : DHCP_FORCE_FLAG -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let dhcpdeletesubnet =
  foreign "DhcpDeleteSubnet"
    ((ptr uint16_t) @-> uint32_t @-> int32_t @-> returning uint32_t)
(* ServerIpAddress : LPCWSTR optional -> (ptr uint16_t) *)
(* SubnetAddress : DWORD -> uint32_t *)
(* ForceFlag : DHCP_FORCE_FLAG -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library dhcpsapi (t "DHCPSAPI.dll"))
(cffi:use-foreign-library dhcpsapi)

(cffi:defcfun ("DhcpDeleteSubnet" dhcp-delete-subnet :convention :stdcall) :uint32
  (server-ip-address (:string :encoding :utf-16le))   ; LPCWSTR optional
  (subnet-address :uint32)   ; DWORD
  (force-flag :int32))   ; DHCP_FORCE_FLAG
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DhcpDeleteSubnet = Win32::API::More->new('DHCPSAPI',
    'DWORD DhcpDeleteSubnet(LPCWSTR ServerIpAddress, DWORD SubnetAddress, int ForceFlag)');
# my $ret = $DhcpDeleteSubnet->Call($ServerIpAddress, $SubnetAddress, $ForceFlag);
# ServerIpAddress : LPCWSTR optional -> LPCWSTR
# SubnetAddress : DWORD -> DWORD
# ForceFlag : DHCP_FORCE_FLAG -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型