ホーム › NetworkManagement.Dhcp › DhcpV4AddPolicyRange
DhcpV4AddPolicyRange
関数指定したIPv4ポリシーにIPアドレス範囲を追加する。
シグネチャ
// DHCPSAPI.dll
#include <windows.h>
DWORD DhcpV4AddPolicyRange(
LPWSTR ServerIpAddress, // optional
DWORD SubnetAddress,
LPWSTR PolicyName,
DHCP_IP_RANGE* Range
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| ServerIpAddress | LPWSTR | inoptional |
| SubnetAddress | DWORD | in |
| PolicyName | LPWSTR | in |
| Range | DHCP_IP_RANGE* | in |
戻り値の型: DWORD
各言語での呼び出し定義
// DHCPSAPI.dll
#include <windows.h>
DWORD DhcpV4AddPolicyRange(
LPWSTR ServerIpAddress, // optional
DWORD SubnetAddress,
LPWSTR PolicyName,
DHCP_IP_RANGE* Range
);[DllImport("DHCPSAPI.dll", ExactSpelling = true)]
static extern uint DhcpV4AddPolicyRange(
[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 DhcpV4AddPolicyRange(
<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 DhcpV4AddPolicyRange 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
DhcpV4AddPolicyRange = ctypes.windll.dhcpsapi.DhcpV4AddPolicyRange
DhcpV4AddPolicyRange.restype = wintypes.DWORD
DhcpV4AddPolicyRange.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')
DhcpV4AddPolicyRange = Fiddle::Function.new(
lib['DhcpV4AddPolicyRange'],
[
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 DhcpV4AddPolicyRange(
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 DhcpV4AddPolicyRange([MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress, uint SubnetAddress, [MarshalAs(UnmanagedType.LPWStr)] string PolicyName, IntPtr Range);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DHCPSAPI_DhcpV4AddPolicyRange' -Namespace Win32 -PassThru
# $api::DhcpV4AddPolicyRange(ServerIpAddress, SubnetAddress, PolicyName, Range)#uselib "DHCPSAPI.dll"
#func global DhcpV4AddPolicyRange "DhcpV4AddPolicyRange" sptr, sptr, sptr, sptr
; DhcpV4AddPolicyRange 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 DhcpV4AddPolicyRange "DhcpV4AddPolicyRange" wstr, int, wstr, var ; res = DhcpV4AddPolicyRange(ServerIpAddress, SubnetAddress, PolicyName, Range) ; ServerIpAddress : LPWSTR optional -> "wstr" ; SubnetAddress : DWORD -> "int" ; PolicyName : LPWSTR -> "wstr" ; Range : DHCP_IP_RANGE* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "DHCPSAPI.dll" #cfunc global DhcpV4AddPolicyRange "DhcpV4AddPolicyRange" wstr, int, wstr, sptr ; res = DhcpV4AddPolicyRange(ServerIpAddress, SubnetAddress, PolicyName, varptr(Range)) ; ServerIpAddress : LPWSTR optional -> "wstr" ; SubnetAddress : DWORD -> "int" ; PolicyName : LPWSTR -> "wstr" ; Range : DHCP_IP_RANGE* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD DhcpV4AddPolicyRange(LPWSTR ServerIpAddress, DWORD SubnetAddress, LPWSTR PolicyName, DHCP_IP_RANGE* Range) #uselib "DHCPSAPI.dll" #cfunc global DhcpV4AddPolicyRange "DhcpV4AddPolicyRange" wstr, int, wstr, var ; res = DhcpV4AddPolicyRange(ServerIpAddress, SubnetAddress, PolicyName, Range) ; ServerIpAddress : LPWSTR optional -> "wstr" ; SubnetAddress : DWORD -> "int" ; PolicyName : LPWSTR -> "wstr" ; Range : DHCP_IP_RANGE* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD DhcpV4AddPolicyRange(LPWSTR ServerIpAddress, DWORD SubnetAddress, LPWSTR PolicyName, DHCP_IP_RANGE* Range) #uselib "DHCPSAPI.dll" #cfunc global DhcpV4AddPolicyRange "DhcpV4AddPolicyRange" wstr, int, wstr, intptr ; res = DhcpV4AddPolicyRange(ServerIpAddress, SubnetAddress, PolicyName, varptr(Range)) ; ServerIpAddress : LPWSTR optional -> "wstr" ; SubnetAddress : DWORD -> "int" ; PolicyName : LPWSTR -> "wstr" ; Range : DHCP_IP_RANGE* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
procDhcpV4AddPolicyRange = dhcpsapi.NewProc("DhcpV4AddPolicyRange")
)
// ServerIpAddress (LPWSTR optional), SubnetAddress (DWORD), PolicyName (LPWSTR), Range (DHCP_IP_RANGE*)
r1, _, err := procDhcpV4AddPolicyRange.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 // DWORDfunction DhcpV4AddPolicyRange(
ServerIpAddress: PWideChar; // LPWSTR optional
SubnetAddress: DWORD; // DWORD
PolicyName: PWideChar; // LPWSTR
Range: Pointer // DHCP_IP_RANGE*
): DWORD; stdcall;
external 'DHCPSAPI.dll' name 'DhcpV4AddPolicyRange';result := DllCall("DHCPSAPI\DhcpV4AddPolicyRange"
, "WStr", ServerIpAddress ; LPWSTR optional
, "UInt", SubnetAddress ; DWORD
, "WStr", PolicyName ; LPWSTR
, "Ptr", Range ; DHCP_IP_RANGE*
, "UInt") ; return: DWORD●DhcpV4AddPolicyRange(ServerIpAddress, SubnetAddress, PolicyName, Range) = DLL("DHCPSAPI.dll", "dword DhcpV4AddPolicyRange(char*, dword, char*, void*)")
# 呼び出し: DhcpV4AddPolicyRange(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)。