ホーム › NetworkManagement.Dhcp › DhcpServerQueryAttribute
DhcpServerQueryAttribute
関数DHCPサーバーの指定属性値を照会する。
シグネチャ
// DHCPSAPI.dll
#include <windows.h>
DWORD DhcpServerQueryAttribute(
LPWSTR ServerIpAddr, // optional
DWORD dwReserved,
DWORD DhcpAttribId,
DHCP_ATTRIB** pDhcpAttrib
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ServerIpAddr | LPWSTR | inoptional | 対象DHCPサーバーのIPアドレスを示すUnicode文字列。ローカルならNULL可。 |
| dwReserved | DWORD | in | 予約済みパラメーター。0を指定する。 |
| DhcpAttribId | DWORD | in | 問い合わせるサーバー属性の識別子(認可状態・動的BootP等)。 |
| pDhcpAttrib | DHCP_ATTRIB** | inout | 取得した属性値のDHCP_ATTRIBへのポインタを受け取る二重ポインタ。使用後は解放する。 |
戻り値の型: 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 方式にも切替可。#uselib "DHCPSAPI.dll" #cfunc global DhcpServerQueryAttribute "DhcpServerQueryAttribute" wstr, int, int, sptr ; res = DhcpServerQueryAttribute(ServerIpAddr, dwReserved, DhcpAttribId, varptr(pDhcpAttrib)) ; ServerIpAddr : LPWSTR optional -> "wstr" ; dwReserved : DWORD -> "int" ; DhcpAttribId : DWORD -> "int" ; pDhcpAttrib : DHCP_ATTRIB** in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; DWORD DhcpServerQueryAttribute(LPWSTR ServerIpAddr, DWORD dwReserved, DWORD DhcpAttribId, DHCP_ATTRIB** pDhcpAttrib) #uselib "DHCPSAPI.dll" #cfunc global DhcpServerQueryAttribute "DhcpServerQueryAttribute" wstr, int, int, intptr ; res = DhcpServerQueryAttribute(ServerIpAddr, dwReserved, DhcpAttribId, varptr(pDhcpAttrib)) ; ServerIpAddr : LPWSTR optional -> "wstr" ; dwReserved : DWORD -> "int" ; DhcpAttribId : DWORD -> "int" ; pDhcpAttrib : DHCP_ATTRIB** in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // DWORDfunction 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)。const std = @import("std");
extern "dhcpsapi" fn DhcpServerQueryAttribute(
ServerIpAddr: [*c]const u16, // LPWSTR optional
dwReserved: u32, // DWORD
DhcpAttribId: u32, // DWORD
pDhcpAttrib: [*c][*c]DHCP_ATTRIB // DHCP_ATTRIB** in/out
) callconv(std.os.windows.WINAPI) u32;proc DhcpServerQueryAttribute(
ServerIpAddr: WideCString, # LPWSTR optional
dwReserved: uint32, # DWORD
DhcpAttribId: uint32, # DWORD
pDhcpAttrib: ptr DHCP_ATTRIB # DHCP_ATTRIB** in/out
): uint32 {.importc: "DhcpServerQueryAttribute", stdcall, dynlib: "DHCPSAPI.dll".}pragma(lib, "dhcpsapi");
extern(Windows)
uint DhcpServerQueryAttribute(
const(wchar)* ServerIpAddr, // LPWSTR optional
uint dwReserved, // DWORD
uint DhcpAttribId, // DWORD
DHCP_ATTRIB** pDhcpAttrib // DHCP_ATTRIB** in/out
);ccall((:DhcpServerQueryAttribute, "DHCPSAPI.dll"), stdcall, UInt32,
(Cwstring, UInt32, UInt32, Ptr{DHCP_ATTRIB}),
ServerIpAddr, dwReserved, DhcpAttribId, pDhcpAttrib)
# ServerIpAddr : LPWSTR optional -> Cwstring
# dwReserved : DWORD -> UInt32
# DhcpAttribId : DWORD -> UInt32
# pDhcpAttrib : DHCP_ATTRIB** in/out -> Ptr{DHCP_ATTRIB}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t DhcpServerQueryAttribute(
const uint16_t* ServerIpAddr,
uint32_t dwReserved,
uint32_t DhcpAttribId,
void* pDhcpAttrib);
]]
local dhcpsapi = ffi.load("dhcpsapi")
-- dhcpsapi.DhcpServerQueryAttribute(ServerIpAddr, dwReserved, DhcpAttribId, pDhcpAttrib)
-- ServerIpAddr : LPWSTR optional
-- dwReserved : DWORD
-- DhcpAttribId : DWORD
-- pDhcpAttrib : DHCP_ATTRIB** in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('DHCPSAPI.dll');
const DhcpServerQueryAttribute = lib.func('__stdcall', 'DhcpServerQueryAttribute', 'uint32_t', ['str16', 'uint32_t', 'uint32_t', 'void *']);
// DhcpServerQueryAttribute(ServerIpAddr, dwReserved, DhcpAttribId, pDhcpAttrib)
// ServerIpAddr : LPWSTR optional -> 'str16'
// dwReserved : DWORD -> 'uint32_t'
// DhcpAttribId : DWORD -> 'uint32_t'
// pDhcpAttrib : DHCP_ATTRIB** in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("DHCPSAPI.dll", {
DhcpServerQueryAttribute: { parameters: ["buffer", "u32", "u32", "pointer"], result: "u32" },
});
// lib.symbols.DhcpServerQueryAttribute(ServerIpAddr, dwReserved, DhcpAttribId, pDhcpAttrib)
// ServerIpAddr : LPWSTR optional -> "buffer"
// dwReserved : DWORD -> "u32"
// DhcpAttribId : DWORD -> "u32"
// pDhcpAttrib : DHCP_ATTRIB** in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t DhcpServerQueryAttribute(
const uint16_t* ServerIpAddr,
uint32_t dwReserved,
uint32_t DhcpAttribId,
void* pDhcpAttrib);
C, "DHCPSAPI.dll");
// $ffi->DhcpServerQueryAttribute(ServerIpAddr, dwReserved, DhcpAttribId, pDhcpAttrib);
// ServerIpAddr : LPWSTR optional
// dwReserved : DWORD
// DhcpAttribId : DWORD
// pDhcpAttrib : DHCP_ATTRIB** 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 DhcpServerQueryAttribute(
WString ServerIpAddr, // LPWSTR optional
int dwReserved, // DWORD
int DhcpAttribId, // DWORD
Pointer pDhcpAttrib // DHCP_ATTRIB** in/out
);
}@[Link("dhcpsapi")]
lib LibDHCPSAPI
fun DhcpServerQueryAttribute = DhcpServerQueryAttribute(
ServerIpAddr : UInt16*, # LPWSTR optional
dwReserved : UInt32, # DWORD
DhcpAttribId : UInt32, # DWORD
pDhcpAttrib : DHCP_ATTRIB** # DHCP_ATTRIB** 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 DhcpServerQueryAttributeNative = Uint32 Function(Pointer<Utf16>, Uint32, Uint32, Pointer<Void>);
typedef DhcpServerQueryAttributeDart = int Function(Pointer<Utf16>, int, int, Pointer<Void>);
final DhcpServerQueryAttribute = DynamicLibrary.open('DHCPSAPI.dll')
.lookupFunction<DhcpServerQueryAttributeNative, DhcpServerQueryAttributeDart>('DhcpServerQueryAttribute');
// ServerIpAddr : LPWSTR optional -> Pointer<Utf16>
// dwReserved : DWORD -> Uint32
// DhcpAttribId : DWORD -> Uint32
// pDhcpAttrib : DHCP_ATTRIB** in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DhcpServerQueryAttribute"
c_DhcpServerQueryAttribute :: CWString -> Word32 -> Word32 -> Ptr () -> IO Word32
-- ServerIpAddr : LPWSTR optional -> CWString
-- dwReserved : DWORD -> Word32
-- DhcpAttribId : DWORD -> Word32
-- pDhcpAttrib : DHCP_ATTRIB** in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let dhcpserverqueryattribute =
foreign "DhcpServerQueryAttribute"
((ptr uint16_t) @-> uint32_t @-> uint32_t @-> (ptr void) @-> returning uint32_t)
(* ServerIpAddr : LPWSTR optional -> (ptr uint16_t) *)
(* dwReserved : DWORD -> uint32_t *)
(* DhcpAttribId : DWORD -> uint32_t *)
(* pDhcpAttrib : DHCP_ATTRIB** 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 ("DhcpServerQueryAttribute" dhcp-server-query-attribute :convention :stdcall) :uint32
(server-ip-addr (:string :encoding :utf-16le)) ; LPWSTR optional
(dw-reserved :uint32) ; DWORD
(dhcp-attrib-id :uint32) ; DWORD
(p-dhcp-attrib :pointer)) ; DHCP_ATTRIB** in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DhcpServerQueryAttribute = Win32::API::More->new('DHCPSAPI',
'DWORD DhcpServerQueryAttribute(LPCWSTR ServerIpAddr, DWORD dwReserved, DWORD DhcpAttribId, LPVOID pDhcpAttrib)');
# my $ret = $DhcpServerQueryAttribute->Call($ServerIpAddr, $dwReserved, $DhcpAttribId, $pDhcpAttrib);
# ServerIpAddr : LPWSTR optional -> LPCWSTR
# dwReserved : DWORD -> DWORD
# DhcpAttribId : DWORD -> DWORD
# pDhcpAttrib : DHCP_ATTRIB** in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型