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

DhcpServerQueryAttribute

関数
DHCPサーバーの指定属性値を照会する。
DLLDHCPSAPI.dll呼出規約winapi対応OSwindowsserver2008

シグネチャ

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

DWORD DhcpServerQueryAttribute(
    LPWSTR ServerIpAddr,   // optional
    DWORD dwReserved,
    DWORD DhcpAttribId,
    DHCP_ATTRIB** pDhcpAttrib
);

パラメーター

名前方向
ServerIpAddrLPWSTRinoptional
dwReservedDWORDin
DhcpAttribIdDWORDin
pDhcpAttribDHCP_ATTRIB**inout

戻り値の型: DWORD

各言語での呼び出し定義

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

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

DhcpServerQueryAttribute = ctypes.windll.dhcpsapi.DhcpServerQueryAttribute
DhcpServerQueryAttribute.restype = wintypes.DWORD
DhcpServerQueryAttribute.argtypes = [
    wintypes.LPCWSTR,  # ServerIpAddr : LPWSTR optional
    wintypes.DWORD,  # dwReserved : DWORD
    wintypes.DWORD,  # DhcpAttribId : DWORD
    ctypes.c_void_p,  # pDhcpAttrib : DHCP_ATTRIB** in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
	procDhcpServerQueryAttribute = dhcpsapi.NewProc("DhcpServerQueryAttribute")
)

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