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

DhcpSetOptionValues

関数
指定スコープに複数のDHCPオプション値をまとめて設定する。
DLLDHCPSAPI.dll呼出規約winapi対応OSwindowsserver2008

シグネチャ

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

DWORD DhcpSetOptionValues(
    LPCWSTR ServerIpAddress,   // optional
    const DHCP_OPTION_SCOPE_INFO* ScopeInfo,
    const DHCP_OPTION_VALUE_ARRAY* OptionValues
);

パラメーター

名前方向説明
ServerIpAddressLPCWSTRinoptional操作対象DHCPサーバのIPアドレスまたはホスト名(Unicode)。
ScopeInfoDHCP_OPTION_SCOPE_INFO*in値を適用する範囲を示すDHCP_OPTION_SCOPE_INFO構造体へのポインタ。
OptionValuesDHCP_OPTION_VALUE_ARRAY*in設定する複数オプション値を格納したDHCP_OPTION_VALUE_ARRAY構造体へのポインタ。

戻り値の型: DWORD

各言語での呼び出し定義

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

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

DhcpSetOptionValues = ctypes.windll.dhcpsapi.DhcpSetOptionValues
DhcpSetOptionValues.restype = wintypes.DWORD
DhcpSetOptionValues.argtypes = [
    wintypes.LPCWSTR,  # ServerIpAddress : LPCWSTR optional
    ctypes.c_void_p,  # ScopeInfo : DHCP_OPTION_SCOPE_INFO*
    ctypes.c_void_p,  # OptionValues : DHCP_OPTION_VALUE_ARRAY*
]
require 'fiddle'
require 'fiddle/import'

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

var (
	dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
	procDhcpSetOptionValues = dhcpsapi.NewProc("DhcpSetOptionValues")
)

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

extern "dhcpsapi" fn DhcpSetOptionValues(
    ServerIpAddress: [*c]const u16, // LPCWSTR optional
    ScopeInfo: [*c]DHCP_OPTION_SCOPE_INFO, // DHCP_OPTION_SCOPE_INFO*
    OptionValues: [*c]DHCP_OPTION_VALUE_ARRAY // DHCP_OPTION_VALUE_ARRAY*
) callconv(std.os.windows.WINAPI) u32;
proc DhcpSetOptionValues(
    ServerIpAddress: WideCString,  # LPCWSTR optional
    ScopeInfo: ptr DHCP_OPTION_SCOPE_INFO,  # DHCP_OPTION_SCOPE_INFO*
    OptionValues: ptr DHCP_OPTION_VALUE_ARRAY  # DHCP_OPTION_VALUE_ARRAY*
): uint32 {.importc: "DhcpSetOptionValues", stdcall, dynlib: "DHCPSAPI.dll".}
pragma(lib, "dhcpsapi");
extern(Windows)
uint DhcpSetOptionValues(
    const(wchar)* ServerIpAddress,   // LPCWSTR optional
    DHCP_OPTION_SCOPE_INFO* ScopeInfo,   // DHCP_OPTION_SCOPE_INFO*
    DHCP_OPTION_VALUE_ARRAY* OptionValues   // DHCP_OPTION_VALUE_ARRAY*
);
ccall((:DhcpSetOptionValues, "DHCPSAPI.dll"), stdcall, UInt32,
      (Cwstring, Ptr{DHCP_OPTION_SCOPE_INFO}, Ptr{DHCP_OPTION_VALUE_ARRAY}),
      ServerIpAddress, ScopeInfo, OptionValues)
# ServerIpAddress : LPCWSTR optional -> Cwstring
# ScopeInfo : DHCP_OPTION_SCOPE_INFO* -> Ptr{DHCP_OPTION_SCOPE_INFO}
# OptionValues : DHCP_OPTION_VALUE_ARRAY* -> Ptr{DHCP_OPTION_VALUE_ARRAY}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t DhcpSetOptionValues(
    const uint16_t* ServerIpAddress,
    void* ScopeInfo,
    void* OptionValues);
]]
local dhcpsapi = ffi.load("dhcpsapi")
-- dhcpsapi.DhcpSetOptionValues(ServerIpAddress, ScopeInfo, OptionValues)
-- ServerIpAddress : LPCWSTR optional
-- ScopeInfo : DHCP_OPTION_SCOPE_INFO*
-- OptionValues : DHCP_OPTION_VALUE_ARRAY*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('DHCPSAPI.dll');
const DhcpSetOptionValues = lib.func('__stdcall', 'DhcpSetOptionValues', 'uint32_t', ['str16', 'void *', 'void *']);
// DhcpSetOptionValues(ServerIpAddress, ScopeInfo, OptionValues)
// ServerIpAddress : LPCWSTR optional -> 'str16'
// ScopeInfo : DHCP_OPTION_SCOPE_INFO* -> 'void *'
// OptionValues : DHCP_OPTION_VALUE_ARRAY* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("DHCPSAPI.dll", {
  DhcpSetOptionValues: { parameters: ["buffer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.DhcpSetOptionValues(ServerIpAddress, ScopeInfo, OptionValues)
// ServerIpAddress : LPCWSTR optional -> "buffer"
// ScopeInfo : DHCP_OPTION_SCOPE_INFO* -> "pointer"
// OptionValues : DHCP_OPTION_VALUE_ARRAY* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t DhcpSetOptionValues(
    const uint16_t* ServerIpAddress,
    void* ScopeInfo,
    void* OptionValues);
C, "DHCPSAPI.dll");
// $ffi->DhcpSetOptionValues(ServerIpAddress, ScopeInfo, OptionValues);
// ServerIpAddress : LPCWSTR optional
// ScopeInfo : DHCP_OPTION_SCOPE_INFO*
// OptionValues : DHCP_OPTION_VALUE_ARRAY*
// 構造体/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 DhcpSetOptionValues(
        WString ServerIpAddress,   // LPCWSTR optional
        Pointer ScopeInfo,   // DHCP_OPTION_SCOPE_INFO*
        Pointer OptionValues   // DHCP_OPTION_VALUE_ARRAY*
    );
}
@[Link("dhcpsapi")]
lib LibDHCPSAPI
  fun DhcpSetOptionValues = DhcpSetOptionValues(
    ServerIpAddress : UInt16*,   # LPCWSTR optional
    ScopeInfo : DHCP_OPTION_SCOPE_INFO*,   # DHCP_OPTION_SCOPE_INFO*
    OptionValues : DHCP_OPTION_VALUE_ARRAY*   # DHCP_OPTION_VALUE_ARRAY*
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef DhcpSetOptionValuesNative = Uint32 Function(Pointer<Utf16>, Pointer<Void>, Pointer<Void>);
typedef DhcpSetOptionValuesDart = int Function(Pointer<Utf16>, Pointer<Void>, Pointer<Void>);
final DhcpSetOptionValues = DynamicLibrary.open('DHCPSAPI.dll')
    .lookupFunction<DhcpSetOptionValuesNative, DhcpSetOptionValuesDart>('DhcpSetOptionValues');
// ServerIpAddress : LPCWSTR optional -> Pointer<Utf16>
// ScopeInfo : DHCP_OPTION_SCOPE_INFO* -> Pointer<Void>
// OptionValues : DHCP_OPTION_VALUE_ARRAY* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DhcpSetOptionValues(
  ServerIpAddress: PWideChar;   // LPCWSTR optional
  ScopeInfo: Pointer;   // DHCP_OPTION_SCOPE_INFO*
  OptionValues: Pointer   // DHCP_OPTION_VALUE_ARRAY*
): DWORD; stdcall;
  external 'DHCPSAPI.dll' name 'DhcpSetOptionValues';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DhcpSetOptionValues"
  c_DhcpSetOptionValues :: CWString -> Ptr () -> Ptr () -> IO Word32
-- ServerIpAddress : LPCWSTR optional -> CWString
-- ScopeInfo : DHCP_OPTION_SCOPE_INFO* -> Ptr ()
-- OptionValues : DHCP_OPTION_VALUE_ARRAY* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let dhcpsetoptionvalues =
  foreign "DhcpSetOptionValues"
    ((ptr uint16_t) @-> (ptr void) @-> (ptr void) @-> returning uint32_t)
(* ServerIpAddress : LPCWSTR optional -> (ptr uint16_t) *)
(* ScopeInfo : DHCP_OPTION_SCOPE_INFO* -> (ptr void) *)
(* OptionValues : DHCP_OPTION_VALUE_ARRAY* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library dhcpsapi (t "DHCPSAPI.dll"))
(cffi:use-foreign-library dhcpsapi)

(cffi:defcfun ("DhcpSetOptionValues" dhcp-set-option-values :convention :stdcall) :uint32
  (server-ip-address (:string :encoding :utf-16le))   ; LPCWSTR optional
  (scope-info :pointer)   ; DHCP_OPTION_SCOPE_INFO*
  (option-values :pointer))   ; DHCP_OPTION_VALUE_ARRAY*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DhcpSetOptionValues = Win32::API::More->new('DHCPSAPI',
    'DWORD DhcpSetOptionValues(LPCWSTR ServerIpAddress, LPVOID ScopeInfo, LPVOID OptionValues)');
# my $ret = $DhcpSetOptionValues->Call($ServerIpAddress, $ScopeInfo, $OptionValues);
# ServerIpAddress : LPCWSTR optional -> LPCWSTR
# ScopeInfo : DHCP_OPTION_SCOPE_INFO* -> LPVOID
# OptionValues : DHCP_OPTION_VALUE_ARRAY* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型