ホーム › 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 | 対象DHCPサーバーのIPアドレスを示すUnicode文字列。ローカルならNULL可。 |
| SubnetAddress | DWORD | in | ポリシー範囲を追加する対象サブネットのIPアドレス(DWORD)。 |
| PolicyName | LPWSTR | in | 範囲を追加する対象ポリシーの名前を示す文字列。 |
| Range | DHCP_IP_RANGE* | in | 追加するIPアドレス範囲を表すDHCP_IP_RANGE構造体へのポインタ。 |
戻り値の型: 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)。const std = @import("std");
extern "dhcpsapi" fn DhcpV4AddPolicyRange(
ServerIpAddress: [*c]const u16, // LPWSTR optional
SubnetAddress: u32, // DWORD
PolicyName: [*c]const u16, // LPWSTR
Range: [*c]DHCP_IP_RANGE // DHCP_IP_RANGE*
) callconv(std.os.windows.WINAPI) u32;proc DhcpV4AddPolicyRange(
ServerIpAddress: WideCString, # LPWSTR optional
SubnetAddress: uint32, # DWORD
PolicyName: WideCString, # LPWSTR
Range: ptr DHCP_IP_RANGE # DHCP_IP_RANGE*
): uint32 {.importc: "DhcpV4AddPolicyRange", stdcall, dynlib: "DHCPSAPI.dll".}pragma(lib, "dhcpsapi");
extern(Windows)
uint DhcpV4AddPolicyRange(
const(wchar)* ServerIpAddress, // LPWSTR optional
uint SubnetAddress, // DWORD
const(wchar)* PolicyName, // LPWSTR
DHCP_IP_RANGE* Range // DHCP_IP_RANGE*
);ccall((:DhcpV4AddPolicyRange, "DHCPSAPI.dll"), stdcall, UInt32,
(Cwstring, UInt32, Cwstring, Ptr{DHCP_IP_RANGE}),
ServerIpAddress, SubnetAddress, PolicyName, Range)
# ServerIpAddress : LPWSTR optional -> Cwstring
# SubnetAddress : DWORD -> UInt32
# PolicyName : LPWSTR -> Cwstring
# Range : DHCP_IP_RANGE* -> Ptr{DHCP_IP_RANGE}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t DhcpV4AddPolicyRange(
const uint16_t* ServerIpAddress,
uint32_t SubnetAddress,
const uint16_t* PolicyName,
void* Range);
]]
local dhcpsapi = ffi.load("dhcpsapi")
-- dhcpsapi.DhcpV4AddPolicyRange(ServerIpAddress, SubnetAddress, PolicyName, Range)
-- ServerIpAddress : LPWSTR optional
-- SubnetAddress : DWORD
-- PolicyName : LPWSTR
-- Range : DHCP_IP_RANGE*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('DHCPSAPI.dll');
const DhcpV4AddPolicyRange = lib.func('__stdcall', 'DhcpV4AddPolicyRange', 'uint32_t', ['str16', 'uint32_t', 'str16', 'void *']);
// DhcpV4AddPolicyRange(ServerIpAddress, SubnetAddress, PolicyName, Range)
// ServerIpAddress : LPWSTR optional -> 'str16'
// SubnetAddress : DWORD -> 'uint32_t'
// PolicyName : LPWSTR -> 'str16'
// Range : DHCP_IP_RANGE* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("DHCPSAPI.dll", {
DhcpV4AddPolicyRange: { parameters: ["buffer", "u32", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.DhcpV4AddPolicyRange(ServerIpAddress, SubnetAddress, PolicyName, Range)
// ServerIpAddress : LPWSTR optional -> "buffer"
// SubnetAddress : DWORD -> "u32"
// PolicyName : LPWSTR -> "buffer"
// Range : DHCP_IP_RANGE* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t DhcpV4AddPolicyRange(
const uint16_t* ServerIpAddress,
uint32_t SubnetAddress,
const uint16_t* PolicyName,
void* Range);
C, "DHCPSAPI.dll");
// $ffi->DhcpV4AddPolicyRange(ServerIpAddress, SubnetAddress, PolicyName, Range);
// ServerIpAddress : LPWSTR optional
// SubnetAddress : DWORD
// PolicyName : LPWSTR
// Range : DHCP_IP_RANGE*
// 構造体/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 DhcpV4AddPolicyRange(
WString ServerIpAddress, // LPWSTR optional
int SubnetAddress, // DWORD
WString PolicyName, // LPWSTR
Pointer Range // DHCP_IP_RANGE*
);
}@[Link("dhcpsapi")]
lib LibDHCPSAPI
fun DhcpV4AddPolicyRange = DhcpV4AddPolicyRange(
ServerIpAddress : UInt16*, # LPWSTR optional
SubnetAddress : UInt32, # DWORD
PolicyName : UInt16*, # LPWSTR
Range : DHCP_IP_RANGE* # DHCP_IP_RANGE*
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DhcpV4AddPolicyRangeNative = Uint32 Function(Pointer<Utf16>, Uint32, Pointer<Utf16>, Pointer<Void>);
typedef DhcpV4AddPolicyRangeDart = int Function(Pointer<Utf16>, int, Pointer<Utf16>, Pointer<Void>);
final DhcpV4AddPolicyRange = DynamicLibrary.open('DHCPSAPI.dll')
.lookupFunction<DhcpV4AddPolicyRangeNative, DhcpV4AddPolicyRangeDart>('DhcpV4AddPolicyRange');
// ServerIpAddress : LPWSTR optional -> Pointer<Utf16>
// SubnetAddress : DWORD -> Uint32
// PolicyName : LPWSTR -> Pointer<Utf16>
// Range : DHCP_IP_RANGE* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DhcpV4AddPolicyRange(
ServerIpAddress: PWideChar; // LPWSTR optional
SubnetAddress: DWORD; // DWORD
PolicyName: PWideChar; // LPWSTR
Range: Pointer // DHCP_IP_RANGE*
): DWORD; stdcall;
external 'DHCPSAPI.dll' name 'DhcpV4AddPolicyRange';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DhcpV4AddPolicyRange"
c_DhcpV4AddPolicyRange :: CWString -> Word32 -> CWString -> Ptr () -> IO Word32
-- ServerIpAddress : LPWSTR optional -> CWString
-- SubnetAddress : DWORD -> Word32
-- PolicyName : LPWSTR -> CWString
-- Range : DHCP_IP_RANGE* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let dhcpv4addpolicyrange =
foreign "DhcpV4AddPolicyRange"
((ptr uint16_t) @-> uint32_t @-> (ptr uint16_t) @-> (ptr void) @-> returning uint32_t)
(* ServerIpAddress : LPWSTR optional -> (ptr uint16_t) *)
(* SubnetAddress : DWORD -> uint32_t *)
(* PolicyName : LPWSTR -> (ptr uint16_t) *)
(* Range : DHCP_IP_RANGE* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library dhcpsapi (t "DHCPSAPI.dll"))
(cffi:use-foreign-library dhcpsapi)
(cffi:defcfun ("DhcpV4AddPolicyRange" dhcp-v4-add-policy-range :convention :stdcall) :uint32
(server-ip-address (:string :encoding :utf-16le)) ; LPWSTR optional
(subnet-address :uint32) ; DWORD
(policy-name (:string :encoding :utf-16le)) ; LPWSTR
(range :pointer)) ; DHCP_IP_RANGE*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DhcpV4AddPolicyRange = Win32::API::More->new('DHCPSAPI',
'DWORD DhcpV4AddPolicyRange(LPCWSTR ServerIpAddress, DWORD SubnetAddress, LPCWSTR PolicyName, LPVOID Range)');
# my $ret = $DhcpV4AddPolicyRange->Call($ServerIpAddress, $SubnetAddress, $PolicyName, $Range);
# ServerIpAddress : LPWSTR optional -> LPCWSTR
# SubnetAddress : DWORD -> DWORD
# PolicyName : LPWSTR -> LPCWSTR
# Range : DHCP_IP_RANGE* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型