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