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

DhcpEnumOptionsV6

関数
クラス/ベンダー指定でIPv6向けDHCPオプション定義を列挙する。
DLLDHCPSAPI.dll呼出規約winapi対応OSwindowsserver2008

シグネチャ

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

DWORD DhcpEnumOptionsV6(
    LPWSTR ServerIpAddress,   // optional
    DWORD Flags,
    LPWSTR ClassName,   // optional
    LPWSTR VendorName,   // optional
    DWORD* ResumeHandle,
    DWORD PreferredMaximum,
    DHCP_OPTION_ARRAY** Options,
    DWORD* OptionsRead,
    DWORD* OptionsTotal
);

パラメーター

名前方向説明
ServerIpAddressLPWSTRinoptional対象DHCPv6サーバーのIPアドレスを示すUnicode文字列。ローカルならNULL可。
FlagsDWORDinベンダー固有オプションを列挙するか否かを示すフラグ。
ClassNameLPWSTRinoptional列挙対象のクラス名。既定クラスならNULL可。
VendorNameLPWSTRinoptionalベンダー固有の場合のベンダー名。標準オプションならNULL可。
ResumeHandleDWORD*inout列挙の再開位置ハンドルへのポインタ。初回は0を指す変数を渡す。
PreferredMaximumDWORDin1回で返すオプションデータの推奨最大バイト数。
OptionsDHCP_OPTION_ARRAY**inout列挙結果のDHCP_OPTION_ARRAYへのポインタを受け取る二重ポインタ。使用後は解放する。
OptionsReadDWORD*inout今回読み取られたオプション数を受け取るDWORDへのポインタ。
OptionsTotalDWORD*inout残りのオプション総数を受け取るDWORDへのポインタ。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD DhcpEnumOptionsV6(
    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 DhcpEnumOptionsV6(
    [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 DhcpEnumOptionsV6(
    <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 DhcpEnumOptionsV6 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

DhcpEnumOptionsV6 = ctypes.windll.dhcpsapi.DhcpEnumOptionsV6
DhcpEnumOptionsV6.restype = wintypes.DWORD
DhcpEnumOptionsV6.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')
DhcpEnumOptionsV6 = Fiddle::Function.new(
  lib['DhcpEnumOptionsV6'],
  [
    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 DhcpEnumOptionsV6(
        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 DhcpEnumOptionsV6([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_DhcpEnumOptionsV6' -Namespace Win32 -PassThru
# $api::DhcpEnumOptionsV6(ServerIpAddress, Flags, ClassName, VendorName, ResumeHandle, PreferredMaximum, Options, OptionsRead, OptionsTotal)
#uselib "DHCPSAPI.dll"
#func global DhcpEnumOptionsV6 "DhcpEnumOptionsV6" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; DhcpEnumOptionsV6 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 DhcpEnumOptionsV6 "DhcpEnumOptionsV6" wstr, int, wstr, wstr, var, int, var, var, var
; res = DhcpEnumOptionsV6(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 DhcpEnumOptionsV6(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 DhcpEnumOptionsV6 "DhcpEnumOptionsV6" wstr, int, wstr, wstr, var, int, var, var, var
; res = DhcpEnumOptionsV6(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 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
	procDhcpEnumOptionsV6 = dhcpsapi.NewProc("DhcpEnumOptionsV6")
)

// 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 := procDhcpEnumOptionsV6.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   // DWORD
function DhcpEnumOptionsV6(
  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 'DhcpEnumOptionsV6';
result := DllCall("DHCPSAPI\DhcpEnumOptionsV6"
    , "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
●DhcpEnumOptionsV6(ServerIpAddress, Flags, ClassName, VendorName, ResumeHandle, PreferredMaximum, Options, OptionsRead, OptionsTotal) = DLL("DHCPSAPI.dll", "dword DhcpEnumOptionsV6(char*, dword, char*, char*, void*, dword, void*, void*, void*)")
# 呼び出し: DhcpEnumOptionsV6(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 DhcpEnumOptionsV6(
    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 DhcpEnumOptionsV6(
    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: "DhcpEnumOptionsV6", stdcall, dynlib: "DHCPSAPI.dll".}
pragma(lib, "dhcpsapi");
extern(Windows)
uint DhcpEnumOptionsV6(
    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((:DhcpEnumOptionsV6, "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 DhcpEnumOptionsV6(
    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.DhcpEnumOptionsV6(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 DhcpEnumOptionsV6 = lib.func('__stdcall', 'DhcpEnumOptionsV6', 'uint32_t', ['str16', 'uint32_t', 'str16', 'str16', 'uint32_t *', 'uint32_t', 'void *', 'uint32_t *', 'uint32_t *']);
// DhcpEnumOptionsV6(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", {
  DhcpEnumOptionsV6: { parameters: ["buffer", "u32", "buffer", "buffer", "pointer", "u32", "pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.DhcpEnumOptionsV6(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 DhcpEnumOptionsV6(
    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->DhcpEnumOptionsV6(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 DhcpEnumOptionsV6(
        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 DhcpEnumOptionsV6 = DhcpEnumOptionsV6(
    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 DhcpEnumOptionsV6Native = Uint32 Function(Pointer<Utf16>, Uint32, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>, Uint32, Pointer<Void>, Pointer<Uint32>, Pointer<Uint32>);
typedef DhcpEnumOptionsV6Dart = int Function(Pointer<Utf16>, int, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>, int, Pointer<Void>, Pointer<Uint32>, Pointer<Uint32>);
final DhcpEnumOptionsV6 = DynamicLibrary.open('DHCPSAPI.dll')
    .lookupFunction<DhcpEnumOptionsV6Native, DhcpEnumOptionsV6Dart>('DhcpEnumOptionsV6');
// 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 DhcpEnumOptionsV6(
  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 'DhcpEnumOptionsV6';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DhcpEnumOptionsV6"
  c_DhcpEnumOptionsV6 :: 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 dhcpenumoptionsv6 =
  foreign "DhcpEnumOptionsV6"
    ((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 ("DhcpEnumOptionsV6" dhcp-enum-options-v6 :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 $DhcpEnumOptionsV6 = Win32::API::More->new('DHCPSAPI',
    'DWORD DhcpEnumOptionsV6(LPCWSTR ServerIpAddress, DWORD Flags, LPCWSTR ClassName, LPCWSTR VendorName, LPVOID ResumeHandle, DWORD PreferredMaximum, LPVOID Options, LPVOID OptionsRead, LPVOID OptionsTotal)');
# my $ret = $DhcpEnumOptionsV6->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
使用する型