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

DhcpCreateOption

関数
DHCPサーバーに新しいオプション定義を作成する。
DLLDHCPSAPI.dll呼出規約winapi対応OSwindowsserver2008

シグネチャ

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

DWORD DhcpCreateOption(
    LPCWSTR ServerIpAddress,   // optional
    DWORD OptionID,
    const DHCP_OPTION* OptionInfo
);

パラメーター

名前方向
ServerIpAddressLPCWSTRinoptional
OptionIDDWORDin
OptionInfoDHCP_OPTION*in

戻り値の型: DWORD

各言語での呼び出し定義

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

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

DhcpCreateOption = ctypes.windll.dhcpsapi.DhcpCreateOption
DhcpCreateOption.restype = wintypes.DWORD
DhcpCreateOption.argtypes = [
    wintypes.LPCWSTR,  # ServerIpAddress : LPCWSTR optional
    wintypes.DWORD,  # OptionID : DWORD
    ctypes.c_void_p,  # OptionInfo : DHCP_OPTION*
]
require 'fiddle'
require 'fiddle/import'

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

var (
	dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
	procDhcpCreateOption = dhcpsapi.NewProc("DhcpCreateOption")
)

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