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