ホーム › NetworkManagement.Dhcp › DhcpServerQueryAttributes
DhcpServerQueryAttributes
関数DHCPサーバーの複数の属性値をまとめて照会する。
シグネチャ
// DHCPSAPI.dll
#include <windows.h>
DWORD DhcpServerQueryAttributes(
LPWSTR ServerIpAddr, // optional
DWORD dwReserved,
DWORD dwAttribCount,
DWORD* pDhcpAttribs,
DHCP_ATTRIB_ARRAY** pDhcpAttribArr
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| ServerIpAddr | LPWSTR | inoptional |
| dwReserved | DWORD | in |
| dwAttribCount | DWORD | in |
| pDhcpAttribs | DWORD* | inout |
| pDhcpAttribArr | DHCP_ATTRIB_ARRAY** | inout |
戻り値の型: DWORD
各言語での呼び出し定義
// DHCPSAPI.dll
#include <windows.h>
DWORD DhcpServerQueryAttributes(
LPWSTR ServerIpAddr, // optional
DWORD dwReserved,
DWORD dwAttribCount,
DWORD* pDhcpAttribs,
DHCP_ATTRIB_ARRAY** pDhcpAttribArr
);[DllImport("DHCPSAPI.dll", ExactSpelling = true)]
static extern uint DhcpServerQueryAttributes(
[MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddr, // LPWSTR optional
uint dwReserved, // DWORD
uint dwAttribCount, // DWORD
ref uint pDhcpAttribs, // DWORD* in/out
IntPtr pDhcpAttribArr // DHCP_ATTRIB_ARRAY** in/out
);<DllImport("DHCPSAPI.dll", ExactSpelling:=True)>
Public Shared Function DhcpServerQueryAttributes(
<MarshalAs(UnmanagedType.LPWStr)> ServerIpAddr As String, ' LPWSTR optional
dwReserved As UInteger, ' DWORD
dwAttribCount As UInteger, ' DWORD
ByRef pDhcpAttribs As UInteger, ' DWORD* in/out
pDhcpAttribArr As IntPtr ' DHCP_ATTRIB_ARRAY** in/out
) As UInteger
End Function' ServerIpAddr : LPWSTR optional
' dwReserved : DWORD
' dwAttribCount : DWORD
' pDhcpAttribs : DWORD* in/out
' pDhcpAttribArr : DHCP_ATTRIB_ARRAY** in/out
Declare PtrSafe Function DhcpServerQueryAttributes Lib "dhcpsapi" ( _
ByVal ServerIpAddr As LongPtr, _
ByVal dwReserved As Long, _
ByVal dwAttribCount As Long, _
ByRef pDhcpAttribs As Long, _
ByVal pDhcpAttribArr As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DhcpServerQueryAttributes = ctypes.windll.dhcpsapi.DhcpServerQueryAttributes
DhcpServerQueryAttributes.restype = wintypes.DWORD
DhcpServerQueryAttributes.argtypes = [
wintypes.LPCWSTR, # ServerIpAddr : LPWSTR optional
wintypes.DWORD, # dwReserved : DWORD
wintypes.DWORD, # dwAttribCount : DWORD
ctypes.POINTER(wintypes.DWORD), # pDhcpAttribs : DWORD* in/out
ctypes.c_void_p, # pDhcpAttribArr : DHCP_ATTRIB_ARRAY** in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('DHCPSAPI.dll')
DhcpServerQueryAttributes = Fiddle::Function.new(
lib['DhcpServerQueryAttributes'],
[
Fiddle::TYPE_VOIDP, # ServerIpAddr : LPWSTR optional
-Fiddle::TYPE_INT, # dwReserved : DWORD
-Fiddle::TYPE_INT, # dwAttribCount : DWORD
Fiddle::TYPE_VOIDP, # pDhcpAttribs : DWORD* in/out
Fiddle::TYPE_VOIDP, # pDhcpAttribArr : DHCP_ATTRIB_ARRAY** in/out
],
-Fiddle::TYPE_INT)#[link(name = "dhcpsapi")]
extern "system" {
fn DhcpServerQueryAttributes(
ServerIpAddr: *mut u16, // LPWSTR optional
dwReserved: u32, // DWORD
dwAttribCount: u32, // DWORD
pDhcpAttribs: *mut u32, // DWORD* in/out
pDhcpAttribArr: *mut *mut DHCP_ATTRIB_ARRAY // DHCP_ATTRIB_ARRAY** in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("DHCPSAPI.dll")]
public static extern uint DhcpServerQueryAttributes([MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddr, uint dwReserved, uint dwAttribCount, ref uint pDhcpAttribs, IntPtr pDhcpAttribArr);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DHCPSAPI_DhcpServerQueryAttributes' -Namespace Win32 -PassThru
# $api::DhcpServerQueryAttributes(ServerIpAddr, dwReserved, dwAttribCount, pDhcpAttribs, pDhcpAttribArr)#uselib "DHCPSAPI.dll"
#func global DhcpServerQueryAttributes "DhcpServerQueryAttributes" sptr, sptr, sptr, sptr, sptr
; DhcpServerQueryAttributes ServerIpAddr, dwReserved, dwAttribCount, varptr(pDhcpAttribs), varptr(pDhcpAttribArr) ; 戻り値は stat
; ServerIpAddr : LPWSTR optional -> "sptr"
; dwReserved : DWORD -> "sptr"
; dwAttribCount : DWORD -> "sptr"
; pDhcpAttribs : DWORD* in/out -> "sptr"
; pDhcpAttribArr : DHCP_ATTRIB_ARRAY** in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "DHCPSAPI.dll" #cfunc global DhcpServerQueryAttributes "DhcpServerQueryAttributes" wstr, int, int, var, var ; res = DhcpServerQueryAttributes(ServerIpAddr, dwReserved, dwAttribCount, pDhcpAttribs, pDhcpAttribArr) ; ServerIpAddr : LPWSTR optional -> "wstr" ; dwReserved : DWORD -> "int" ; dwAttribCount : DWORD -> "int" ; pDhcpAttribs : DWORD* in/out -> "var" ; pDhcpAttribArr : DHCP_ATTRIB_ARRAY** in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "DHCPSAPI.dll" #cfunc global DhcpServerQueryAttributes "DhcpServerQueryAttributes" wstr, int, int, sptr, sptr ; res = DhcpServerQueryAttributes(ServerIpAddr, dwReserved, dwAttribCount, varptr(pDhcpAttribs), varptr(pDhcpAttribArr)) ; ServerIpAddr : LPWSTR optional -> "wstr" ; dwReserved : DWORD -> "int" ; dwAttribCount : DWORD -> "int" ; pDhcpAttribs : DWORD* in/out -> "sptr" ; pDhcpAttribArr : DHCP_ATTRIB_ARRAY** in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD DhcpServerQueryAttributes(LPWSTR ServerIpAddr, DWORD dwReserved, DWORD dwAttribCount, DWORD* pDhcpAttribs, DHCP_ATTRIB_ARRAY** pDhcpAttribArr) #uselib "DHCPSAPI.dll" #cfunc global DhcpServerQueryAttributes "DhcpServerQueryAttributes" wstr, int, int, var, var ; res = DhcpServerQueryAttributes(ServerIpAddr, dwReserved, dwAttribCount, pDhcpAttribs, pDhcpAttribArr) ; ServerIpAddr : LPWSTR optional -> "wstr" ; dwReserved : DWORD -> "int" ; dwAttribCount : DWORD -> "int" ; pDhcpAttribs : DWORD* in/out -> "var" ; pDhcpAttribArr : DHCP_ATTRIB_ARRAY** in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD DhcpServerQueryAttributes(LPWSTR ServerIpAddr, DWORD dwReserved, DWORD dwAttribCount, DWORD* pDhcpAttribs, DHCP_ATTRIB_ARRAY** pDhcpAttribArr) #uselib "DHCPSAPI.dll" #cfunc global DhcpServerQueryAttributes "DhcpServerQueryAttributes" wstr, int, int, intptr, intptr ; res = DhcpServerQueryAttributes(ServerIpAddr, dwReserved, dwAttribCount, varptr(pDhcpAttribs), varptr(pDhcpAttribArr)) ; ServerIpAddr : LPWSTR optional -> "wstr" ; dwReserved : DWORD -> "int" ; dwAttribCount : DWORD -> "int" ; pDhcpAttribs : DWORD* in/out -> "intptr" ; pDhcpAttribArr : DHCP_ATTRIB_ARRAY** in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
procDhcpServerQueryAttributes = dhcpsapi.NewProc("DhcpServerQueryAttributes")
)
// ServerIpAddr (LPWSTR optional), dwReserved (DWORD), dwAttribCount (DWORD), pDhcpAttribs (DWORD* in/out), pDhcpAttribArr (DHCP_ATTRIB_ARRAY** in/out)
r1, _, err := procDhcpServerQueryAttributes.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ServerIpAddr))),
uintptr(dwReserved),
uintptr(dwAttribCount),
uintptr(pDhcpAttribs),
uintptr(pDhcpAttribArr),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction DhcpServerQueryAttributes(
ServerIpAddr: PWideChar; // LPWSTR optional
dwReserved: DWORD; // DWORD
dwAttribCount: DWORD; // DWORD
pDhcpAttribs: Pointer; // DWORD* in/out
pDhcpAttribArr: Pointer // DHCP_ATTRIB_ARRAY** in/out
): DWORD; stdcall;
external 'DHCPSAPI.dll' name 'DhcpServerQueryAttributes';result := DllCall("DHCPSAPI\DhcpServerQueryAttributes"
, "WStr", ServerIpAddr ; LPWSTR optional
, "UInt", dwReserved ; DWORD
, "UInt", dwAttribCount ; DWORD
, "Ptr", pDhcpAttribs ; DWORD* in/out
, "Ptr", pDhcpAttribArr ; DHCP_ATTRIB_ARRAY** in/out
, "UInt") ; return: DWORD●DhcpServerQueryAttributes(ServerIpAddr, dwReserved, dwAttribCount, pDhcpAttribs, pDhcpAttribArr) = DLL("DHCPSAPI.dll", "dword DhcpServerQueryAttributes(char*, dword, dword, void*, void*)")
# 呼び出し: DhcpServerQueryAttributes(ServerIpAddr, dwReserved, dwAttribCount, pDhcpAttribs, pDhcpAttribArr)
# ServerIpAddr : LPWSTR optional -> "char*"
# dwReserved : DWORD -> "dword"
# dwAttribCount : DWORD -> "dword"
# pDhcpAttribs : DWORD* in/out -> "void*"
# pDhcpAttribArr : DHCP_ATTRIB_ARRAY** in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。