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