ホーム › NetworkManagement.Dhcp › DhcpEnumOptionsV5
DhcpEnumOptionsV5
関数クラス/ベンダー指定でDHCPオプション定義を列挙する。
シグネチャ
// DHCPSAPI.dll
#include <windows.h>
DWORD DhcpEnumOptionsV5(
LPWSTR ServerIpAddress, // optional
DWORD Flags,
LPWSTR ClassName, // optional
LPWSTR VendorName, // optional
DWORD* ResumeHandle,
DWORD PreferredMaximum,
DHCP_OPTION_ARRAY** Options,
DWORD* OptionsRead,
DWORD* OptionsTotal
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ServerIpAddress | LPWSTR | inoptional | 操作対象DHCPサーバのIPアドレスまたはホスト名(Unicode)。 |
| Flags | DWORD | in | ベンダ固有オプションか等を示すフラグを指定する。 |
| ClassName | LPWSTR | inoptional | 列挙対象のユーザクラス名(Unicode)へのポインタ。NULL可。 |
| VendorName | LPWSTR | inoptional | 列挙対象のベンダクラス名(Unicode)へのポインタ。NULL可。 |
| ResumeHandle | DWORD* | inout | 列挙の再開位置を示すDWORDへのポインタ。初回は0を指す。 |
| PreferredMaximum | DWORD | in | 一度に取得するオプション数の上限をバイト数で指定する。 |
| Options | DHCP_OPTION_ARRAY** | inout | 列挙結果を受け取るDHCP_OPTION_ARRAYへのポインタ。 |
| OptionsRead | DWORD* | inout | 今回読み取ったオプション数を受け取るDWORDへのポインタ。 |
| OptionsTotal | DWORD* | inout | 未列挙分も含む残りオプション総数を受け取るDWORDへのポインタ。 |
戻り値の型: DWORD
各言語での呼び出し定義
// DHCPSAPI.dll
#include <windows.h>
DWORD DhcpEnumOptionsV5(
LPWSTR ServerIpAddress, // optional
DWORD Flags,
LPWSTR ClassName, // optional
LPWSTR VendorName, // optional
DWORD* ResumeHandle,
DWORD PreferredMaximum,
DHCP_OPTION_ARRAY** Options,
DWORD* OptionsRead,
DWORD* OptionsTotal
);[DllImport("DHCPSAPI.dll", ExactSpelling = true)]
static extern uint DhcpEnumOptionsV5(
[MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress, // LPWSTR optional
uint Flags, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] string ClassName, // LPWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string VendorName, // LPWSTR optional
ref uint ResumeHandle, // DWORD* in/out
uint PreferredMaximum, // DWORD
IntPtr Options, // DHCP_OPTION_ARRAY** in/out
ref uint OptionsRead, // DWORD* in/out
ref uint OptionsTotal // DWORD* in/out
);<DllImport("DHCPSAPI.dll", ExactSpelling:=True)>
Public Shared Function DhcpEnumOptionsV5(
<MarshalAs(UnmanagedType.LPWStr)> ServerIpAddress As String, ' LPWSTR optional
Flags As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> ClassName As String, ' LPWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> VendorName As String, ' LPWSTR optional
ByRef ResumeHandle As UInteger, ' DWORD* in/out
PreferredMaximum As UInteger, ' DWORD
Options As IntPtr, ' DHCP_OPTION_ARRAY** in/out
ByRef OptionsRead As UInteger, ' DWORD* in/out
ByRef OptionsTotal As UInteger ' DWORD* in/out
) As UInteger
End Function' ServerIpAddress : LPWSTR optional
' Flags : DWORD
' ClassName : LPWSTR optional
' VendorName : LPWSTR optional
' ResumeHandle : DWORD* in/out
' PreferredMaximum : DWORD
' Options : DHCP_OPTION_ARRAY** in/out
' OptionsRead : DWORD* in/out
' OptionsTotal : DWORD* in/out
Declare PtrSafe Function DhcpEnumOptionsV5 Lib "dhcpsapi" ( _
ByVal ServerIpAddress As LongPtr, _
ByVal Flags As Long, _
ByVal ClassName As LongPtr, _
ByVal VendorName As LongPtr, _
ByRef ResumeHandle As Long, _
ByVal PreferredMaximum As Long, _
ByVal Options As LongPtr, _
ByRef OptionsRead As Long, _
ByRef OptionsTotal As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DhcpEnumOptionsV5 = ctypes.windll.dhcpsapi.DhcpEnumOptionsV5
DhcpEnumOptionsV5.restype = wintypes.DWORD
DhcpEnumOptionsV5.argtypes = [
wintypes.LPCWSTR, # ServerIpAddress : LPWSTR optional
wintypes.DWORD, # Flags : DWORD
wintypes.LPCWSTR, # ClassName : LPWSTR optional
wintypes.LPCWSTR, # VendorName : LPWSTR optional
ctypes.POINTER(wintypes.DWORD), # ResumeHandle : DWORD* in/out
wintypes.DWORD, # PreferredMaximum : DWORD
ctypes.c_void_p, # Options : DHCP_OPTION_ARRAY** in/out
ctypes.POINTER(wintypes.DWORD), # OptionsRead : DWORD* in/out
ctypes.POINTER(wintypes.DWORD), # OptionsTotal : DWORD* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('DHCPSAPI.dll')
DhcpEnumOptionsV5 = Fiddle::Function.new(
lib['DhcpEnumOptionsV5'],
[
Fiddle::TYPE_VOIDP, # ServerIpAddress : LPWSTR optional
-Fiddle::TYPE_INT, # Flags : DWORD
Fiddle::TYPE_VOIDP, # ClassName : LPWSTR optional
Fiddle::TYPE_VOIDP, # VendorName : LPWSTR optional
Fiddle::TYPE_VOIDP, # ResumeHandle : DWORD* in/out
-Fiddle::TYPE_INT, # PreferredMaximum : DWORD
Fiddle::TYPE_VOIDP, # Options : DHCP_OPTION_ARRAY** in/out
Fiddle::TYPE_VOIDP, # OptionsRead : DWORD* in/out
Fiddle::TYPE_VOIDP, # OptionsTotal : DWORD* in/out
],
-Fiddle::TYPE_INT)#[link(name = "dhcpsapi")]
extern "system" {
fn DhcpEnumOptionsV5(
ServerIpAddress: *mut u16, // LPWSTR optional
Flags: u32, // DWORD
ClassName: *mut u16, // LPWSTR optional
VendorName: *mut u16, // LPWSTR optional
ResumeHandle: *mut u32, // DWORD* in/out
PreferredMaximum: u32, // DWORD
Options: *mut *mut DHCP_OPTION_ARRAY, // DHCP_OPTION_ARRAY** in/out
OptionsRead: *mut u32, // DWORD* in/out
OptionsTotal: *mut u32 // DWORD* in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("DHCPSAPI.dll")]
public static extern uint DhcpEnumOptionsV5([MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress, uint Flags, [MarshalAs(UnmanagedType.LPWStr)] string ClassName, [MarshalAs(UnmanagedType.LPWStr)] string VendorName, ref uint ResumeHandle, uint PreferredMaximum, IntPtr Options, ref uint OptionsRead, ref uint OptionsTotal);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DHCPSAPI_DhcpEnumOptionsV5' -Namespace Win32 -PassThru
# $api::DhcpEnumOptionsV5(ServerIpAddress, Flags, ClassName, VendorName, ResumeHandle, PreferredMaximum, Options, OptionsRead, OptionsTotal)#uselib "DHCPSAPI.dll"
#func global DhcpEnumOptionsV5 "DhcpEnumOptionsV5" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; DhcpEnumOptionsV5 ServerIpAddress, Flags, ClassName, VendorName, varptr(ResumeHandle), PreferredMaximum, varptr(Options), varptr(OptionsRead), varptr(OptionsTotal) ; 戻り値は stat
; ServerIpAddress : LPWSTR optional -> "sptr"
; Flags : DWORD -> "sptr"
; ClassName : LPWSTR optional -> "sptr"
; VendorName : LPWSTR optional -> "sptr"
; ResumeHandle : DWORD* in/out -> "sptr"
; PreferredMaximum : DWORD -> "sptr"
; Options : DHCP_OPTION_ARRAY** in/out -> "sptr"
; OptionsRead : DWORD* in/out -> "sptr"
; OptionsTotal : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "DHCPSAPI.dll" #cfunc global DhcpEnumOptionsV5 "DhcpEnumOptionsV5" wstr, int, wstr, wstr, var, int, var, var, var ; res = DhcpEnumOptionsV5(ServerIpAddress, Flags, ClassName, VendorName, ResumeHandle, PreferredMaximum, Options, OptionsRead, OptionsTotal) ; ServerIpAddress : LPWSTR optional -> "wstr" ; Flags : DWORD -> "int" ; ClassName : LPWSTR optional -> "wstr" ; VendorName : LPWSTR optional -> "wstr" ; ResumeHandle : DWORD* in/out -> "var" ; PreferredMaximum : DWORD -> "int" ; Options : DHCP_OPTION_ARRAY** in/out -> "var" ; OptionsRead : DWORD* in/out -> "var" ; OptionsTotal : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "DHCPSAPI.dll" #cfunc global DhcpEnumOptionsV5 "DhcpEnumOptionsV5" wstr, int, wstr, wstr, sptr, int, sptr, sptr, sptr ; res = DhcpEnumOptionsV5(ServerIpAddress, Flags, ClassName, VendorName, varptr(ResumeHandle), PreferredMaximum, varptr(Options), varptr(OptionsRead), varptr(OptionsTotal)) ; ServerIpAddress : LPWSTR optional -> "wstr" ; Flags : DWORD -> "int" ; ClassName : LPWSTR optional -> "wstr" ; VendorName : LPWSTR optional -> "wstr" ; ResumeHandle : DWORD* in/out -> "sptr" ; PreferredMaximum : DWORD -> "int" ; Options : DHCP_OPTION_ARRAY** in/out -> "sptr" ; OptionsRead : DWORD* in/out -> "sptr" ; OptionsTotal : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD DhcpEnumOptionsV5(LPWSTR ServerIpAddress, DWORD Flags, LPWSTR ClassName, LPWSTR VendorName, DWORD* ResumeHandle, DWORD PreferredMaximum, DHCP_OPTION_ARRAY** Options, DWORD* OptionsRead, DWORD* OptionsTotal) #uselib "DHCPSAPI.dll" #cfunc global DhcpEnumOptionsV5 "DhcpEnumOptionsV5" wstr, int, wstr, wstr, var, int, var, var, var ; res = DhcpEnumOptionsV5(ServerIpAddress, Flags, ClassName, VendorName, ResumeHandle, PreferredMaximum, Options, OptionsRead, OptionsTotal) ; ServerIpAddress : LPWSTR optional -> "wstr" ; Flags : DWORD -> "int" ; ClassName : LPWSTR optional -> "wstr" ; VendorName : LPWSTR optional -> "wstr" ; ResumeHandle : DWORD* in/out -> "var" ; PreferredMaximum : DWORD -> "int" ; Options : DHCP_OPTION_ARRAY** in/out -> "var" ; OptionsRead : DWORD* in/out -> "var" ; OptionsTotal : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD DhcpEnumOptionsV5(LPWSTR ServerIpAddress, DWORD Flags, LPWSTR ClassName, LPWSTR VendorName, DWORD* ResumeHandle, DWORD PreferredMaximum, DHCP_OPTION_ARRAY** Options, DWORD* OptionsRead, DWORD* OptionsTotal) #uselib "DHCPSAPI.dll" #cfunc global DhcpEnumOptionsV5 "DhcpEnumOptionsV5" wstr, int, wstr, wstr, intptr, int, intptr, intptr, intptr ; res = DhcpEnumOptionsV5(ServerIpAddress, Flags, ClassName, VendorName, varptr(ResumeHandle), PreferredMaximum, varptr(Options), varptr(OptionsRead), varptr(OptionsTotal)) ; ServerIpAddress : LPWSTR optional -> "wstr" ; Flags : DWORD -> "int" ; ClassName : LPWSTR optional -> "wstr" ; VendorName : LPWSTR optional -> "wstr" ; ResumeHandle : DWORD* in/out -> "intptr" ; PreferredMaximum : DWORD -> "int" ; Options : DHCP_OPTION_ARRAY** in/out -> "intptr" ; OptionsRead : DWORD* in/out -> "intptr" ; OptionsTotal : DWORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
procDhcpEnumOptionsV5 = dhcpsapi.NewProc("DhcpEnumOptionsV5")
)
// ServerIpAddress (LPWSTR optional), Flags (DWORD), ClassName (LPWSTR optional), VendorName (LPWSTR optional), ResumeHandle (DWORD* in/out), PreferredMaximum (DWORD), Options (DHCP_OPTION_ARRAY** in/out), OptionsRead (DWORD* in/out), OptionsTotal (DWORD* in/out)
r1, _, err := procDhcpEnumOptionsV5.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ServerIpAddress))),
uintptr(Flags),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ClassName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(VendorName))),
uintptr(ResumeHandle),
uintptr(PreferredMaximum),
uintptr(Options),
uintptr(OptionsRead),
uintptr(OptionsTotal),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction DhcpEnumOptionsV5(
ServerIpAddress: PWideChar; // LPWSTR optional
Flags: DWORD; // DWORD
ClassName: PWideChar; // LPWSTR optional
VendorName: PWideChar; // LPWSTR optional
ResumeHandle: Pointer; // DWORD* in/out
PreferredMaximum: DWORD; // DWORD
Options: Pointer; // DHCP_OPTION_ARRAY** in/out
OptionsRead: Pointer; // DWORD* in/out
OptionsTotal: Pointer // DWORD* in/out
): DWORD; stdcall;
external 'DHCPSAPI.dll' name 'DhcpEnumOptionsV5';result := DllCall("DHCPSAPI\DhcpEnumOptionsV5"
, "WStr", ServerIpAddress ; LPWSTR optional
, "UInt", Flags ; DWORD
, "WStr", ClassName ; LPWSTR optional
, "WStr", VendorName ; LPWSTR optional
, "Ptr", ResumeHandle ; DWORD* in/out
, "UInt", PreferredMaximum ; DWORD
, "Ptr", Options ; DHCP_OPTION_ARRAY** in/out
, "Ptr", OptionsRead ; DWORD* in/out
, "Ptr", OptionsTotal ; DWORD* in/out
, "UInt") ; return: DWORD●DhcpEnumOptionsV5(ServerIpAddress, Flags, ClassName, VendorName, ResumeHandle, PreferredMaximum, Options, OptionsRead, OptionsTotal) = DLL("DHCPSAPI.dll", "dword DhcpEnumOptionsV5(char*, dword, char*, char*, void*, dword, void*, void*, void*)")
# 呼び出し: DhcpEnumOptionsV5(ServerIpAddress, Flags, ClassName, VendorName, ResumeHandle, PreferredMaximum, Options, OptionsRead, OptionsTotal)
# ServerIpAddress : LPWSTR optional -> "char*"
# Flags : DWORD -> "dword"
# ClassName : LPWSTR optional -> "char*"
# VendorName : LPWSTR optional -> "char*"
# ResumeHandle : DWORD* in/out -> "void*"
# PreferredMaximum : DWORD -> "dword"
# Options : DHCP_OPTION_ARRAY** in/out -> "void*"
# OptionsRead : DWORD* in/out -> "void*"
# OptionsTotal : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "dhcpsapi" fn DhcpEnumOptionsV5(
ServerIpAddress: [*c]const u16, // LPWSTR optional
Flags: u32, // DWORD
ClassName: [*c]const u16, // LPWSTR optional
VendorName: [*c]const u16, // LPWSTR optional
ResumeHandle: [*c]u32, // DWORD* in/out
PreferredMaximum: u32, // DWORD
Options: [*c][*c]DHCP_OPTION_ARRAY, // DHCP_OPTION_ARRAY** in/out
OptionsRead: [*c]u32, // DWORD* in/out
OptionsTotal: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) u32;proc DhcpEnumOptionsV5(
ServerIpAddress: WideCString, # LPWSTR optional
Flags: uint32, # DWORD
ClassName: WideCString, # LPWSTR optional
VendorName: WideCString, # LPWSTR optional
ResumeHandle: ptr uint32, # DWORD* in/out
PreferredMaximum: uint32, # DWORD
Options: ptr DHCP_OPTION_ARRAY, # DHCP_OPTION_ARRAY** in/out
OptionsRead: ptr uint32, # DWORD* in/out
OptionsTotal: ptr uint32 # DWORD* in/out
): uint32 {.importc: "DhcpEnumOptionsV5", stdcall, dynlib: "DHCPSAPI.dll".}pragma(lib, "dhcpsapi");
extern(Windows)
uint DhcpEnumOptionsV5(
const(wchar)* ServerIpAddress, // LPWSTR optional
uint Flags, // DWORD
const(wchar)* ClassName, // LPWSTR optional
const(wchar)* VendorName, // LPWSTR optional
uint* ResumeHandle, // DWORD* in/out
uint PreferredMaximum, // DWORD
DHCP_OPTION_ARRAY** Options, // DHCP_OPTION_ARRAY** in/out
uint* OptionsRead, // DWORD* in/out
uint* OptionsTotal // DWORD* in/out
);ccall((:DhcpEnumOptionsV5, "DHCPSAPI.dll"), stdcall, UInt32,
(Cwstring, UInt32, Cwstring, Cwstring, Ptr{UInt32}, UInt32, Ptr{DHCP_OPTION_ARRAY}, Ptr{UInt32}, Ptr{UInt32}),
ServerIpAddress, Flags, ClassName, VendorName, ResumeHandle, PreferredMaximum, Options, OptionsRead, OptionsTotal)
# ServerIpAddress : LPWSTR optional -> Cwstring
# Flags : DWORD -> UInt32
# ClassName : LPWSTR optional -> Cwstring
# VendorName : LPWSTR optional -> Cwstring
# ResumeHandle : DWORD* in/out -> Ptr{UInt32}
# PreferredMaximum : DWORD -> UInt32
# Options : DHCP_OPTION_ARRAY** in/out -> Ptr{DHCP_OPTION_ARRAY}
# OptionsRead : DWORD* in/out -> Ptr{UInt32}
# OptionsTotal : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t DhcpEnumOptionsV5(
const uint16_t* ServerIpAddress,
uint32_t Flags,
const uint16_t* ClassName,
const uint16_t* VendorName,
uint32_t* ResumeHandle,
uint32_t PreferredMaximum,
void* Options,
uint32_t* OptionsRead,
uint32_t* OptionsTotal);
]]
local dhcpsapi = ffi.load("dhcpsapi")
-- dhcpsapi.DhcpEnumOptionsV5(ServerIpAddress, Flags, ClassName, VendorName, ResumeHandle, PreferredMaximum, Options, OptionsRead, OptionsTotal)
-- ServerIpAddress : LPWSTR optional
-- Flags : DWORD
-- ClassName : LPWSTR optional
-- VendorName : LPWSTR optional
-- ResumeHandle : DWORD* in/out
-- PreferredMaximum : DWORD
-- Options : DHCP_OPTION_ARRAY** in/out
-- OptionsRead : DWORD* in/out
-- OptionsTotal : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('DHCPSAPI.dll');
const DhcpEnumOptionsV5 = lib.func('__stdcall', 'DhcpEnumOptionsV5', 'uint32_t', ['str16', 'uint32_t', 'str16', 'str16', 'uint32_t *', 'uint32_t', 'void *', 'uint32_t *', 'uint32_t *']);
// DhcpEnumOptionsV5(ServerIpAddress, Flags, ClassName, VendorName, ResumeHandle, PreferredMaximum, Options, OptionsRead, OptionsTotal)
// ServerIpAddress : LPWSTR optional -> 'str16'
// Flags : DWORD -> 'uint32_t'
// ClassName : LPWSTR optional -> 'str16'
// VendorName : LPWSTR optional -> 'str16'
// ResumeHandle : DWORD* in/out -> 'uint32_t *'
// PreferredMaximum : DWORD -> 'uint32_t'
// Options : DHCP_OPTION_ARRAY** in/out -> 'void *'
// OptionsRead : DWORD* in/out -> 'uint32_t *'
// OptionsTotal : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("DHCPSAPI.dll", {
DhcpEnumOptionsV5: { parameters: ["buffer", "u32", "buffer", "buffer", "pointer", "u32", "pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.DhcpEnumOptionsV5(ServerIpAddress, Flags, ClassName, VendorName, ResumeHandle, PreferredMaximum, Options, OptionsRead, OptionsTotal)
// ServerIpAddress : LPWSTR optional -> "buffer"
// Flags : DWORD -> "u32"
// ClassName : LPWSTR optional -> "buffer"
// VendorName : LPWSTR optional -> "buffer"
// ResumeHandle : DWORD* in/out -> "pointer"
// PreferredMaximum : DWORD -> "u32"
// Options : DHCP_OPTION_ARRAY** in/out -> "pointer"
// OptionsRead : DWORD* in/out -> "pointer"
// OptionsTotal : DWORD* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t DhcpEnumOptionsV5(
const uint16_t* ServerIpAddress,
uint32_t Flags,
const uint16_t* ClassName,
const uint16_t* VendorName,
uint32_t* ResumeHandle,
uint32_t PreferredMaximum,
void* Options,
uint32_t* OptionsRead,
uint32_t* OptionsTotal);
C, "DHCPSAPI.dll");
// $ffi->DhcpEnumOptionsV5(ServerIpAddress, Flags, ClassName, VendorName, ResumeHandle, PreferredMaximum, Options, OptionsRead, OptionsTotal);
// ServerIpAddress : LPWSTR optional
// Flags : DWORD
// ClassName : LPWSTR optional
// VendorName : LPWSTR optional
// ResumeHandle : DWORD* in/out
// PreferredMaximum : DWORD
// Options : DHCP_OPTION_ARRAY** in/out
// OptionsRead : DWORD* in/out
// OptionsTotal : DWORD* 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 DhcpEnumOptionsV5(
WString ServerIpAddress, // LPWSTR optional
int Flags, // DWORD
WString ClassName, // LPWSTR optional
WString VendorName, // LPWSTR optional
IntByReference ResumeHandle, // DWORD* in/out
int PreferredMaximum, // DWORD
Pointer Options, // DHCP_OPTION_ARRAY** in/out
IntByReference OptionsRead, // DWORD* in/out
IntByReference OptionsTotal // DWORD* in/out
);
}@[Link("dhcpsapi")]
lib LibDHCPSAPI
fun DhcpEnumOptionsV5 = DhcpEnumOptionsV5(
ServerIpAddress : UInt16*, # LPWSTR optional
Flags : UInt32, # DWORD
ClassName : UInt16*, # LPWSTR optional
VendorName : UInt16*, # LPWSTR optional
ResumeHandle : UInt32*, # DWORD* in/out
PreferredMaximum : UInt32, # DWORD
Options : DHCP_OPTION_ARRAY**, # DHCP_OPTION_ARRAY** in/out
OptionsRead : UInt32*, # DWORD* in/out
OptionsTotal : UInt32* # DWORD* 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 DhcpEnumOptionsV5Native = Uint32 Function(Pointer<Utf16>, Uint32, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>, Uint32, Pointer<Void>, Pointer<Uint32>, Pointer<Uint32>);
typedef DhcpEnumOptionsV5Dart = int Function(Pointer<Utf16>, int, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>, int, Pointer<Void>, Pointer<Uint32>, Pointer<Uint32>);
final DhcpEnumOptionsV5 = DynamicLibrary.open('DHCPSAPI.dll')
.lookupFunction<DhcpEnumOptionsV5Native, DhcpEnumOptionsV5Dart>('DhcpEnumOptionsV5');
// ServerIpAddress : LPWSTR optional -> Pointer<Utf16>
// Flags : DWORD -> Uint32
// ClassName : LPWSTR optional -> Pointer<Utf16>
// VendorName : LPWSTR optional -> Pointer<Utf16>
// ResumeHandle : DWORD* in/out -> Pointer<Uint32>
// PreferredMaximum : DWORD -> Uint32
// Options : DHCP_OPTION_ARRAY** in/out -> Pointer<Void>
// OptionsRead : DWORD* in/out -> Pointer<Uint32>
// OptionsTotal : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DhcpEnumOptionsV5(
ServerIpAddress: PWideChar; // LPWSTR optional
Flags: DWORD; // DWORD
ClassName: PWideChar; // LPWSTR optional
VendorName: PWideChar; // LPWSTR optional
ResumeHandle: Pointer; // DWORD* in/out
PreferredMaximum: DWORD; // DWORD
Options: Pointer; // DHCP_OPTION_ARRAY** in/out
OptionsRead: Pointer; // DWORD* in/out
OptionsTotal: Pointer // DWORD* in/out
): DWORD; stdcall;
external 'DHCPSAPI.dll' name 'DhcpEnumOptionsV5';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DhcpEnumOptionsV5"
c_DhcpEnumOptionsV5 :: CWString -> Word32 -> CWString -> CWString -> Ptr Word32 -> Word32 -> Ptr () -> Ptr Word32 -> Ptr Word32 -> IO Word32
-- ServerIpAddress : LPWSTR optional -> CWString
-- Flags : DWORD -> Word32
-- ClassName : LPWSTR optional -> CWString
-- VendorName : LPWSTR optional -> CWString
-- ResumeHandle : DWORD* in/out -> Ptr Word32
-- PreferredMaximum : DWORD -> Word32
-- Options : DHCP_OPTION_ARRAY** in/out -> Ptr ()
-- OptionsRead : DWORD* in/out -> Ptr Word32
-- OptionsTotal : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let dhcpenumoptionsv5 =
foreign "DhcpEnumOptionsV5"
((ptr uint16_t) @-> uint32_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> uint32_t @-> (ptr void) @-> (ptr uint32_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* ServerIpAddress : LPWSTR optional -> (ptr uint16_t) *)
(* Flags : DWORD -> uint32_t *)
(* ClassName : LPWSTR optional -> (ptr uint16_t) *)
(* VendorName : LPWSTR optional -> (ptr uint16_t) *)
(* ResumeHandle : DWORD* in/out -> (ptr uint32_t) *)
(* PreferredMaximum : DWORD -> uint32_t *)
(* Options : DHCP_OPTION_ARRAY** in/out -> (ptr void) *)
(* OptionsRead : DWORD* in/out -> (ptr uint32_t) *)
(* OptionsTotal : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library dhcpsapi (t "DHCPSAPI.dll"))
(cffi:use-foreign-library dhcpsapi)
(cffi:defcfun ("DhcpEnumOptionsV5" dhcp-enum-options-v5 :convention :stdcall) :uint32
(server-ip-address (:string :encoding :utf-16le)) ; LPWSTR optional
(flags :uint32) ; DWORD
(class-name (:string :encoding :utf-16le)) ; LPWSTR optional
(vendor-name (:string :encoding :utf-16le)) ; LPWSTR optional
(resume-handle :pointer) ; DWORD* in/out
(preferred-maximum :uint32) ; DWORD
(options :pointer) ; DHCP_OPTION_ARRAY** in/out
(options-read :pointer) ; DWORD* in/out
(options-total :pointer)) ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DhcpEnumOptionsV5 = Win32::API::More->new('DHCPSAPI',
'DWORD DhcpEnumOptionsV5(LPCWSTR ServerIpAddress, DWORD Flags, LPCWSTR ClassName, LPCWSTR VendorName, LPVOID ResumeHandle, DWORD PreferredMaximum, LPVOID Options, LPVOID OptionsRead, LPVOID OptionsTotal)');
# my $ret = $DhcpEnumOptionsV5->Call($ServerIpAddress, $Flags, $ClassName, $VendorName, $ResumeHandle, $PreferredMaximum, $Options, $OptionsRead, $OptionsTotal);
# ServerIpAddress : LPWSTR optional -> LPCWSTR
# Flags : DWORD -> DWORD
# ClassName : LPWSTR optional -> LPCWSTR
# VendorName : LPWSTR optional -> LPCWSTR
# ResumeHandle : DWORD* in/out -> LPVOID
# PreferredMaximum : DWORD -> DWORD
# Options : DHCP_OPTION_ARRAY** in/out -> LPVOID
# OptionsRead : DWORD* in/out -> LPVOID
# OptionsTotal : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f DhcpEnumOptionsV6 — クラス/ベンダー指定でIPv6向けDHCPオプション定義を列挙する。
使用する型