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

DhcpV4FailoverTriggerAddrAllocation

関数
IPv4フェールオーバー関係のアドレス再割り当てを起動する。
DLLDHCPSAPI.dll呼出規約winapi対応OSwindowsserver2012

シグネチャ

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

DWORD DhcpV4FailoverTriggerAddrAllocation(
    LPWSTR ServerIpAddress,   // optional
    LPWSTR pFailRelName
);

パラメーター

名前方向説明
ServerIpAddressLPWSTRinoptional対象DHCPサーバーのIPアドレスを示すUnicode文字列。ローカルならNULL可。
pFailRelNameLPWSTRinアドレス割り当てを開始させる対象フェールオーバー関係の名前を示す文字列。

戻り値の型: DWORD

各言語での呼び出し定義

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

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

DhcpV4FailoverTriggerAddrAllocation = ctypes.windll.dhcpsapi.DhcpV4FailoverTriggerAddrAllocation
DhcpV4FailoverTriggerAddrAllocation.restype = wintypes.DWORD
DhcpV4FailoverTriggerAddrAllocation.argtypes = [
    wintypes.LPCWSTR,  # ServerIpAddress : LPWSTR optional
    wintypes.LPCWSTR,  # pFailRelName : LPWSTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('DHCPSAPI.dll')
DhcpV4FailoverTriggerAddrAllocation = Fiddle::Function.new(
  lib['DhcpV4FailoverTriggerAddrAllocation'],
  [
    Fiddle::TYPE_VOIDP,  # ServerIpAddress : LPWSTR optional
    Fiddle::TYPE_VOIDP,  # pFailRelName : LPWSTR
  ],
  -Fiddle::TYPE_INT)
#[link(name = "dhcpsapi")]
extern "system" {
    fn DhcpV4FailoverTriggerAddrAllocation(
        ServerIpAddress: *mut u16,  // LPWSTR optional
        pFailRelName: *mut u16  // LPWSTR
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("DHCPSAPI.dll")]
public static extern uint DhcpV4FailoverTriggerAddrAllocation([MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress, [MarshalAs(UnmanagedType.LPWStr)] string pFailRelName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DHCPSAPI_DhcpV4FailoverTriggerAddrAllocation' -Namespace Win32 -PassThru
# $api::DhcpV4FailoverTriggerAddrAllocation(ServerIpAddress, pFailRelName)
#uselib "DHCPSAPI.dll"
#func global DhcpV4FailoverTriggerAddrAllocation "DhcpV4FailoverTriggerAddrAllocation" sptr, sptr
; DhcpV4FailoverTriggerAddrAllocation ServerIpAddress, pFailRelName   ; 戻り値は stat
; ServerIpAddress : LPWSTR optional -> "sptr"
; pFailRelName : LPWSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "DHCPSAPI.dll"
#cfunc global DhcpV4FailoverTriggerAddrAllocation "DhcpV4FailoverTriggerAddrAllocation" wstr, wstr
; res = DhcpV4FailoverTriggerAddrAllocation(ServerIpAddress, pFailRelName)
; ServerIpAddress : LPWSTR optional -> "wstr"
; pFailRelName : LPWSTR -> "wstr"
; DWORD DhcpV4FailoverTriggerAddrAllocation(LPWSTR ServerIpAddress, LPWSTR pFailRelName)
#uselib "DHCPSAPI.dll"
#cfunc global DhcpV4FailoverTriggerAddrAllocation "DhcpV4FailoverTriggerAddrAllocation" wstr, wstr
; res = DhcpV4FailoverTriggerAddrAllocation(ServerIpAddress, pFailRelName)
; ServerIpAddress : LPWSTR optional -> "wstr"
; pFailRelName : LPWSTR -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
	procDhcpV4FailoverTriggerAddrAllocation = dhcpsapi.NewProc("DhcpV4FailoverTriggerAddrAllocation")
)

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

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

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

foreign import stdcall safe "DhcpV4FailoverTriggerAddrAllocation"
  c_DhcpV4FailoverTriggerAddrAllocation :: CWString -> CWString -> IO Word32
-- ServerIpAddress : LPWSTR optional -> CWString
-- pFailRelName : LPWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

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

(cffi:defcfun ("DhcpV4FailoverTriggerAddrAllocation" dhcp-v4-failover-trigger-addr-allocation :convention :stdcall) :uint32
  (server-ip-address (:string :encoding :utf-16le))   ; LPWSTR optional
  (p-fail-rel-name (:string :encoding :utf-16le)))   ; LPWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DhcpV4FailoverTriggerAddrAllocation = Win32::API::More->new('DHCPSAPI',
    'DWORD DhcpV4FailoverTriggerAddrAllocation(LPCWSTR ServerIpAddress, LPCWSTR pFailRelName)');
# my $ret = $DhcpV4FailoverTriggerAddrAllocation->Call($ServerIpAddress, $pFailRelName);
# ServerIpAddress : LPWSTR optional -> LPCWSTR
# pFailRelName : LPWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。