ホーム › NetworkManagement.Dhcp › DhcpV4GetOptionValue
DhcpV4GetOptionValue
関数指定スコープのIPv4 DHCPオプション値を取得する。
シグネチャ
// DHCPSAPI.dll
#include <windows.h>
DWORD DhcpV4GetOptionValue(
LPWSTR ServerIpAddress, // optional
DWORD Flags,
DWORD OptionID,
LPWSTR PolicyName, // optional
LPWSTR VendorName, // optional
DHCP_OPTION_SCOPE_INFO* ScopeInfo,
DHCP_OPTION_VALUE** OptionValue
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ServerIpAddress | LPWSTR | inoptional | 対象DHCPサーバーのIPアドレスを示すUnicode文字列。ローカルならNULL可。 |
| Flags | DWORD | in | ポリシー/ベンダー固有オプションか否かを示すフラグ。 |
| OptionID | DWORD | in | 値を取得するオプションの識別子(コード)。 |
| PolicyName | LPWSTR | inoptional | オプション値が属するポリシー名。ポリシー単位でなければNULL可。 |
| VendorName | LPWSTR | inoptional | ベンダー固有の場合のベンダー名。標準ならNULL可。 |
| ScopeInfo | DHCP_OPTION_SCOPE_INFO* | inout | オプション値の適用範囲を示すDHCP_OPTION_SCOPE_INFO構造体へのポインタ。 |
| OptionValue | DHCP_OPTION_VALUE** | inout | 取得したオプション値のDHCP_OPTION_VALUEへのポインタを受け取る二重ポインタ。使用後は解放する。 |
戻り値の型: DWORD
各言語での呼び出し定義
// DHCPSAPI.dll
#include <windows.h>
DWORD DhcpV4GetOptionValue(
LPWSTR ServerIpAddress, // optional
DWORD Flags,
DWORD OptionID,
LPWSTR PolicyName, // optional
LPWSTR VendorName, // optional
DHCP_OPTION_SCOPE_INFO* ScopeInfo,
DHCP_OPTION_VALUE** OptionValue
);[DllImport("DHCPSAPI.dll", ExactSpelling = true)]
static extern uint DhcpV4GetOptionValue(
[MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress, // LPWSTR optional
uint Flags, // DWORD
uint OptionID, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] string PolicyName, // LPWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string VendorName, // LPWSTR optional
IntPtr ScopeInfo, // DHCP_OPTION_SCOPE_INFO* in/out
IntPtr OptionValue // DHCP_OPTION_VALUE** in/out
);<DllImport("DHCPSAPI.dll", ExactSpelling:=True)>
Public Shared Function DhcpV4GetOptionValue(
<MarshalAs(UnmanagedType.LPWStr)> ServerIpAddress As String, ' LPWSTR optional
Flags As UInteger, ' DWORD
OptionID As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> PolicyName As String, ' LPWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> VendorName As String, ' LPWSTR optional
ScopeInfo As IntPtr, ' DHCP_OPTION_SCOPE_INFO* in/out
OptionValue As IntPtr ' DHCP_OPTION_VALUE** in/out
) As UInteger
End Function' ServerIpAddress : LPWSTR optional
' Flags : DWORD
' OptionID : DWORD
' PolicyName : LPWSTR optional
' VendorName : LPWSTR optional
' ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out
' OptionValue : DHCP_OPTION_VALUE** in/out
Declare PtrSafe Function DhcpV4GetOptionValue Lib "dhcpsapi" ( _
ByVal ServerIpAddress As LongPtr, _
ByVal Flags As Long, _
ByVal OptionID As Long, _
ByVal PolicyName As LongPtr, _
ByVal VendorName As LongPtr, _
ByVal ScopeInfo As LongPtr, _
ByVal OptionValue As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DhcpV4GetOptionValue = ctypes.windll.dhcpsapi.DhcpV4GetOptionValue
DhcpV4GetOptionValue.restype = wintypes.DWORD
DhcpV4GetOptionValue.argtypes = [
wintypes.LPCWSTR, # ServerIpAddress : LPWSTR optional
wintypes.DWORD, # Flags : DWORD
wintypes.DWORD, # OptionID : DWORD
wintypes.LPCWSTR, # PolicyName : LPWSTR optional
wintypes.LPCWSTR, # VendorName : LPWSTR optional
ctypes.c_void_p, # ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out
ctypes.c_void_p, # OptionValue : DHCP_OPTION_VALUE** in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('DHCPSAPI.dll')
DhcpV4GetOptionValue = Fiddle::Function.new(
lib['DhcpV4GetOptionValue'],
[
Fiddle::TYPE_VOIDP, # ServerIpAddress : LPWSTR optional
-Fiddle::TYPE_INT, # Flags : DWORD
-Fiddle::TYPE_INT, # OptionID : DWORD
Fiddle::TYPE_VOIDP, # PolicyName : LPWSTR optional
Fiddle::TYPE_VOIDP, # VendorName : LPWSTR optional
Fiddle::TYPE_VOIDP, # ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out
Fiddle::TYPE_VOIDP, # OptionValue : DHCP_OPTION_VALUE** in/out
],
-Fiddle::TYPE_INT)#[link(name = "dhcpsapi")]
extern "system" {
fn DhcpV4GetOptionValue(
ServerIpAddress: *mut u16, // LPWSTR optional
Flags: u32, // DWORD
OptionID: u32, // DWORD
PolicyName: *mut u16, // LPWSTR optional
VendorName: *mut u16, // LPWSTR optional
ScopeInfo: *mut DHCP_OPTION_SCOPE_INFO, // DHCP_OPTION_SCOPE_INFO* in/out
OptionValue: *mut *mut DHCP_OPTION_VALUE // DHCP_OPTION_VALUE** in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("DHCPSAPI.dll")]
public static extern uint DhcpV4GetOptionValue([MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress, uint Flags, uint OptionID, [MarshalAs(UnmanagedType.LPWStr)] string PolicyName, [MarshalAs(UnmanagedType.LPWStr)] string VendorName, IntPtr ScopeInfo, IntPtr OptionValue);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DHCPSAPI_DhcpV4GetOptionValue' -Namespace Win32 -PassThru
# $api::DhcpV4GetOptionValue(ServerIpAddress, Flags, OptionID, PolicyName, VendorName, ScopeInfo, OptionValue)#uselib "DHCPSAPI.dll"
#func global DhcpV4GetOptionValue "DhcpV4GetOptionValue" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; DhcpV4GetOptionValue ServerIpAddress, Flags, OptionID, PolicyName, VendorName, varptr(ScopeInfo), varptr(OptionValue) ; 戻り値は stat
; ServerIpAddress : LPWSTR optional -> "sptr"
; Flags : DWORD -> "sptr"
; OptionID : DWORD -> "sptr"
; PolicyName : LPWSTR optional -> "sptr"
; VendorName : LPWSTR optional -> "sptr"
; ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> "sptr"
; OptionValue : DHCP_OPTION_VALUE** in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "DHCPSAPI.dll" #cfunc global DhcpV4GetOptionValue "DhcpV4GetOptionValue" wstr, int, int, wstr, wstr, var, var ; res = DhcpV4GetOptionValue(ServerIpAddress, Flags, OptionID, PolicyName, VendorName, ScopeInfo, OptionValue) ; ServerIpAddress : LPWSTR optional -> "wstr" ; Flags : DWORD -> "int" ; OptionID : DWORD -> "int" ; PolicyName : LPWSTR optional -> "wstr" ; VendorName : LPWSTR optional -> "wstr" ; ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> "var" ; OptionValue : DHCP_OPTION_VALUE** in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "DHCPSAPI.dll" #cfunc global DhcpV4GetOptionValue "DhcpV4GetOptionValue" wstr, int, int, wstr, wstr, sptr, sptr ; res = DhcpV4GetOptionValue(ServerIpAddress, Flags, OptionID, PolicyName, VendorName, varptr(ScopeInfo), varptr(OptionValue)) ; ServerIpAddress : LPWSTR optional -> "wstr" ; Flags : DWORD -> "int" ; OptionID : DWORD -> "int" ; PolicyName : LPWSTR optional -> "wstr" ; VendorName : LPWSTR optional -> "wstr" ; ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> "sptr" ; OptionValue : DHCP_OPTION_VALUE** in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD DhcpV4GetOptionValue(LPWSTR ServerIpAddress, DWORD Flags, DWORD OptionID, LPWSTR PolicyName, LPWSTR VendorName, DHCP_OPTION_SCOPE_INFO* ScopeInfo, DHCP_OPTION_VALUE** OptionValue) #uselib "DHCPSAPI.dll" #cfunc global DhcpV4GetOptionValue "DhcpV4GetOptionValue" wstr, int, int, wstr, wstr, var, var ; res = DhcpV4GetOptionValue(ServerIpAddress, Flags, OptionID, PolicyName, VendorName, ScopeInfo, OptionValue) ; ServerIpAddress : LPWSTR optional -> "wstr" ; Flags : DWORD -> "int" ; OptionID : DWORD -> "int" ; PolicyName : LPWSTR optional -> "wstr" ; VendorName : LPWSTR optional -> "wstr" ; ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> "var" ; OptionValue : DHCP_OPTION_VALUE** in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD DhcpV4GetOptionValue(LPWSTR ServerIpAddress, DWORD Flags, DWORD OptionID, LPWSTR PolicyName, LPWSTR VendorName, DHCP_OPTION_SCOPE_INFO* ScopeInfo, DHCP_OPTION_VALUE** OptionValue) #uselib "DHCPSAPI.dll" #cfunc global DhcpV4GetOptionValue "DhcpV4GetOptionValue" wstr, int, int, wstr, wstr, intptr, intptr ; res = DhcpV4GetOptionValue(ServerIpAddress, Flags, OptionID, PolicyName, VendorName, varptr(ScopeInfo), varptr(OptionValue)) ; ServerIpAddress : LPWSTR optional -> "wstr" ; Flags : DWORD -> "int" ; OptionID : DWORD -> "int" ; PolicyName : LPWSTR optional -> "wstr" ; VendorName : LPWSTR optional -> "wstr" ; ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> "intptr" ; OptionValue : DHCP_OPTION_VALUE** in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
procDhcpV4GetOptionValue = dhcpsapi.NewProc("DhcpV4GetOptionValue")
)
// ServerIpAddress (LPWSTR optional), Flags (DWORD), OptionID (DWORD), PolicyName (LPWSTR optional), VendorName (LPWSTR optional), ScopeInfo (DHCP_OPTION_SCOPE_INFO* in/out), OptionValue (DHCP_OPTION_VALUE** in/out)
r1, _, err := procDhcpV4GetOptionValue.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ServerIpAddress))),
uintptr(Flags),
uintptr(OptionID),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(PolicyName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(VendorName))),
uintptr(ScopeInfo),
uintptr(OptionValue),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction DhcpV4GetOptionValue(
ServerIpAddress: PWideChar; // LPWSTR optional
Flags: DWORD; // DWORD
OptionID: DWORD; // DWORD
PolicyName: PWideChar; // LPWSTR optional
VendorName: PWideChar; // LPWSTR optional
ScopeInfo: Pointer; // DHCP_OPTION_SCOPE_INFO* in/out
OptionValue: Pointer // DHCP_OPTION_VALUE** in/out
): DWORD; stdcall;
external 'DHCPSAPI.dll' name 'DhcpV4GetOptionValue';result := DllCall("DHCPSAPI\DhcpV4GetOptionValue"
, "WStr", ServerIpAddress ; LPWSTR optional
, "UInt", Flags ; DWORD
, "UInt", OptionID ; DWORD
, "WStr", PolicyName ; LPWSTR optional
, "WStr", VendorName ; LPWSTR optional
, "Ptr", ScopeInfo ; DHCP_OPTION_SCOPE_INFO* in/out
, "Ptr", OptionValue ; DHCP_OPTION_VALUE** in/out
, "UInt") ; return: DWORD●DhcpV4GetOptionValue(ServerIpAddress, Flags, OptionID, PolicyName, VendorName, ScopeInfo, OptionValue) = DLL("DHCPSAPI.dll", "dword DhcpV4GetOptionValue(char*, dword, dword, char*, char*, void*, void*)")
# 呼び出し: DhcpV4GetOptionValue(ServerIpAddress, Flags, OptionID, PolicyName, VendorName, ScopeInfo, OptionValue)
# ServerIpAddress : LPWSTR optional -> "char*"
# Flags : DWORD -> "dword"
# OptionID : DWORD -> "dword"
# PolicyName : LPWSTR optional -> "char*"
# VendorName : LPWSTR optional -> "char*"
# ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> "void*"
# OptionValue : DHCP_OPTION_VALUE** in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "dhcpsapi" fn DhcpV4GetOptionValue(
ServerIpAddress: [*c]const u16, // LPWSTR optional
Flags: u32, // DWORD
OptionID: u32, // DWORD
PolicyName: [*c]const u16, // LPWSTR optional
VendorName: [*c]const u16, // LPWSTR optional
ScopeInfo: [*c]DHCP_OPTION_SCOPE_INFO, // DHCP_OPTION_SCOPE_INFO* in/out
OptionValue: [*c][*c]DHCP_OPTION_VALUE // DHCP_OPTION_VALUE** in/out
) callconv(std.os.windows.WINAPI) u32;proc DhcpV4GetOptionValue(
ServerIpAddress: WideCString, # LPWSTR optional
Flags: uint32, # DWORD
OptionID: uint32, # DWORD
PolicyName: WideCString, # LPWSTR optional
VendorName: WideCString, # LPWSTR optional
ScopeInfo: ptr DHCP_OPTION_SCOPE_INFO, # DHCP_OPTION_SCOPE_INFO* in/out
OptionValue: ptr DHCP_OPTION_VALUE # DHCP_OPTION_VALUE** in/out
): uint32 {.importc: "DhcpV4GetOptionValue", stdcall, dynlib: "DHCPSAPI.dll".}pragma(lib, "dhcpsapi");
extern(Windows)
uint DhcpV4GetOptionValue(
const(wchar)* ServerIpAddress, // LPWSTR optional
uint Flags, // DWORD
uint OptionID, // DWORD
const(wchar)* PolicyName, // LPWSTR optional
const(wchar)* VendorName, // LPWSTR optional
DHCP_OPTION_SCOPE_INFO* ScopeInfo, // DHCP_OPTION_SCOPE_INFO* in/out
DHCP_OPTION_VALUE** OptionValue // DHCP_OPTION_VALUE** in/out
);ccall((:DhcpV4GetOptionValue, "DHCPSAPI.dll"), stdcall, UInt32,
(Cwstring, UInt32, UInt32, Cwstring, Cwstring, Ptr{DHCP_OPTION_SCOPE_INFO}, Ptr{DHCP_OPTION_VALUE}),
ServerIpAddress, Flags, OptionID, PolicyName, VendorName, ScopeInfo, OptionValue)
# ServerIpAddress : LPWSTR optional -> Cwstring
# Flags : DWORD -> UInt32
# OptionID : DWORD -> UInt32
# PolicyName : LPWSTR optional -> Cwstring
# VendorName : LPWSTR optional -> Cwstring
# ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> Ptr{DHCP_OPTION_SCOPE_INFO}
# OptionValue : DHCP_OPTION_VALUE** in/out -> Ptr{DHCP_OPTION_VALUE}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t DhcpV4GetOptionValue(
const uint16_t* ServerIpAddress,
uint32_t Flags,
uint32_t OptionID,
const uint16_t* PolicyName,
const uint16_t* VendorName,
void* ScopeInfo,
void* OptionValue);
]]
local dhcpsapi = ffi.load("dhcpsapi")
-- dhcpsapi.DhcpV4GetOptionValue(ServerIpAddress, Flags, OptionID, PolicyName, VendorName, ScopeInfo, OptionValue)
-- ServerIpAddress : LPWSTR optional
-- Flags : DWORD
-- OptionID : DWORD
-- PolicyName : LPWSTR optional
-- VendorName : LPWSTR optional
-- ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out
-- OptionValue : DHCP_OPTION_VALUE** in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('DHCPSAPI.dll');
const DhcpV4GetOptionValue = lib.func('__stdcall', 'DhcpV4GetOptionValue', 'uint32_t', ['str16', 'uint32_t', 'uint32_t', 'str16', 'str16', 'void *', 'void *']);
// DhcpV4GetOptionValue(ServerIpAddress, Flags, OptionID, PolicyName, VendorName, ScopeInfo, OptionValue)
// ServerIpAddress : LPWSTR optional -> 'str16'
// Flags : DWORD -> 'uint32_t'
// OptionID : DWORD -> 'uint32_t'
// PolicyName : LPWSTR optional -> 'str16'
// VendorName : LPWSTR optional -> 'str16'
// ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> 'void *'
// OptionValue : DHCP_OPTION_VALUE** in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("DHCPSAPI.dll", {
DhcpV4GetOptionValue: { parameters: ["buffer", "u32", "u32", "buffer", "buffer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.DhcpV4GetOptionValue(ServerIpAddress, Flags, OptionID, PolicyName, VendorName, ScopeInfo, OptionValue)
// ServerIpAddress : LPWSTR optional -> "buffer"
// Flags : DWORD -> "u32"
// OptionID : DWORD -> "u32"
// PolicyName : LPWSTR optional -> "buffer"
// VendorName : LPWSTR optional -> "buffer"
// ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> "pointer"
// OptionValue : DHCP_OPTION_VALUE** in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t DhcpV4GetOptionValue(
const uint16_t* ServerIpAddress,
uint32_t Flags,
uint32_t OptionID,
const uint16_t* PolicyName,
const uint16_t* VendorName,
void* ScopeInfo,
void* OptionValue);
C, "DHCPSAPI.dll");
// $ffi->DhcpV4GetOptionValue(ServerIpAddress, Flags, OptionID, PolicyName, VendorName, ScopeInfo, OptionValue);
// ServerIpAddress : LPWSTR optional
// Flags : DWORD
// OptionID : DWORD
// PolicyName : LPWSTR optional
// VendorName : LPWSTR optional
// ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out
// OptionValue : DHCP_OPTION_VALUE** 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 DhcpV4GetOptionValue(
WString ServerIpAddress, // LPWSTR optional
int Flags, // DWORD
int OptionID, // DWORD
WString PolicyName, // LPWSTR optional
WString VendorName, // LPWSTR optional
Pointer ScopeInfo, // DHCP_OPTION_SCOPE_INFO* in/out
Pointer OptionValue // DHCP_OPTION_VALUE** in/out
);
}@[Link("dhcpsapi")]
lib LibDHCPSAPI
fun DhcpV4GetOptionValue = DhcpV4GetOptionValue(
ServerIpAddress : UInt16*, # LPWSTR optional
Flags : UInt32, # DWORD
OptionID : UInt32, # DWORD
PolicyName : UInt16*, # LPWSTR optional
VendorName : UInt16*, # LPWSTR optional
ScopeInfo : DHCP_OPTION_SCOPE_INFO*, # DHCP_OPTION_SCOPE_INFO* in/out
OptionValue : DHCP_OPTION_VALUE** # DHCP_OPTION_VALUE** 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 DhcpV4GetOptionValueNative = Uint32 Function(Pointer<Utf16>, Uint32, Uint32, Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>, Pointer<Void>);
typedef DhcpV4GetOptionValueDart = int Function(Pointer<Utf16>, int, int, Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>, Pointer<Void>);
final DhcpV4GetOptionValue = DynamicLibrary.open('DHCPSAPI.dll')
.lookupFunction<DhcpV4GetOptionValueNative, DhcpV4GetOptionValueDart>('DhcpV4GetOptionValue');
// ServerIpAddress : LPWSTR optional -> Pointer<Utf16>
// Flags : DWORD -> Uint32
// OptionID : DWORD -> Uint32
// PolicyName : LPWSTR optional -> Pointer<Utf16>
// VendorName : LPWSTR optional -> Pointer<Utf16>
// ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> Pointer<Void>
// OptionValue : DHCP_OPTION_VALUE** in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DhcpV4GetOptionValue(
ServerIpAddress: PWideChar; // LPWSTR optional
Flags: DWORD; // DWORD
OptionID: DWORD; // DWORD
PolicyName: PWideChar; // LPWSTR optional
VendorName: PWideChar; // LPWSTR optional
ScopeInfo: Pointer; // DHCP_OPTION_SCOPE_INFO* in/out
OptionValue: Pointer // DHCP_OPTION_VALUE** in/out
): DWORD; stdcall;
external 'DHCPSAPI.dll' name 'DhcpV4GetOptionValue';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DhcpV4GetOptionValue"
c_DhcpV4GetOptionValue :: CWString -> Word32 -> Word32 -> CWString -> CWString -> Ptr () -> Ptr () -> IO Word32
-- ServerIpAddress : LPWSTR optional -> CWString
-- Flags : DWORD -> Word32
-- OptionID : DWORD -> Word32
-- PolicyName : LPWSTR optional -> CWString
-- VendorName : LPWSTR optional -> CWString
-- ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> Ptr ()
-- OptionValue : DHCP_OPTION_VALUE** in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let dhcpv4getoptionvalue =
foreign "DhcpV4GetOptionValue"
((ptr uint16_t) @-> uint32_t @-> uint32_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr void) @-> (ptr void) @-> returning uint32_t)
(* ServerIpAddress : LPWSTR optional -> (ptr uint16_t) *)
(* Flags : DWORD -> uint32_t *)
(* OptionID : DWORD -> uint32_t *)
(* PolicyName : LPWSTR optional -> (ptr uint16_t) *)
(* VendorName : LPWSTR optional -> (ptr uint16_t) *)
(* ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> (ptr void) *)
(* OptionValue : DHCP_OPTION_VALUE** 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 ("DhcpV4GetOptionValue" dhcp-v4-get-option-value :convention :stdcall) :uint32
(server-ip-address (:string :encoding :utf-16le)) ; LPWSTR optional
(flags :uint32) ; DWORD
(option-id :uint32) ; DWORD
(policy-name (:string :encoding :utf-16le)) ; LPWSTR optional
(vendor-name (:string :encoding :utf-16le)) ; LPWSTR optional
(scope-info :pointer) ; DHCP_OPTION_SCOPE_INFO* in/out
(option-value :pointer)) ; DHCP_OPTION_VALUE** in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DhcpV4GetOptionValue = Win32::API::More->new('DHCPSAPI',
'DWORD DhcpV4GetOptionValue(LPCWSTR ServerIpAddress, DWORD Flags, DWORD OptionID, LPCWSTR PolicyName, LPCWSTR VendorName, LPVOID ScopeInfo, LPVOID OptionValue)');
# my $ret = $DhcpV4GetOptionValue->Call($ServerIpAddress, $Flags, $OptionID, $PolicyName, $VendorName, $ScopeInfo, $OptionValue);
# ServerIpAddress : LPWSTR optional -> LPCWSTR
# Flags : DWORD -> DWORD
# OptionID : DWORD -> DWORD
# PolicyName : LPWSTR optional -> LPCWSTR
# VendorName : LPWSTR optional -> LPCWSTR
# ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> LPVOID
# OptionValue : DHCP_OPTION_VALUE** in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。