ホーム › 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 | 対象DHCPサーバーのIPアドレスを示すUnicode文字列。ローカルならNULL可。 |
| dwReserved | DWORD | in | 予約済みパラメーター。0を指定する。 |
| dwAttribCount | DWORD | in | 問い合わせる属性の個数。 |
| pDhcpAttribs | DWORD* | inout | 問い合わせる属性IDの配列へのポインタ。要素数はdwAttribCount。 |
| pDhcpAttribArr | DHCP_ATTRIB_ARRAY** | inout | 取得した属性値群のDHCP_ATTRIB_ARRAYへのポインタを受け取る二重ポインタ。使用後は解放する。 |
戻り値の型: 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)。const std = @import("std");
extern "dhcpsapi" fn DhcpServerQueryAttributes(
ServerIpAddr: [*c]const u16, // LPWSTR optional
dwReserved: u32, // DWORD
dwAttribCount: u32, // DWORD
pDhcpAttribs: [*c]u32, // DWORD* in/out
pDhcpAttribArr: [*c][*c]DHCP_ATTRIB_ARRAY // DHCP_ATTRIB_ARRAY** in/out
) callconv(std.os.windows.WINAPI) u32;proc DhcpServerQueryAttributes(
ServerIpAddr: WideCString, # LPWSTR optional
dwReserved: uint32, # DWORD
dwAttribCount: uint32, # DWORD
pDhcpAttribs: ptr uint32, # DWORD* in/out
pDhcpAttribArr: ptr DHCP_ATTRIB_ARRAY # DHCP_ATTRIB_ARRAY** in/out
): uint32 {.importc: "DhcpServerQueryAttributes", stdcall, dynlib: "DHCPSAPI.dll".}pragma(lib, "dhcpsapi");
extern(Windows)
uint DhcpServerQueryAttributes(
const(wchar)* ServerIpAddr, // LPWSTR optional
uint dwReserved, // DWORD
uint dwAttribCount, // DWORD
uint* pDhcpAttribs, // DWORD* in/out
DHCP_ATTRIB_ARRAY** pDhcpAttribArr // DHCP_ATTRIB_ARRAY** in/out
);ccall((:DhcpServerQueryAttributes, "DHCPSAPI.dll"), stdcall, UInt32,
(Cwstring, UInt32, UInt32, Ptr{UInt32}, Ptr{DHCP_ATTRIB_ARRAY}),
ServerIpAddr, dwReserved, dwAttribCount, pDhcpAttribs, pDhcpAttribArr)
# ServerIpAddr : LPWSTR optional -> Cwstring
# dwReserved : DWORD -> UInt32
# dwAttribCount : DWORD -> UInt32
# pDhcpAttribs : DWORD* in/out -> Ptr{UInt32}
# pDhcpAttribArr : DHCP_ATTRIB_ARRAY** in/out -> Ptr{DHCP_ATTRIB_ARRAY}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t DhcpServerQueryAttributes(
const uint16_t* ServerIpAddr,
uint32_t dwReserved,
uint32_t dwAttribCount,
uint32_t* pDhcpAttribs,
void* pDhcpAttribArr);
]]
local dhcpsapi = ffi.load("dhcpsapi")
-- dhcpsapi.DhcpServerQueryAttributes(ServerIpAddr, dwReserved, dwAttribCount, pDhcpAttribs, pDhcpAttribArr)
-- ServerIpAddr : LPWSTR optional
-- dwReserved : DWORD
-- dwAttribCount : DWORD
-- pDhcpAttribs : DWORD* in/out
-- pDhcpAttribArr : DHCP_ATTRIB_ARRAY** in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('DHCPSAPI.dll');
const DhcpServerQueryAttributes = lib.func('__stdcall', 'DhcpServerQueryAttributes', 'uint32_t', ['str16', 'uint32_t', 'uint32_t', 'uint32_t *', 'void *']);
// DhcpServerQueryAttributes(ServerIpAddr, dwReserved, dwAttribCount, pDhcpAttribs, pDhcpAttribArr)
// ServerIpAddr : LPWSTR optional -> 'str16'
// dwReserved : DWORD -> 'uint32_t'
// dwAttribCount : DWORD -> 'uint32_t'
// pDhcpAttribs : DWORD* in/out -> 'uint32_t *'
// pDhcpAttribArr : DHCP_ATTRIB_ARRAY** in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("DHCPSAPI.dll", {
DhcpServerQueryAttributes: { parameters: ["buffer", "u32", "u32", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.DhcpServerQueryAttributes(ServerIpAddr, dwReserved, dwAttribCount, pDhcpAttribs, pDhcpAttribArr)
// ServerIpAddr : LPWSTR optional -> "buffer"
// dwReserved : DWORD -> "u32"
// dwAttribCount : DWORD -> "u32"
// pDhcpAttribs : DWORD* in/out -> "pointer"
// pDhcpAttribArr : DHCP_ATTRIB_ARRAY** in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t DhcpServerQueryAttributes(
const uint16_t* ServerIpAddr,
uint32_t dwReserved,
uint32_t dwAttribCount,
uint32_t* pDhcpAttribs,
void* pDhcpAttribArr);
C, "DHCPSAPI.dll");
// $ffi->DhcpServerQueryAttributes(ServerIpAddr, dwReserved, dwAttribCount, pDhcpAttribs, pDhcpAttribArr);
// ServerIpAddr : LPWSTR optional
// dwReserved : DWORD
// dwAttribCount : DWORD
// pDhcpAttribs : DWORD* in/out
// pDhcpAttribArr : DHCP_ATTRIB_ARRAY** in/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 DhcpServerQueryAttributes(
WString ServerIpAddr, // LPWSTR optional
int dwReserved, // DWORD
int dwAttribCount, // DWORD
IntByReference pDhcpAttribs, // DWORD* in/out
Pointer pDhcpAttribArr // DHCP_ATTRIB_ARRAY** in/out
);
}@[Link("dhcpsapi")]
lib LibDHCPSAPI
fun DhcpServerQueryAttributes = DhcpServerQueryAttributes(
ServerIpAddr : UInt16*, # LPWSTR optional
dwReserved : UInt32, # DWORD
dwAttribCount : UInt32, # DWORD
pDhcpAttribs : UInt32*, # DWORD* in/out
pDhcpAttribArr : DHCP_ATTRIB_ARRAY** # DHCP_ATTRIB_ARRAY** in/out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DhcpServerQueryAttributesNative = Uint32 Function(Pointer<Utf16>, Uint32, Uint32, Pointer<Uint32>, Pointer<Void>);
typedef DhcpServerQueryAttributesDart = int Function(Pointer<Utf16>, int, int, Pointer<Uint32>, Pointer<Void>);
final DhcpServerQueryAttributes = DynamicLibrary.open('DHCPSAPI.dll')
.lookupFunction<DhcpServerQueryAttributesNative, DhcpServerQueryAttributesDart>('DhcpServerQueryAttributes');
// ServerIpAddr : LPWSTR optional -> Pointer<Utf16>
// dwReserved : DWORD -> Uint32
// dwAttribCount : DWORD -> Uint32
// pDhcpAttribs : DWORD* in/out -> Pointer<Uint32>
// pDhcpAttribArr : DHCP_ATTRIB_ARRAY** in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function 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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DhcpServerQueryAttributes"
c_DhcpServerQueryAttributes :: CWString -> Word32 -> Word32 -> Ptr Word32 -> Ptr () -> IO Word32
-- ServerIpAddr : LPWSTR optional -> CWString
-- dwReserved : DWORD -> Word32
-- dwAttribCount : DWORD -> Word32
-- pDhcpAttribs : DWORD* in/out -> Ptr Word32
-- pDhcpAttribArr : DHCP_ATTRIB_ARRAY** in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let dhcpserverqueryattributes =
foreign "DhcpServerQueryAttributes"
((ptr uint16_t) @-> uint32_t @-> uint32_t @-> (ptr uint32_t) @-> (ptr void) @-> returning uint32_t)
(* ServerIpAddr : LPWSTR optional -> (ptr uint16_t) *)
(* dwReserved : DWORD -> uint32_t *)
(* dwAttribCount : DWORD -> uint32_t *)
(* pDhcpAttribs : DWORD* in/out -> (ptr uint32_t) *)
(* pDhcpAttribArr : DHCP_ATTRIB_ARRAY** in/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 ("DhcpServerQueryAttributes" dhcp-server-query-attributes :convention :stdcall) :uint32
(server-ip-addr (:string :encoding :utf-16le)) ; LPWSTR optional
(dw-reserved :uint32) ; DWORD
(dw-attrib-count :uint32) ; DWORD
(p-dhcp-attribs :pointer) ; DWORD* in/out
(p-dhcp-attrib-arr :pointer)) ; DHCP_ATTRIB_ARRAY** in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DhcpServerQueryAttributes = Win32::API::More->new('DHCPSAPI',
'DWORD DhcpServerQueryAttributes(LPCWSTR ServerIpAddr, DWORD dwReserved, DWORD dwAttribCount, LPVOID pDhcpAttribs, LPVOID pDhcpAttribArr)');
# my $ret = $DhcpServerQueryAttributes->Call($ServerIpAddr, $dwReserved, $dwAttribCount, $pDhcpAttribs, $pDhcpAttribArr);
# ServerIpAddr : LPWSTR optional -> LPCWSTR
# dwReserved : DWORD -> DWORD
# dwAttribCount : DWORD -> DWORD
# pDhcpAttribs : DWORD* in/out -> LPVOID
# pDhcpAttribArr : DHCP_ATTRIB_ARRAY** in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型