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