ホーム › NetworkManagement.Dhcp › DhcpAddSubnetElementV6
DhcpAddSubnetElementV6
関数DHCPのIPv6サブネットに範囲や除外などの要素を追加する。
シグネチャ
// DHCPSAPI.dll
#include <windows.h>
DWORD DhcpAddSubnetElementV6(
LPWSTR ServerIpAddress, // optional
DHCP_IPV6_ADDRESS SubnetAddress,
DHCP_SUBNET_ELEMENT_DATA_V6* AddElementInfo
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| ServerIpAddress | LPWSTR | inoptional |
| SubnetAddress | DHCP_IPV6_ADDRESS | in |
| AddElementInfo | DHCP_SUBNET_ELEMENT_DATA_V6* | inout |
戻り値の型: DWORD
各言語での呼び出し定義
// DHCPSAPI.dll
#include <windows.h>
DWORD DhcpAddSubnetElementV6(
LPWSTR ServerIpAddress, // optional
DHCP_IPV6_ADDRESS SubnetAddress,
DHCP_SUBNET_ELEMENT_DATA_V6* AddElementInfo
);[DllImport("DHCPSAPI.dll", ExactSpelling = true)]
static extern uint DhcpAddSubnetElementV6(
[MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress, // LPWSTR optional
DHCP_IPV6_ADDRESS SubnetAddress, // DHCP_IPV6_ADDRESS
IntPtr AddElementInfo // DHCP_SUBNET_ELEMENT_DATA_V6* in/out
);<DllImport("DHCPSAPI.dll", ExactSpelling:=True)>
Public Shared Function DhcpAddSubnetElementV6(
<MarshalAs(UnmanagedType.LPWStr)> ServerIpAddress As String, ' LPWSTR optional
SubnetAddress As DHCP_IPV6_ADDRESS, ' DHCP_IPV6_ADDRESS
AddElementInfo As IntPtr ' DHCP_SUBNET_ELEMENT_DATA_V6* in/out
) As UInteger
End Function' ServerIpAddress : LPWSTR optional
' SubnetAddress : DHCP_IPV6_ADDRESS
' AddElementInfo : DHCP_SUBNET_ELEMENT_DATA_V6* in/out
Declare PtrSafe Function DhcpAddSubnetElementV6 Lib "dhcpsapi" ( _
ByVal ServerIpAddress As LongPtr, _
ByVal SubnetAddress As LongPtr, _
ByVal AddElementInfo As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DhcpAddSubnetElementV6 = ctypes.windll.dhcpsapi.DhcpAddSubnetElementV6
DhcpAddSubnetElementV6.restype = wintypes.DWORD
DhcpAddSubnetElementV6.argtypes = [
wintypes.LPCWSTR, # ServerIpAddress : LPWSTR optional
DHCP_IPV6_ADDRESS, # SubnetAddress : DHCP_IPV6_ADDRESS
ctypes.c_void_p, # AddElementInfo : DHCP_SUBNET_ELEMENT_DATA_V6* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('DHCPSAPI.dll')
DhcpAddSubnetElementV6 = Fiddle::Function.new(
lib['DhcpAddSubnetElementV6'],
[
Fiddle::TYPE_VOIDP, # ServerIpAddress : LPWSTR optional
Fiddle::TYPE_VOIDP, # SubnetAddress : DHCP_IPV6_ADDRESS
Fiddle::TYPE_VOIDP, # AddElementInfo : DHCP_SUBNET_ELEMENT_DATA_V6* in/out
],
-Fiddle::TYPE_INT)#[link(name = "dhcpsapi")]
extern "system" {
fn DhcpAddSubnetElementV6(
ServerIpAddress: *mut u16, // LPWSTR optional
SubnetAddress: DHCP_IPV6_ADDRESS, // DHCP_IPV6_ADDRESS
AddElementInfo: *mut DHCP_SUBNET_ELEMENT_DATA_V6 // DHCP_SUBNET_ELEMENT_DATA_V6* in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("DHCPSAPI.dll")]
public static extern uint DhcpAddSubnetElementV6([MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress, DHCP_IPV6_ADDRESS SubnetAddress, IntPtr AddElementInfo);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DHCPSAPI_DhcpAddSubnetElementV6' -Namespace Win32 -PassThru
# $api::DhcpAddSubnetElementV6(ServerIpAddress, SubnetAddress, AddElementInfo)#uselib "DHCPSAPI.dll"
#func global DhcpAddSubnetElementV6 "DhcpAddSubnetElementV6" sptr, sptr, sptr
; DhcpAddSubnetElementV6 ServerIpAddress, SubnetAddress, varptr(AddElementInfo) ; 戻り値は stat
; ServerIpAddress : LPWSTR optional -> "sptr"
; SubnetAddress : DHCP_IPV6_ADDRESS -> "sptr"
; AddElementInfo : DHCP_SUBNET_ELEMENT_DATA_V6* in/out -> "sptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "DHCPSAPI.dll" #cfunc global DhcpAddSubnetElementV6 "DhcpAddSubnetElementV6" wstr, int, var ; res = DhcpAddSubnetElementV6(ServerIpAddress, SubnetAddress, AddElementInfo) ; ServerIpAddress : LPWSTR optional -> "wstr" ; SubnetAddress : DHCP_IPV6_ADDRESS -> "int" ; AddElementInfo : DHCP_SUBNET_ELEMENT_DATA_V6* in/out -> "var" ; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。 ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "DHCPSAPI.dll" #cfunc global DhcpAddSubnetElementV6 "DhcpAddSubnetElementV6" wstr, int, sptr ; res = DhcpAddSubnetElementV6(ServerIpAddress, SubnetAddress, varptr(AddElementInfo)) ; ServerIpAddress : LPWSTR optional -> "wstr" ; SubnetAddress : DHCP_IPV6_ADDRESS -> "int" ; AddElementInfo : DHCP_SUBNET_ELEMENT_DATA_V6* in/out -> "sptr" ; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。 ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD DhcpAddSubnetElementV6(LPWSTR ServerIpAddress, DHCP_IPV6_ADDRESS SubnetAddress, DHCP_SUBNET_ELEMENT_DATA_V6* AddElementInfo) #uselib "DHCPSAPI.dll" #cfunc global DhcpAddSubnetElementV6 "DhcpAddSubnetElementV6" wstr, int, var ; res = DhcpAddSubnetElementV6(ServerIpAddress, SubnetAddress, AddElementInfo) ; ServerIpAddress : LPWSTR optional -> "wstr" ; SubnetAddress : DHCP_IPV6_ADDRESS -> "int" ; AddElementInfo : DHCP_SUBNET_ELEMENT_DATA_V6* in/out -> "var" ; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。 ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD DhcpAddSubnetElementV6(LPWSTR ServerIpAddress, DHCP_IPV6_ADDRESS SubnetAddress, DHCP_SUBNET_ELEMENT_DATA_V6* AddElementInfo) #uselib "DHCPSAPI.dll" #cfunc global DhcpAddSubnetElementV6 "DhcpAddSubnetElementV6" wstr, int, intptr ; res = DhcpAddSubnetElementV6(ServerIpAddress, SubnetAddress, varptr(AddElementInfo)) ; ServerIpAddress : LPWSTR optional -> "wstr" ; SubnetAddress : DHCP_IPV6_ADDRESS -> "int" ; AddElementInfo : DHCP_SUBNET_ELEMENT_DATA_V6* in/out -> "intptr" ; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。 ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
procDhcpAddSubnetElementV6 = dhcpsapi.NewProc("DhcpAddSubnetElementV6")
)
// ServerIpAddress (LPWSTR optional), SubnetAddress (DHCP_IPV6_ADDRESS), AddElementInfo (DHCP_SUBNET_ELEMENT_DATA_V6* in/out)
r1, _, err := procDhcpAddSubnetElementV6.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ServerIpAddress))),
uintptr(SubnetAddress),
uintptr(AddElementInfo),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction DhcpAddSubnetElementV6(
ServerIpAddress: PWideChar; // LPWSTR optional
SubnetAddress: DHCP_IPV6_ADDRESS; // DHCP_IPV6_ADDRESS
AddElementInfo: Pointer // DHCP_SUBNET_ELEMENT_DATA_V6* in/out
): DWORD; stdcall;
external 'DHCPSAPI.dll' name 'DhcpAddSubnetElementV6';result := DllCall("DHCPSAPI\DhcpAddSubnetElementV6"
, "WStr", ServerIpAddress ; LPWSTR optional
, "Ptr", SubnetAddress ; DHCP_IPV6_ADDRESS
, "Ptr", AddElementInfo ; DHCP_SUBNET_ELEMENT_DATA_V6* in/out
, "UInt") ; return: DWORD●DhcpAddSubnetElementV6(ServerIpAddress, SubnetAddress, AddElementInfo) = DLL("DHCPSAPI.dll", "dword DhcpAddSubnetElementV6(char*, void*, void*)")
# 呼び出し: DhcpAddSubnetElementV6(ServerIpAddress, SubnetAddress, AddElementInfo)
# ServerIpAddress : LPWSTR optional -> "char*"
# SubnetAddress : DHCP_IPV6_ADDRESS -> "void*"
# AddElementInfo : DHCP_SUBNET_ELEMENT_DATA_V6* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。