Win32 API 日本語リファレンス
ホームNetworkManagement.Dhcp › DhcpServerSetConfigV4

DhcpServerSetConfigV4

関数
DHCPサーバーのV4拡張の構成パラメータを設定する。
DLLDHCPSAPI.dll呼出規約winapi対応OSwindowsserver2008

シグネチャ

// DHCPSAPI.dll
#include <windows.h>

DWORD DhcpServerSetConfigV4(
    LPCWSTR ServerIpAddress,   // optional
    DWORD FieldsToSet,
    DHCP_SERVER_CONFIG_INFO_V4* ConfigInfo
);

パラメーター

名前方向
ServerIpAddressLPCWSTRinoptional
FieldsToSetDWORDin
ConfigInfoDHCP_SERVER_CONFIG_INFO_V4*inout

戻り値の型: DWORD

各言語での呼び出し定義

// DHCPSAPI.dll
#include <windows.h>

DWORD DhcpServerSetConfigV4(
    LPCWSTR ServerIpAddress,   // optional
    DWORD FieldsToSet,
    DHCP_SERVER_CONFIG_INFO_V4* ConfigInfo
);
[DllImport("DHCPSAPI.dll", ExactSpelling = true)]
static extern uint DhcpServerSetConfigV4(
    [MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress,   // LPCWSTR optional
    uint FieldsToSet,   // DWORD
    IntPtr ConfigInfo   // DHCP_SERVER_CONFIG_INFO_V4* in/out
);
<DllImport("DHCPSAPI.dll", ExactSpelling:=True)>
Public Shared Function DhcpServerSetConfigV4(
    <MarshalAs(UnmanagedType.LPWStr)> ServerIpAddress As String,   ' LPCWSTR optional
    FieldsToSet As UInteger,   ' DWORD
    ConfigInfo As IntPtr   ' DHCP_SERVER_CONFIG_INFO_V4* in/out
) As UInteger
End Function
' ServerIpAddress : LPCWSTR optional
' FieldsToSet : DWORD
' ConfigInfo : DHCP_SERVER_CONFIG_INFO_V4* in/out
Declare PtrSafe Function DhcpServerSetConfigV4 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

DhcpServerSetConfigV4 = ctypes.windll.dhcpsapi.DhcpServerSetConfigV4
DhcpServerSetConfigV4.restype = wintypes.DWORD
DhcpServerSetConfigV4.argtypes = [
    wintypes.LPCWSTR,  # ServerIpAddress : LPCWSTR optional
    wintypes.DWORD,  # FieldsToSet : DWORD
    ctypes.c_void_p,  # ConfigInfo : DHCP_SERVER_CONFIG_INFO_V4* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('DHCPSAPI.dll')
DhcpServerSetConfigV4 = Fiddle::Function.new(
  lib['DhcpServerSetConfigV4'],
  [
    Fiddle::TYPE_VOIDP,  # ServerIpAddress : LPCWSTR optional
    -Fiddle::TYPE_INT,  # FieldsToSet : DWORD
    Fiddle::TYPE_VOIDP,  # ConfigInfo : DHCP_SERVER_CONFIG_INFO_V4* in/out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "dhcpsapi")]
extern "system" {
    fn DhcpServerSetConfigV4(
        ServerIpAddress: *const u16,  // LPCWSTR optional
        FieldsToSet: u32,  // DWORD
        ConfigInfo: *mut DHCP_SERVER_CONFIG_INFO_V4  // DHCP_SERVER_CONFIG_INFO_V4* in/out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("DHCPSAPI.dll")]
public static extern uint DhcpServerSetConfigV4([MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress, uint FieldsToSet, IntPtr ConfigInfo);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DHCPSAPI_DhcpServerSetConfigV4' -Namespace Win32 -PassThru
# $api::DhcpServerSetConfigV4(ServerIpAddress, FieldsToSet, ConfigInfo)
#uselib "DHCPSAPI.dll"
#func global DhcpServerSetConfigV4 "DhcpServerSetConfigV4" sptr, sptr, sptr
; DhcpServerSetConfigV4 ServerIpAddress, FieldsToSet, varptr(ConfigInfo)   ; 戻り値は stat
; ServerIpAddress : LPCWSTR optional -> "sptr"
; FieldsToSet : DWORD -> "sptr"
; ConfigInfo : DHCP_SERVER_CONFIG_INFO_V4* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "DHCPSAPI.dll"
#cfunc global DhcpServerSetConfigV4 "DhcpServerSetConfigV4" wstr, int, var
; res = DhcpServerSetConfigV4(ServerIpAddress, FieldsToSet, ConfigInfo)
; ServerIpAddress : LPCWSTR optional -> "wstr"
; FieldsToSet : DWORD -> "int"
; ConfigInfo : DHCP_SERVER_CONFIG_INFO_V4* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD DhcpServerSetConfigV4(LPCWSTR ServerIpAddress, DWORD FieldsToSet, DHCP_SERVER_CONFIG_INFO_V4* ConfigInfo)
#uselib "DHCPSAPI.dll"
#cfunc global DhcpServerSetConfigV4 "DhcpServerSetConfigV4" wstr, int, var
; res = DhcpServerSetConfigV4(ServerIpAddress, FieldsToSet, ConfigInfo)
; ServerIpAddress : LPCWSTR optional -> "wstr"
; FieldsToSet : DWORD -> "int"
; ConfigInfo : DHCP_SERVER_CONFIG_INFO_V4* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
	procDhcpServerSetConfigV4 = dhcpsapi.NewProc("DhcpServerSetConfigV4")
)

// ServerIpAddress (LPCWSTR optional), FieldsToSet (DWORD), ConfigInfo (DHCP_SERVER_CONFIG_INFO_V4* in/out)
r1, _, err := procDhcpServerSetConfigV4.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ServerIpAddress))),
	uintptr(FieldsToSet),
	uintptr(ConfigInfo),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function DhcpServerSetConfigV4(
  ServerIpAddress: PWideChar;   // LPCWSTR optional
  FieldsToSet: DWORD;   // DWORD
  ConfigInfo: Pointer   // DHCP_SERVER_CONFIG_INFO_V4* in/out
): DWORD; stdcall;
  external 'DHCPSAPI.dll' name 'DhcpServerSetConfigV4';
result := DllCall("DHCPSAPI\DhcpServerSetConfigV4"
    , "WStr", ServerIpAddress   ; LPCWSTR optional
    , "UInt", FieldsToSet   ; DWORD
    , "Ptr", ConfigInfo   ; DHCP_SERVER_CONFIG_INFO_V4* in/out
    , "UInt")   ; return: DWORD
●DhcpServerSetConfigV4(ServerIpAddress, FieldsToSet, ConfigInfo) = DLL("DHCPSAPI.dll", "dword DhcpServerSetConfigV4(char*, dword, void*)")
# 呼び出し: DhcpServerSetConfigV4(ServerIpAddress, FieldsToSet, ConfigInfo)
# ServerIpAddress : LPCWSTR optional -> "char*"
# FieldsToSet : DWORD -> "dword"
# ConfigInfo : DHCP_SERVER_CONFIG_INFO_V4* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。