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

DhcpSetSubnetInfo

関数
DHCPサーバーの指定サブネットの情報を設定する。
DLLDHCPSAPI.dll呼出規約winapi対応OSwindowsserver2000

シグネチャ

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

DWORD DhcpSetSubnetInfo(
    LPCWSTR ServerIpAddress,   // optional
    DWORD SubnetAddress,
    const DHCP_SUBNET_INFO* SubnetInfo
);

パラメーター

名前方向
ServerIpAddressLPCWSTRinoptional
SubnetAddressDWORDin
SubnetInfoDHCP_SUBNET_INFO*in

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD DhcpSetSubnetInfo(
    LPCWSTR ServerIpAddress,   // optional
    DWORD SubnetAddress,
    const DHCP_SUBNET_INFO* SubnetInfo
);
[DllImport("DHCPSAPI.dll", ExactSpelling = true)]
static extern uint DhcpSetSubnetInfo(
    [MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress,   // LPCWSTR optional
    uint SubnetAddress,   // DWORD
    IntPtr SubnetInfo   // DHCP_SUBNET_INFO*
);
<DllImport("DHCPSAPI.dll", ExactSpelling:=True)>
Public Shared Function DhcpSetSubnetInfo(
    <MarshalAs(UnmanagedType.LPWStr)> ServerIpAddress As String,   ' LPCWSTR optional
    SubnetAddress As UInteger,   ' DWORD
    SubnetInfo As IntPtr   ' DHCP_SUBNET_INFO*
) As UInteger
End Function
' ServerIpAddress : LPCWSTR optional
' SubnetAddress : DWORD
' SubnetInfo : DHCP_SUBNET_INFO*
Declare PtrSafe Function DhcpSetSubnetInfo Lib "dhcpsapi" ( _
    ByVal ServerIpAddress As LongPtr, _
    ByVal SubnetAddress As Long, _
    ByVal SubnetInfo As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DhcpSetSubnetInfo = ctypes.windll.dhcpsapi.DhcpSetSubnetInfo
DhcpSetSubnetInfo.restype = wintypes.DWORD
DhcpSetSubnetInfo.argtypes = [
    wintypes.LPCWSTR,  # ServerIpAddress : LPCWSTR optional
    wintypes.DWORD,  # SubnetAddress : DWORD
    ctypes.c_void_p,  # SubnetInfo : DHCP_SUBNET_INFO*
]
require 'fiddle'
require 'fiddle/import'

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

var (
	dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
	procDhcpSetSubnetInfo = dhcpsapi.NewProc("DhcpSetSubnetInfo")
)

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