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

DhcpGetOptionValue

関数
指定スコープのDHCPオプション値を取得する。
DLLDHCPSAPI.dll呼出規約winapi対応OSwindowsserver2000

シグネチャ

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

DWORD DhcpGetOptionValue(
    LPCWSTR ServerIpAddress,   // optional
    DWORD OptionID,
    const DHCP_OPTION_SCOPE_INFO* ScopeInfo,
    DHCP_OPTION_VALUE** OptionValue
);

パラメーター

名前方向
ServerIpAddressLPCWSTRinoptional
OptionIDDWORDin
ScopeInfoDHCP_OPTION_SCOPE_INFO*in
OptionValueDHCP_OPTION_VALUE**inout

戻り値の型: DWORD

各言語での呼び出し定義

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

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

DhcpGetOptionValue = ctypes.windll.dhcpsapi.DhcpGetOptionValue
DhcpGetOptionValue.restype = wintypes.DWORD
DhcpGetOptionValue.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_VALUE** in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
	procDhcpGetOptionValue = dhcpsapi.NewProc("DhcpGetOptionValue")
)

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