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

DhcpCreateOption

関数
DHCPサーバーに新しいオプション定義を作成する。
DLLDHCPSAPI.dll呼出規約winapi対応OSwindowsserver2008

シグネチャ

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

DWORD DhcpCreateOption(
    LPCWSTR ServerIpAddress,   // optional
    DWORD OptionID,
    const DHCP_OPTION* OptionInfo
);

パラメーター

名前方向説明
ServerIpAddressLPCWSTRinoptional操作対象DHCPサーバのIPアドレスまたはホスト名(Unicode)。
OptionIDDWORDin作成するDHCPオプションのID(オプションコード)を指定する。
OptionInfoDHCP_OPTION*in作成するオプションの定義を格納したDHCP_OPTION構造体へのポインタ。

戻り値の型: DWORD

各言語での呼び出し定義

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

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

DhcpCreateOption = ctypes.windll.dhcpsapi.DhcpCreateOption
DhcpCreateOption.restype = wintypes.DWORD
DhcpCreateOption.argtypes = [
    wintypes.LPCWSTR,  # ServerIpAddress : LPCWSTR optional
    wintypes.DWORD,  # OptionID : DWORD
    ctypes.c_void_p,  # OptionInfo : DHCP_OPTION*
]
require 'fiddle'
require 'fiddle/import'

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

var (
	dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
	procDhcpCreateOption = dhcpsapi.NewProc("DhcpCreateOption")
)

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

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

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

foreign import stdcall safe "DhcpCreateOption"
  c_DhcpCreateOption :: CWString -> Word32 -> Ptr () -> IO Word32
-- ServerIpAddress : LPCWSTR optional -> CWString
-- OptionID : DWORD -> Word32
-- OptionInfo : DHCP_OPTION* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

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

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

関連項目

使用する型