ホーム › NetworkManagement.Dhcp › DhcpV4CreateClientInfo
DhcpV4CreateClientInfo
関数DHCPサーバーに新しいIPv4クライアント予約情報を作成する。
シグネチャ
// DHCPSAPI.dll
#include <windows.h>
DWORD DhcpV4CreateClientInfo(
LPCWSTR ServerIpAddress, // optional
const DHCP_CLIENT_INFO_PB* ClientInfo
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ServerIpAddress | LPCWSTR | inoptional | DHCP サーバーの IP アドレスまたはホスト名を表す、null で終わる Unicode 文字列へのポインター。 |
| ClientInfo | DHCP_CLIENT_INFO_PB* | in | DHCP クライアントのリース レコード情報を格納する DHCP_CLIENT_INFO_PB 構造体へのポインター。この構造体の ClientIpAddress フィールドおよび ClientHardwareAddress フィールドは必須で、その他はすべて省略可能です。 |
戻り値の型: DWORD
公式ドキュメント
DHCP サーバー データベースに DHCPv4 クライアントのリース レコードを作成します。
戻り値
関数が成功した場合は、ERROR_SUCCESS を返します。
関数が失敗した場合は、次のいずれかの値、または DHCP Server Management API Error Codes のエラー コードを返します。
| 値 | 意味 |
|---|---|
| 1 つ以上のパラメーターが無効です。 | |
| この呼び出しは、DHCP Administrators セキュリティ グループのメンバーではないクライアントによって実行されました。 | |
| ClientInfo で渡された ClientIpAddress が、DHCP サーバーに構成されているどの DHCPv4 スコープとも一致しません。 | |
| 指定された DHCP クライアント レコードは、DHCP サーバー データベースに既に存在します。 |
解説(Remarks)
この関数は、サーバーに構成された ClientIpAddress に対応するスコープが存在しない場合はリースの作成を許可せず、代わりに ERROR_DHCP_SUBNET_NOT_PRESENT を返します。この関数は、IP アドレスの競合を避けるために、指定されたクライアント IP アドレスを使用不可 (または配布済み) としてマークします。このようにマークされたアドレスは、スコープのアドレス統計にも反映されます。
DhcpCreateClientInfoVQ とは異なり、この関数はリース レコードの作成時に、ClientInfo に渡された DHCP_CLIENT_INFO_PB 構造体の bClientType、AddressState、Status、ProbationEnds、QuarantineCapable の各フィールドを使用します。また、ClientInfo 内で渡された場合は、新しいリース レコードに新規フィールド PolicyName も追加します。PolicyName が DHCP サーバーまたは対応するスコープに構成されている有効なポリシーに対応しているかどうかの検証は行われません。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// DHCPSAPI.dll
#include <windows.h>
DWORD DhcpV4CreateClientInfo(
LPCWSTR ServerIpAddress, // optional
const DHCP_CLIENT_INFO_PB* ClientInfo
);[DllImport("DHCPSAPI.dll", ExactSpelling = true)]
static extern uint DhcpV4CreateClientInfo(
[MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress, // LPCWSTR optional
IntPtr ClientInfo // DHCP_CLIENT_INFO_PB*
);<DllImport("DHCPSAPI.dll", ExactSpelling:=True)>
Public Shared Function DhcpV4CreateClientInfo(
<MarshalAs(UnmanagedType.LPWStr)> ServerIpAddress As String, ' LPCWSTR optional
ClientInfo As IntPtr ' DHCP_CLIENT_INFO_PB*
) As UInteger
End Function' ServerIpAddress : LPCWSTR optional
' ClientInfo : DHCP_CLIENT_INFO_PB*
Declare PtrSafe Function DhcpV4CreateClientInfo Lib "dhcpsapi" ( _
ByVal ServerIpAddress As LongPtr, _
ByVal ClientInfo As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DhcpV4CreateClientInfo = ctypes.windll.dhcpsapi.DhcpV4CreateClientInfo
DhcpV4CreateClientInfo.restype = wintypes.DWORD
DhcpV4CreateClientInfo.argtypes = [
wintypes.LPCWSTR, # ServerIpAddress : LPCWSTR optional
ctypes.c_void_p, # ClientInfo : DHCP_CLIENT_INFO_PB*
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('DHCPSAPI.dll')
DhcpV4CreateClientInfo = Fiddle::Function.new(
lib['DhcpV4CreateClientInfo'],
[
Fiddle::TYPE_VOIDP, # ServerIpAddress : LPCWSTR optional
Fiddle::TYPE_VOIDP, # ClientInfo : DHCP_CLIENT_INFO_PB*
],
-Fiddle::TYPE_INT)#[link(name = "dhcpsapi")]
extern "system" {
fn DhcpV4CreateClientInfo(
ServerIpAddress: *const u16, // LPCWSTR optional
ClientInfo: *const DHCP_CLIENT_INFO_PB // DHCP_CLIENT_INFO_PB*
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("DHCPSAPI.dll")]
public static extern uint DhcpV4CreateClientInfo([MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress, IntPtr ClientInfo);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DHCPSAPI_DhcpV4CreateClientInfo' -Namespace Win32 -PassThru
# $api::DhcpV4CreateClientInfo(ServerIpAddress, ClientInfo)#uselib "DHCPSAPI.dll"
#func global DhcpV4CreateClientInfo "DhcpV4CreateClientInfo" sptr, sptr
; DhcpV4CreateClientInfo ServerIpAddress, varptr(ClientInfo) ; 戻り値は stat
; ServerIpAddress : LPCWSTR optional -> "sptr"
; ClientInfo : DHCP_CLIENT_INFO_PB* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "DHCPSAPI.dll" #cfunc global DhcpV4CreateClientInfo "DhcpV4CreateClientInfo" wstr, var ; res = DhcpV4CreateClientInfo(ServerIpAddress, ClientInfo) ; ServerIpAddress : LPCWSTR optional -> "wstr" ; ClientInfo : DHCP_CLIENT_INFO_PB* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "DHCPSAPI.dll" #cfunc global DhcpV4CreateClientInfo "DhcpV4CreateClientInfo" wstr, sptr ; res = DhcpV4CreateClientInfo(ServerIpAddress, varptr(ClientInfo)) ; ServerIpAddress : LPCWSTR optional -> "wstr" ; ClientInfo : DHCP_CLIENT_INFO_PB* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD DhcpV4CreateClientInfo(LPCWSTR ServerIpAddress, DHCP_CLIENT_INFO_PB* ClientInfo) #uselib "DHCPSAPI.dll" #cfunc global DhcpV4CreateClientInfo "DhcpV4CreateClientInfo" wstr, var ; res = DhcpV4CreateClientInfo(ServerIpAddress, ClientInfo) ; ServerIpAddress : LPCWSTR optional -> "wstr" ; ClientInfo : DHCP_CLIENT_INFO_PB* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD DhcpV4CreateClientInfo(LPCWSTR ServerIpAddress, DHCP_CLIENT_INFO_PB* ClientInfo) #uselib "DHCPSAPI.dll" #cfunc global DhcpV4CreateClientInfo "DhcpV4CreateClientInfo" wstr, intptr ; res = DhcpV4CreateClientInfo(ServerIpAddress, varptr(ClientInfo)) ; ServerIpAddress : LPCWSTR optional -> "wstr" ; ClientInfo : DHCP_CLIENT_INFO_PB* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
procDhcpV4CreateClientInfo = dhcpsapi.NewProc("DhcpV4CreateClientInfo")
)
// ServerIpAddress (LPCWSTR optional), ClientInfo (DHCP_CLIENT_INFO_PB*)
r1, _, err := procDhcpV4CreateClientInfo.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ServerIpAddress))),
uintptr(ClientInfo),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction DhcpV4CreateClientInfo(
ServerIpAddress: PWideChar; // LPCWSTR optional
ClientInfo: Pointer // DHCP_CLIENT_INFO_PB*
): DWORD; stdcall;
external 'DHCPSAPI.dll' name 'DhcpV4CreateClientInfo';result := DllCall("DHCPSAPI\DhcpV4CreateClientInfo"
, "WStr", ServerIpAddress ; LPCWSTR optional
, "Ptr", ClientInfo ; DHCP_CLIENT_INFO_PB*
, "UInt") ; return: DWORD●DhcpV4CreateClientInfo(ServerIpAddress, ClientInfo) = DLL("DHCPSAPI.dll", "dword DhcpV4CreateClientInfo(char*, void*)")
# 呼び出し: DhcpV4CreateClientInfo(ServerIpAddress, ClientInfo)
# ServerIpAddress : LPCWSTR optional -> "char*"
# ClientInfo : DHCP_CLIENT_INFO_PB* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "dhcpsapi" fn DhcpV4CreateClientInfo(
ServerIpAddress: [*c]const u16, // LPCWSTR optional
ClientInfo: [*c]DHCP_CLIENT_INFO_PB // DHCP_CLIENT_INFO_PB*
) callconv(std.os.windows.WINAPI) u32;proc DhcpV4CreateClientInfo(
ServerIpAddress: WideCString, # LPCWSTR optional
ClientInfo: ptr DHCP_CLIENT_INFO_PB # DHCP_CLIENT_INFO_PB*
): uint32 {.importc: "DhcpV4CreateClientInfo", stdcall, dynlib: "DHCPSAPI.dll".}pragma(lib, "dhcpsapi");
extern(Windows)
uint DhcpV4CreateClientInfo(
const(wchar)* ServerIpAddress, // LPCWSTR optional
DHCP_CLIENT_INFO_PB* ClientInfo // DHCP_CLIENT_INFO_PB*
);ccall((:DhcpV4CreateClientInfo, "DHCPSAPI.dll"), stdcall, UInt32,
(Cwstring, Ptr{DHCP_CLIENT_INFO_PB}),
ServerIpAddress, ClientInfo)
# ServerIpAddress : LPCWSTR optional -> Cwstring
# ClientInfo : DHCP_CLIENT_INFO_PB* -> Ptr{DHCP_CLIENT_INFO_PB}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t DhcpV4CreateClientInfo(
const uint16_t* ServerIpAddress,
void* ClientInfo);
]]
local dhcpsapi = ffi.load("dhcpsapi")
-- dhcpsapi.DhcpV4CreateClientInfo(ServerIpAddress, ClientInfo)
-- ServerIpAddress : LPCWSTR optional
-- ClientInfo : DHCP_CLIENT_INFO_PB*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('DHCPSAPI.dll');
const DhcpV4CreateClientInfo = lib.func('__stdcall', 'DhcpV4CreateClientInfo', 'uint32_t', ['str16', 'void *']);
// DhcpV4CreateClientInfo(ServerIpAddress, ClientInfo)
// ServerIpAddress : LPCWSTR optional -> 'str16'
// ClientInfo : DHCP_CLIENT_INFO_PB* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("DHCPSAPI.dll", {
DhcpV4CreateClientInfo: { parameters: ["buffer", "pointer"], result: "u32" },
});
// lib.symbols.DhcpV4CreateClientInfo(ServerIpAddress, ClientInfo)
// ServerIpAddress : LPCWSTR optional -> "buffer"
// ClientInfo : DHCP_CLIENT_INFO_PB* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t DhcpV4CreateClientInfo(
const uint16_t* ServerIpAddress,
void* ClientInfo);
C, "DHCPSAPI.dll");
// $ffi->DhcpV4CreateClientInfo(ServerIpAddress, ClientInfo);
// ServerIpAddress : LPCWSTR optional
// ClientInfo : DHCP_CLIENT_INFO_PB*
// 構造体/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 DhcpV4CreateClientInfo(
WString ServerIpAddress, // LPCWSTR optional
Pointer ClientInfo // DHCP_CLIENT_INFO_PB*
);
}@[Link("dhcpsapi")]
lib LibDHCPSAPI
fun DhcpV4CreateClientInfo = DhcpV4CreateClientInfo(
ServerIpAddress : UInt16*, # LPCWSTR optional
ClientInfo : DHCP_CLIENT_INFO_PB* # DHCP_CLIENT_INFO_PB*
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DhcpV4CreateClientInfoNative = Uint32 Function(Pointer<Utf16>, Pointer<Void>);
typedef DhcpV4CreateClientInfoDart = int Function(Pointer<Utf16>, Pointer<Void>);
final DhcpV4CreateClientInfo = DynamicLibrary.open('DHCPSAPI.dll')
.lookupFunction<DhcpV4CreateClientInfoNative, DhcpV4CreateClientInfoDart>('DhcpV4CreateClientInfo');
// ServerIpAddress : LPCWSTR optional -> Pointer<Utf16>
// ClientInfo : DHCP_CLIENT_INFO_PB* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DhcpV4CreateClientInfo(
ServerIpAddress: PWideChar; // LPCWSTR optional
ClientInfo: Pointer // DHCP_CLIENT_INFO_PB*
): DWORD; stdcall;
external 'DHCPSAPI.dll' name 'DhcpV4CreateClientInfo';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DhcpV4CreateClientInfo"
c_DhcpV4CreateClientInfo :: CWString -> Ptr () -> IO Word32
-- ServerIpAddress : LPCWSTR optional -> CWString
-- ClientInfo : DHCP_CLIENT_INFO_PB* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let dhcpv4createclientinfo =
foreign "DhcpV4CreateClientInfo"
((ptr uint16_t) @-> (ptr void) @-> returning uint32_t)
(* ServerIpAddress : LPCWSTR optional -> (ptr uint16_t) *)
(* ClientInfo : DHCP_CLIENT_INFO_PB* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library dhcpsapi (t "DHCPSAPI.dll"))
(cffi:use-foreign-library dhcpsapi)
(cffi:defcfun ("DhcpV4CreateClientInfo" dhcp-v4-create-client-info :convention :stdcall) :uint32
(server-ip-address (:string :encoding :utf-16le)) ; LPCWSTR optional
(client-info :pointer)) ; DHCP_CLIENT_INFO_PB*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DhcpV4CreateClientInfo = Win32::API::More->new('DHCPSAPI',
'DWORD DhcpV4CreateClientInfo(LPCWSTR ServerIpAddress, LPVOID ClientInfo)');
# my $ret = $DhcpV4CreateClientInfo->Call($ServerIpAddress, $ClientInfo);
# ServerIpAddress : LPCWSTR optional -> LPCWSTR
# ClientInfo : DHCP_CLIENT_INFO_PB* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f DhcpV4CreateClientInfoEx — 拡張形式でIPv4クライアント予約情報をDHCPサーバーに作成する。
公式の関連項目
- f DhcpV4GetClientInfo — 検索条件に一致するIPv4 DHCPクライアントの情報を取得する。
- f DhcpV6CreateClientInfo — DHCPサーバーに新しいIPv6クライアント予約情報を作成する。