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

DhcpV4RemovePolicyRange

関数
指定したIPv4ポリシーからIPアドレス範囲を削除する。
DLLDHCPSAPI.dll呼出規約winapi対応OSwindowsserver2012

シグネチャ

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

DWORD DhcpV4RemovePolicyRange(
    LPWSTR ServerIpAddress,   // optional
    DWORD SubnetAddress,
    LPWSTR PolicyName,
    DHCP_IP_RANGE* Range
);

パラメーター

名前方向
ServerIpAddressLPWSTRinoptional
SubnetAddressDWORDin
PolicyNameLPWSTRin
RangeDHCP_IP_RANGE*in

戻り値の型: DWORD

各言語での呼び出し定義

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

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

DhcpV4RemovePolicyRange = ctypes.windll.dhcpsapi.DhcpV4RemovePolicyRange
DhcpV4RemovePolicyRange.restype = wintypes.DWORD
DhcpV4RemovePolicyRange.argtypes = [
    wintypes.LPCWSTR,  # ServerIpAddress : LPWSTR optional
    wintypes.DWORD,  # SubnetAddress : DWORD
    wintypes.LPCWSTR,  # PolicyName : LPWSTR
    ctypes.c_void_p,  # Range : DHCP_IP_RANGE*
]
require 'fiddle'
require 'fiddle/import'

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

var (
	dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
	procDhcpV4RemovePolicyRange = dhcpsapi.NewProc("DhcpV4RemovePolicyRange")
)

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