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

DhcpV4GetClientInfo

関数
検索条件に一致するIPv4 DHCPクライアントの情報を取得する。
DLLDHCPSAPI.dll呼出規約winapi対応OSwindowsserver2012

シグネチャ

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

DWORD DhcpV4GetClientInfo(
    LPCWSTR ServerIpAddress,   // optional
    const DHCP_SEARCH_INFO* SearchInfo,
    DHCP_CLIENT_INFO_PB** ClientInfo
);

パラメーター

名前方向
ServerIpAddressLPCWSTRinoptional
SearchInfoDHCP_SEARCH_INFO*in
ClientInfoDHCP_CLIENT_INFO_PB**out

戻り値の型: DWORD

各言語での呼び出し定義

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

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

DhcpV4GetClientInfo = ctypes.windll.dhcpsapi.DhcpV4GetClientInfo
DhcpV4GetClientInfo.restype = wintypes.DWORD
DhcpV4GetClientInfo.argtypes = [
    wintypes.LPCWSTR,  # ServerIpAddress : LPCWSTR optional
    ctypes.c_void_p,  # SearchInfo : DHCP_SEARCH_INFO*
    ctypes.c_void_p,  # ClientInfo : DHCP_CLIENT_INFO_PB** out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
	procDhcpV4GetClientInfo = dhcpsapi.NewProc("DhcpV4GetClientInfo")
)

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