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

DhcpRemoveSubnetElementV4

関数
DHCPサブネットからV4拡張の要素を削除する。
DLLDHCPSAPI.dll呼出規約winapi対応OSwindowsserver2008

シグネチャ

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

DWORD DhcpRemoveSubnetElementV4(
    LPCWSTR ServerIpAddress,   // optional
    DWORD SubnetAddress,
    const DHCP_SUBNET_ELEMENT_DATA_V4* RemoveElementInfo,
    DHCP_FORCE_FLAG ForceFlag
);

パラメーター

名前方向
ServerIpAddressLPCWSTRinoptional
SubnetAddressDWORDin
RemoveElementInfoDHCP_SUBNET_ELEMENT_DATA_V4*in
ForceFlagDHCP_FORCE_FLAGin

戻り値の型: DWORD

各言語での呼び出し定義

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

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

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

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

var (
	dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
	procDhcpRemoveSubnetElementV4 = dhcpsapi.NewProc("DhcpRemoveSubnetElementV4")
)

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