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