ホーム › NetworkManagement.Dhcp › DhcpV4GetClientInfo
DhcpV4GetClientInfo
関数検索条件に一致するIPv4 DHCPクライアントの情報を取得する。
シグネチャ
// DHCPSAPI.dll
#include <windows.h>
DWORD DhcpV4GetClientInfo(
LPCWSTR ServerIpAddress, // optional
const DHCP_SEARCH_INFO* SearchInfo,
DHCP_CLIENT_INFO_PB** ClientInfo
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ServerIpAddress | LPCWSTR | inoptional | 対象DHCPサーバーのIPアドレスを示すUnicode文字列。ローカルならNULL可。 |
| SearchInfo | DHCP_SEARCH_INFO* | in | 検索条件(IPアドレス・ハードウェアアドレス等)を指定するDHCP_SEARCH_INFO構造体へのポインタ。 |
| ClientInfo | DHCP_CLIENT_INFO_PB** | out | 取得したクライアント情報のDHCP_CLIENT_INFO_PBへのポインタを受け取る二重ポインタ。使用後は解放する。 |
戻り値の型: 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 方式にも切替可。#uselib "DHCPSAPI.dll" #cfunc global DhcpV4GetClientInfo "DhcpV4GetClientInfo" wstr, sptr, sptr ; res = DhcpV4GetClientInfo(ServerIpAddress, varptr(SearchInfo), varptr(ClientInfo)) ; ServerIpAddress : LPCWSTR optional -> "wstr" ; SearchInfo : DHCP_SEARCH_INFO* -> "sptr" ; ClientInfo : DHCP_CLIENT_INFO_PB** out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; DWORD DhcpV4GetClientInfo(LPCWSTR ServerIpAddress, DHCP_SEARCH_INFO* SearchInfo, DHCP_CLIENT_INFO_PB** ClientInfo) #uselib "DHCPSAPI.dll" #cfunc global DhcpV4GetClientInfo "DhcpV4GetClientInfo" wstr, intptr, intptr ; res = DhcpV4GetClientInfo(ServerIpAddress, varptr(SearchInfo), varptr(ClientInfo)) ; ServerIpAddress : LPCWSTR optional -> "wstr" ; SearchInfo : DHCP_SEARCH_INFO* -> "intptr" ; ClientInfo : DHCP_CLIENT_INFO_PB** out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // DWORDfunction 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)。const std = @import("std");
extern "dhcpsapi" fn DhcpV4GetClientInfo(
ServerIpAddress: [*c]const u16, // LPCWSTR optional
SearchInfo: [*c]DHCP_SEARCH_INFO, // DHCP_SEARCH_INFO*
ClientInfo: [*c][*c]DHCP_CLIENT_INFO_PB // DHCP_CLIENT_INFO_PB** out
) callconv(std.os.windows.WINAPI) u32;proc DhcpV4GetClientInfo(
ServerIpAddress: WideCString, # LPCWSTR optional
SearchInfo: ptr DHCP_SEARCH_INFO, # DHCP_SEARCH_INFO*
ClientInfo: ptr DHCP_CLIENT_INFO_PB # DHCP_CLIENT_INFO_PB** out
): uint32 {.importc: "DhcpV4GetClientInfo", stdcall, dynlib: "DHCPSAPI.dll".}pragma(lib, "dhcpsapi");
extern(Windows)
uint DhcpV4GetClientInfo(
const(wchar)* ServerIpAddress, // LPCWSTR optional
DHCP_SEARCH_INFO* SearchInfo, // DHCP_SEARCH_INFO*
DHCP_CLIENT_INFO_PB** ClientInfo // DHCP_CLIENT_INFO_PB** out
);ccall((:DhcpV4GetClientInfo, "DHCPSAPI.dll"), stdcall, UInt32,
(Cwstring, Ptr{DHCP_SEARCH_INFO}, Ptr{DHCP_CLIENT_INFO_PB}),
ServerIpAddress, SearchInfo, ClientInfo)
# ServerIpAddress : LPCWSTR optional -> Cwstring
# SearchInfo : DHCP_SEARCH_INFO* -> Ptr{DHCP_SEARCH_INFO}
# ClientInfo : DHCP_CLIENT_INFO_PB** out -> Ptr{DHCP_CLIENT_INFO_PB}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t DhcpV4GetClientInfo(
const uint16_t* ServerIpAddress,
void* SearchInfo,
void* ClientInfo);
]]
local dhcpsapi = ffi.load("dhcpsapi")
-- dhcpsapi.DhcpV4GetClientInfo(ServerIpAddress, SearchInfo, ClientInfo)
-- ServerIpAddress : LPCWSTR optional
-- SearchInfo : DHCP_SEARCH_INFO*
-- ClientInfo : DHCP_CLIENT_INFO_PB** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('DHCPSAPI.dll');
const DhcpV4GetClientInfo = lib.func('__stdcall', 'DhcpV4GetClientInfo', 'uint32_t', ['str16', 'void *', 'void *']);
// DhcpV4GetClientInfo(ServerIpAddress, SearchInfo, ClientInfo)
// ServerIpAddress : LPCWSTR optional -> 'str16'
// SearchInfo : DHCP_SEARCH_INFO* -> 'void *'
// ClientInfo : DHCP_CLIENT_INFO_PB** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("DHCPSAPI.dll", {
DhcpV4GetClientInfo: { parameters: ["buffer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.DhcpV4GetClientInfo(ServerIpAddress, SearchInfo, ClientInfo)
// ServerIpAddress : LPCWSTR optional -> "buffer"
// SearchInfo : DHCP_SEARCH_INFO* -> "pointer"
// ClientInfo : DHCP_CLIENT_INFO_PB** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t DhcpV4GetClientInfo(
const uint16_t* ServerIpAddress,
void* SearchInfo,
void* ClientInfo);
C, "DHCPSAPI.dll");
// $ffi->DhcpV4GetClientInfo(ServerIpAddress, SearchInfo, ClientInfo);
// ServerIpAddress : LPCWSTR optional
// SearchInfo : DHCP_SEARCH_INFO*
// ClientInfo : DHCP_CLIENT_INFO_PB** out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Dhcpsapi extends StdCallLibrary {
Dhcpsapi INSTANCE = Native.load("dhcpsapi", Dhcpsapi.class);
int DhcpV4GetClientInfo(
WString ServerIpAddress, // LPCWSTR optional
Pointer SearchInfo, // DHCP_SEARCH_INFO*
Pointer ClientInfo // DHCP_CLIENT_INFO_PB** out
);
}@[Link("dhcpsapi")]
lib LibDHCPSAPI
fun DhcpV4GetClientInfo = DhcpV4GetClientInfo(
ServerIpAddress : UInt16*, # LPCWSTR optional
SearchInfo : DHCP_SEARCH_INFO*, # DHCP_SEARCH_INFO*
ClientInfo : DHCP_CLIENT_INFO_PB** # DHCP_CLIENT_INFO_PB** out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DhcpV4GetClientInfoNative = Uint32 Function(Pointer<Utf16>, Pointer<Void>, Pointer<Void>);
typedef DhcpV4GetClientInfoDart = int Function(Pointer<Utf16>, Pointer<Void>, Pointer<Void>);
final DhcpV4GetClientInfo = DynamicLibrary.open('DHCPSAPI.dll')
.lookupFunction<DhcpV4GetClientInfoNative, DhcpV4GetClientInfoDart>('DhcpV4GetClientInfo');
// ServerIpAddress : LPCWSTR optional -> Pointer<Utf16>
// SearchInfo : DHCP_SEARCH_INFO* -> Pointer<Void>
// ClientInfo : DHCP_CLIENT_INFO_PB** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DhcpV4GetClientInfo"
c_DhcpV4GetClientInfo :: CWString -> Ptr () -> Ptr () -> IO Word32
-- ServerIpAddress : LPCWSTR optional -> CWString
-- SearchInfo : DHCP_SEARCH_INFO* -> Ptr ()
-- ClientInfo : DHCP_CLIENT_INFO_PB** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let dhcpv4getclientinfo =
foreign "DhcpV4GetClientInfo"
((ptr uint16_t) @-> (ptr void) @-> (ptr void) @-> returning uint32_t)
(* ServerIpAddress : LPCWSTR optional -> (ptr uint16_t) *)
(* SearchInfo : DHCP_SEARCH_INFO* -> (ptr void) *)
(* ClientInfo : DHCP_CLIENT_INFO_PB** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library dhcpsapi (t "DHCPSAPI.dll"))
(cffi:use-foreign-library dhcpsapi)
(cffi:defcfun ("DhcpV4GetClientInfo" dhcp-v4-get-client-info :convention :stdcall) :uint32
(server-ip-address (:string :encoding :utf-16le)) ; LPCWSTR optional
(search-info :pointer) ; DHCP_SEARCH_INFO*
(client-info :pointer)) ; DHCP_CLIENT_INFO_PB** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DhcpV4GetClientInfo = Win32::API::More->new('DHCPSAPI',
'DWORD DhcpV4GetClientInfo(LPCWSTR ServerIpAddress, LPVOID SearchInfo, LPVOID ClientInfo)');
# my $ret = $DhcpV4GetClientInfo->Call($ServerIpAddress, $SearchInfo, $ClientInfo);
# ServerIpAddress : LPCWSTR optional -> LPCWSTR
# SearchInfo : DHCP_SEARCH_INFO* -> LPVOID
# ClientInfo : DHCP_CLIENT_INFO_PB** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f DhcpV4GetClientInfoEx — 検索条件に一致するIPv4クライアント情報を拡張形式で取得する。