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

DhcpV4GetAllOptionValues

関数
指定スコープのすべてのIPv4 DHCPオプション値を取得する。
DLLDHCPSAPI.dll呼出規約winapi対応OSwindowsserver2012

シグネチャ

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

DWORD DhcpV4GetAllOptionValues(
    LPWSTR ServerIpAddress,   // optional
    DWORD Flags,
    DHCP_OPTION_SCOPE_INFO* ScopeInfo,
    DHCP_ALL_OPTION_VALUES_PB** Values
);

パラメーター

名前方向説明
ServerIpAddressLPWSTRinoptional対象DHCPサーバーのIPアドレスを示すUnicode文字列。ローカルならNULL可。
FlagsDWORDin予約済みフラグ。0を指定する。
ScopeInfoDHCP_OPTION_SCOPE_INFO*inout全オプション値を取得する適用範囲を示すDHCP_OPTION_SCOPE_INFO構造体へのポインタ。
ValuesDHCP_ALL_OPTION_VALUES_PB**inout取得したポリシー込みの全オプション値DHCP_ALL_OPTION_VALUES_PBへのポインタを受け取る二重ポインタ。使用後は解放する。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD DhcpV4GetAllOptionValues(
    LPWSTR ServerIpAddress,   // optional
    DWORD Flags,
    DHCP_OPTION_SCOPE_INFO* ScopeInfo,
    DHCP_ALL_OPTION_VALUES_PB** Values
);
[DllImport("DHCPSAPI.dll", ExactSpelling = true)]
static extern uint DhcpV4GetAllOptionValues(
    [MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress,   // LPWSTR optional
    uint Flags,   // DWORD
    IntPtr ScopeInfo,   // DHCP_OPTION_SCOPE_INFO* in/out
    IntPtr Values   // DHCP_ALL_OPTION_VALUES_PB** in/out
);
<DllImport("DHCPSAPI.dll", ExactSpelling:=True)>
Public Shared Function DhcpV4GetAllOptionValues(
    <MarshalAs(UnmanagedType.LPWStr)> ServerIpAddress As String,   ' LPWSTR optional
    Flags As UInteger,   ' DWORD
    ScopeInfo As IntPtr,   ' DHCP_OPTION_SCOPE_INFO* in/out
    Values As IntPtr   ' DHCP_ALL_OPTION_VALUES_PB** in/out
) As UInteger
End Function
' ServerIpAddress : LPWSTR optional
' Flags : DWORD
' ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out
' Values : DHCP_ALL_OPTION_VALUES_PB** in/out
Declare PtrSafe Function DhcpV4GetAllOptionValues Lib "dhcpsapi" ( _
    ByVal ServerIpAddress As LongPtr, _
    ByVal Flags As Long, _
    ByVal ScopeInfo As LongPtr, _
    ByVal Values As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DhcpV4GetAllOptionValues = ctypes.windll.dhcpsapi.DhcpV4GetAllOptionValues
DhcpV4GetAllOptionValues.restype = wintypes.DWORD
DhcpV4GetAllOptionValues.argtypes = [
    wintypes.LPCWSTR,  # ServerIpAddress : LPWSTR optional
    wintypes.DWORD,  # Flags : DWORD
    ctypes.c_void_p,  # ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out
    ctypes.c_void_p,  # Values : DHCP_ALL_OPTION_VALUES_PB** in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('DHCPSAPI.dll')
DhcpV4GetAllOptionValues = Fiddle::Function.new(
  lib['DhcpV4GetAllOptionValues'],
  [
    Fiddle::TYPE_VOIDP,  # ServerIpAddress : LPWSTR optional
    -Fiddle::TYPE_INT,  # Flags : DWORD
    Fiddle::TYPE_VOIDP,  # ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out
    Fiddle::TYPE_VOIDP,  # Values : DHCP_ALL_OPTION_VALUES_PB** in/out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "dhcpsapi")]
extern "system" {
    fn DhcpV4GetAllOptionValues(
        ServerIpAddress: *mut u16,  // LPWSTR optional
        Flags: u32,  // DWORD
        ScopeInfo: *mut DHCP_OPTION_SCOPE_INFO,  // DHCP_OPTION_SCOPE_INFO* in/out
        Values: *mut *mut DHCP_ALL_OPTION_VALUES_PB  // DHCP_ALL_OPTION_VALUES_PB** in/out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("DHCPSAPI.dll")]
public static extern uint DhcpV4GetAllOptionValues([MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress, uint Flags, IntPtr ScopeInfo, IntPtr Values);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DHCPSAPI_DhcpV4GetAllOptionValues' -Namespace Win32 -PassThru
# $api::DhcpV4GetAllOptionValues(ServerIpAddress, Flags, ScopeInfo, Values)
#uselib "DHCPSAPI.dll"
#func global DhcpV4GetAllOptionValues "DhcpV4GetAllOptionValues" sptr, sptr, sptr, sptr
; DhcpV4GetAllOptionValues ServerIpAddress, Flags, varptr(ScopeInfo), varptr(Values)   ; 戻り値は stat
; ServerIpAddress : LPWSTR optional -> "sptr"
; Flags : DWORD -> "sptr"
; ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> "sptr"
; Values : DHCP_ALL_OPTION_VALUES_PB** in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "DHCPSAPI.dll"
#cfunc global DhcpV4GetAllOptionValues "DhcpV4GetAllOptionValues" wstr, int, var, var
; res = DhcpV4GetAllOptionValues(ServerIpAddress, Flags, ScopeInfo, Values)
; ServerIpAddress : LPWSTR optional -> "wstr"
; Flags : DWORD -> "int"
; ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> "var"
; Values : DHCP_ALL_OPTION_VALUES_PB** in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD DhcpV4GetAllOptionValues(LPWSTR ServerIpAddress, DWORD Flags, DHCP_OPTION_SCOPE_INFO* ScopeInfo, DHCP_ALL_OPTION_VALUES_PB** Values)
#uselib "DHCPSAPI.dll"
#cfunc global DhcpV4GetAllOptionValues "DhcpV4GetAllOptionValues" wstr, int, var, var
; res = DhcpV4GetAllOptionValues(ServerIpAddress, Flags, ScopeInfo, Values)
; ServerIpAddress : LPWSTR optional -> "wstr"
; Flags : DWORD -> "int"
; ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> "var"
; Values : DHCP_ALL_OPTION_VALUES_PB** in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
	procDhcpV4GetAllOptionValues = dhcpsapi.NewProc("DhcpV4GetAllOptionValues")
)

// ServerIpAddress (LPWSTR optional), Flags (DWORD), ScopeInfo (DHCP_OPTION_SCOPE_INFO* in/out), Values (DHCP_ALL_OPTION_VALUES_PB** in/out)
r1, _, err := procDhcpV4GetAllOptionValues.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ServerIpAddress))),
	uintptr(Flags),
	uintptr(ScopeInfo),
	uintptr(Values),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function DhcpV4GetAllOptionValues(
  ServerIpAddress: PWideChar;   // LPWSTR optional
  Flags: DWORD;   // DWORD
  ScopeInfo: Pointer;   // DHCP_OPTION_SCOPE_INFO* in/out
  Values: Pointer   // DHCP_ALL_OPTION_VALUES_PB** in/out
): DWORD; stdcall;
  external 'DHCPSAPI.dll' name 'DhcpV4GetAllOptionValues';
result := DllCall("DHCPSAPI\DhcpV4GetAllOptionValues"
    , "WStr", ServerIpAddress   ; LPWSTR optional
    , "UInt", Flags   ; DWORD
    , "Ptr", ScopeInfo   ; DHCP_OPTION_SCOPE_INFO* in/out
    , "Ptr", Values   ; DHCP_ALL_OPTION_VALUES_PB** in/out
    , "UInt")   ; return: DWORD
●DhcpV4GetAllOptionValues(ServerIpAddress, Flags, ScopeInfo, Values) = DLL("DHCPSAPI.dll", "dword DhcpV4GetAllOptionValues(char*, dword, void*, void*)")
# 呼び出し: DhcpV4GetAllOptionValues(ServerIpAddress, Flags, ScopeInfo, Values)
# ServerIpAddress : LPWSTR optional -> "char*"
# Flags : DWORD -> "dword"
# ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> "void*"
# Values : DHCP_ALL_OPTION_VALUES_PB** in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "dhcpsapi" fn DhcpV4GetAllOptionValues(
    ServerIpAddress: [*c]const u16, // LPWSTR optional
    Flags: u32, // DWORD
    ScopeInfo: [*c]DHCP_OPTION_SCOPE_INFO, // DHCP_OPTION_SCOPE_INFO* in/out
    Values: [*c][*c]DHCP_ALL_OPTION_VALUES_PB // DHCP_ALL_OPTION_VALUES_PB** in/out
) callconv(std.os.windows.WINAPI) u32;
proc DhcpV4GetAllOptionValues(
    ServerIpAddress: WideCString,  # LPWSTR optional
    Flags: uint32,  # DWORD
    ScopeInfo: ptr DHCP_OPTION_SCOPE_INFO,  # DHCP_OPTION_SCOPE_INFO* in/out
    Values: ptr DHCP_ALL_OPTION_VALUES_PB  # DHCP_ALL_OPTION_VALUES_PB** in/out
): uint32 {.importc: "DhcpV4GetAllOptionValues", stdcall, dynlib: "DHCPSAPI.dll".}
pragma(lib, "dhcpsapi");
extern(Windows)
uint DhcpV4GetAllOptionValues(
    const(wchar)* ServerIpAddress,   // LPWSTR optional
    uint Flags,   // DWORD
    DHCP_OPTION_SCOPE_INFO* ScopeInfo,   // DHCP_OPTION_SCOPE_INFO* in/out
    DHCP_ALL_OPTION_VALUES_PB** Values   // DHCP_ALL_OPTION_VALUES_PB** in/out
);
ccall((:DhcpV4GetAllOptionValues, "DHCPSAPI.dll"), stdcall, UInt32,
      (Cwstring, UInt32, Ptr{DHCP_OPTION_SCOPE_INFO}, Ptr{DHCP_ALL_OPTION_VALUES_PB}),
      ServerIpAddress, Flags, ScopeInfo, Values)
# ServerIpAddress : LPWSTR optional -> Cwstring
# Flags : DWORD -> UInt32
# ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> Ptr{DHCP_OPTION_SCOPE_INFO}
# Values : DHCP_ALL_OPTION_VALUES_PB** in/out -> Ptr{DHCP_ALL_OPTION_VALUES_PB}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t DhcpV4GetAllOptionValues(
    const uint16_t* ServerIpAddress,
    uint32_t Flags,
    void* ScopeInfo,
    void* Values);
]]
local dhcpsapi = ffi.load("dhcpsapi")
-- dhcpsapi.DhcpV4GetAllOptionValues(ServerIpAddress, Flags, ScopeInfo, Values)
-- ServerIpAddress : LPWSTR optional
-- Flags : DWORD
-- ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out
-- Values : DHCP_ALL_OPTION_VALUES_PB** in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('DHCPSAPI.dll');
const DhcpV4GetAllOptionValues = lib.func('__stdcall', 'DhcpV4GetAllOptionValues', 'uint32_t', ['str16', 'uint32_t', 'void *', 'void *']);
// DhcpV4GetAllOptionValues(ServerIpAddress, Flags, ScopeInfo, Values)
// ServerIpAddress : LPWSTR optional -> 'str16'
// Flags : DWORD -> 'uint32_t'
// ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> 'void *'
// Values : DHCP_ALL_OPTION_VALUES_PB** in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("DHCPSAPI.dll", {
  DhcpV4GetAllOptionValues: { parameters: ["buffer", "u32", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.DhcpV4GetAllOptionValues(ServerIpAddress, Flags, ScopeInfo, Values)
// ServerIpAddress : LPWSTR optional -> "buffer"
// Flags : DWORD -> "u32"
// ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> "pointer"
// Values : DHCP_ALL_OPTION_VALUES_PB** in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t DhcpV4GetAllOptionValues(
    const uint16_t* ServerIpAddress,
    uint32_t Flags,
    void* ScopeInfo,
    void* Values);
C, "DHCPSAPI.dll");
// $ffi->DhcpV4GetAllOptionValues(ServerIpAddress, Flags, ScopeInfo, Values);
// ServerIpAddress : LPWSTR optional
// Flags : DWORD
// ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out
// Values : DHCP_ALL_OPTION_VALUES_PB** 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 DhcpV4GetAllOptionValues(
        WString ServerIpAddress,   // LPWSTR optional
        int Flags,   // DWORD
        Pointer ScopeInfo,   // DHCP_OPTION_SCOPE_INFO* in/out
        Pointer Values   // DHCP_ALL_OPTION_VALUES_PB** in/out
    );
}
@[Link("dhcpsapi")]
lib LibDHCPSAPI
  fun DhcpV4GetAllOptionValues = DhcpV4GetAllOptionValues(
    ServerIpAddress : UInt16*,   # LPWSTR optional
    Flags : UInt32,   # DWORD
    ScopeInfo : DHCP_OPTION_SCOPE_INFO*,   # DHCP_OPTION_SCOPE_INFO* in/out
    Values : DHCP_ALL_OPTION_VALUES_PB**   # DHCP_ALL_OPTION_VALUES_PB** 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 DhcpV4GetAllOptionValuesNative = Uint32 Function(Pointer<Utf16>, Uint32, Pointer<Void>, Pointer<Void>);
typedef DhcpV4GetAllOptionValuesDart = int Function(Pointer<Utf16>, int, Pointer<Void>, Pointer<Void>);
final DhcpV4GetAllOptionValues = DynamicLibrary.open('DHCPSAPI.dll')
    .lookupFunction<DhcpV4GetAllOptionValuesNative, DhcpV4GetAllOptionValuesDart>('DhcpV4GetAllOptionValues');
// ServerIpAddress : LPWSTR optional -> Pointer<Utf16>
// Flags : DWORD -> Uint32
// ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> Pointer<Void>
// Values : DHCP_ALL_OPTION_VALUES_PB** in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DhcpV4GetAllOptionValues(
  ServerIpAddress: PWideChar;   // LPWSTR optional
  Flags: DWORD;   // DWORD
  ScopeInfo: Pointer;   // DHCP_OPTION_SCOPE_INFO* in/out
  Values: Pointer   // DHCP_ALL_OPTION_VALUES_PB** in/out
): DWORD; stdcall;
  external 'DHCPSAPI.dll' name 'DhcpV4GetAllOptionValues';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DhcpV4GetAllOptionValues"
  c_DhcpV4GetAllOptionValues :: CWString -> Word32 -> Ptr () -> Ptr () -> IO Word32
-- ServerIpAddress : LPWSTR optional -> CWString
-- Flags : DWORD -> Word32
-- ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> Ptr ()
-- Values : DHCP_ALL_OPTION_VALUES_PB** in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let dhcpv4getalloptionvalues =
  foreign "DhcpV4GetAllOptionValues"
    ((ptr uint16_t) @-> uint32_t @-> (ptr void) @-> (ptr void) @-> returning uint32_t)
(* ServerIpAddress : LPWSTR optional -> (ptr uint16_t) *)
(* Flags : DWORD -> uint32_t *)
(* ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> (ptr void) *)
(* Values : DHCP_ALL_OPTION_VALUES_PB** 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 ("DhcpV4GetAllOptionValues" dhcp-v4-get-all-option-values :convention :stdcall) :uint32
  (server-ip-address (:string :encoding :utf-16le))   ; LPWSTR optional
  (flags :uint32)   ; DWORD
  (scope-info :pointer)   ; DHCP_OPTION_SCOPE_INFO* in/out
  (values :pointer))   ; DHCP_ALL_OPTION_VALUES_PB** in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DhcpV4GetAllOptionValues = Win32::API::More->new('DHCPSAPI',
    'DWORD DhcpV4GetAllOptionValues(LPCWSTR ServerIpAddress, DWORD Flags, LPVOID ScopeInfo, LPVOID Values)');
# my $ret = $DhcpV4GetAllOptionValues->Call($ServerIpAddress, $Flags, $ScopeInfo, $Values);
# ServerIpAddress : LPWSTR optional -> LPCWSTR
# Flags : DWORD -> DWORD
# ScopeInfo : DHCP_OPTION_SCOPE_INFO* in/out -> LPVOID
# Values : DHCP_ALL_OPTION_VALUES_PB** in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型