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

DhcpSetServerBindingInfo

関数
DHCPサーバーのネットワークバインド情報を設定する。
DLLDHCPSAPI.dll呼出規約winapi対応OSwindowsserver2000

シグネチャ

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

DWORD DhcpSetServerBindingInfo(
    LPCWSTR ServerIpAddress,   // optional
    DWORD Flags,
    DHCP_BIND_ELEMENT_ARRAY* BindElementInfo
);

パラメーター

名前方向説明
ServerIpAddressLPCWSTRinoptional対象DHCPサーバーのIPアドレスを示すUnicode文字列。ローカルサーバーならNULLを指定できる。
FlagsDWORDin動作を制御するビットフラグ。現在は予約済みで0を指定する。
BindElementInfoDHCP_BIND_ELEMENT_ARRAY*inoutサーバーのバインド構成を保持するDHCP_BIND_ELEMENT_ARRAY構造体へのポインタ。設定する束縛要素配列を渡す。

戻り値の型: DWORD

各言語での呼び出し定義

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

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

DhcpSetServerBindingInfo = ctypes.windll.dhcpsapi.DhcpSetServerBindingInfo
DhcpSetServerBindingInfo.restype = wintypes.DWORD
DhcpSetServerBindingInfo.argtypes = [
    wintypes.LPCWSTR,  # ServerIpAddress : LPCWSTR optional
    wintypes.DWORD,  # Flags : DWORD
    ctypes.c_void_p,  # BindElementInfo : DHCP_BIND_ELEMENT_ARRAY* in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
	procDhcpSetServerBindingInfo = dhcpsapi.NewProc("DhcpSetServerBindingInfo")
)

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

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

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

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

関連項目

使用する型