ホーム › NetworkManagement.Dhcp › DhcpV4FailoverSetRelationship
DhcpV4FailoverSetRelationship
関数既存のIPv4フェールオーバー関係のパラメーターを設定する。
シグネチャ
// DHCPSAPI.dll
#include <windows.h>
DWORD DhcpV4FailoverSetRelationship(
LPWSTR ServerIpAddress, // optional
DWORD Flags,
DHCP_FAILOVER_RELATIONSHIP* pRelationship
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ServerIpAddress | LPWSTR | inoptional | 対象DHCPサーバーのIPアドレスを示すUnicode文字列。ローカルならNULL可。 |
| Flags | DWORD | in | Relationship内のどのフィールドを変更するかを示すビットフラグ。 |
| pRelationship | DHCP_FAILOVER_RELATIONSHIP* | in | 更新後のフェールオーバー関係定義を保持するDHCP_FAILOVER_RELATIONSHIP構造体へのポインタ。 |
戻り値の型: DWORD
各言語での呼び出し定義
// DHCPSAPI.dll
#include <windows.h>
DWORD DhcpV4FailoverSetRelationship(
LPWSTR ServerIpAddress, // optional
DWORD Flags,
DHCP_FAILOVER_RELATIONSHIP* pRelationship
);[DllImport("DHCPSAPI.dll", ExactSpelling = true)]
static extern uint DhcpV4FailoverSetRelationship(
[MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress, // LPWSTR optional
uint Flags, // DWORD
IntPtr pRelationship // DHCP_FAILOVER_RELATIONSHIP*
);<DllImport("DHCPSAPI.dll", ExactSpelling:=True)>
Public Shared Function DhcpV4FailoverSetRelationship(
<MarshalAs(UnmanagedType.LPWStr)> ServerIpAddress As String, ' LPWSTR optional
Flags As UInteger, ' DWORD
pRelationship As IntPtr ' DHCP_FAILOVER_RELATIONSHIP*
) As UInteger
End Function' ServerIpAddress : LPWSTR optional
' Flags : DWORD
' pRelationship : DHCP_FAILOVER_RELATIONSHIP*
Declare PtrSafe Function DhcpV4FailoverSetRelationship Lib "dhcpsapi" ( _
ByVal ServerIpAddress As LongPtr, _
ByVal Flags As Long, _
ByVal pRelationship As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DhcpV4FailoverSetRelationship = ctypes.windll.dhcpsapi.DhcpV4FailoverSetRelationship
DhcpV4FailoverSetRelationship.restype = wintypes.DWORD
DhcpV4FailoverSetRelationship.argtypes = [
wintypes.LPCWSTR, # ServerIpAddress : LPWSTR optional
wintypes.DWORD, # Flags : DWORD
ctypes.c_void_p, # pRelationship : DHCP_FAILOVER_RELATIONSHIP*
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('DHCPSAPI.dll')
DhcpV4FailoverSetRelationship = Fiddle::Function.new(
lib['DhcpV4FailoverSetRelationship'],
[
Fiddle::TYPE_VOIDP, # ServerIpAddress : LPWSTR optional
-Fiddle::TYPE_INT, # Flags : DWORD
Fiddle::TYPE_VOIDP, # pRelationship : DHCP_FAILOVER_RELATIONSHIP*
],
-Fiddle::TYPE_INT)#[link(name = "dhcpsapi")]
extern "system" {
fn DhcpV4FailoverSetRelationship(
ServerIpAddress: *mut u16, // LPWSTR optional
Flags: u32, // DWORD
pRelationship: *mut DHCP_FAILOVER_RELATIONSHIP // DHCP_FAILOVER_RELATIONSHIP*
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("DHCPSAPI.dll")]
public static extern uint DhcpV4FailoverSetRelationship([MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress, uint Flags, IntPtr pRelationship);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DHCPSAPI_DhcpV4FailoverSetRelationship' -Namespace Win32 -PassThru
# $api::DhcpV4FailoverSetRelationship(ServerIpAddress, Flags, pRelationship)#uselib "DHCPSAPI.dll"
#func global DhcpV4FailoverSetRelationship "DhcpV4FailoverSetRelationship" sptr, sptr, sptr
; DhcpV4FailoverSetRelationship ServerIpAddress, Flags, varptr(pRelationship) ; 戻り値は stat
; ServerIpAddress : LPWSTR optional -> "sptr"
; Flags : DWORD -> "sptr"
; pRelationship : DHCP_FAILOVER_RELATIONSHIP* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "DHCPSAPI.dll" #cfunc global DhcpV4FailoverSetRelationship "DhcpV4FailoverSetRelationship" wstr, int, var ; res = DhcpV4FailoverSetRelationship(ServerIpAddress, Flags, pRelationship) ; ServerIpAddress : LPWSTR optional -> "wstr" ; Flags : DWORD -> "int" ; pRelationship : DHCP_FAILOVER_RELATIONSHIP* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "DHCPSAPI.dll" #cfunc global DhcpV4FailoverSetRelationship "DhcpV4FailoverSetRelationship" wstr, int, sptr ; res = DhcpV4FailoverSetRelationship(ServerIpAddress, Flags, varptr(pRelationship)) ; ServerIpAddress : LPWSTR optional -> "wstr" ; Flags : DWORD -> "int" ; pRelationship : DHCP_FAILOVER_RELATIONSHIP* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD DhcpV4FailoverSetRelationship(LPWSTR ServerIpAddress, DWORD Flags, DHCP_FAILOVER_RELATIONSHIP* pRelationship) #uselib "DHCPSAPI.dll" #cfunc global DhcpV4FailoverSetRelationship "DhcpV4FailoverSetRelationship" wstr, int, var ; res = DhcpV4FailoverSetRelationship(ServerIpAddress, Flags, pRelationship) ; ServerIpAddress : LPWSTR optional -> "wstr" ; Flags : DWORD -> "int" ; pRelationship : DHCP_FAILOVER_RELATIONSHIP* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD DhcpV4FailoverSetRelationship(LPWSTR ServerIpAddress, DWORD Flags, DHCP_FAILOVER_RELATIONSHIP* pRelationship) #uselib "DHCPSAPI.dll" #cfunc global DhcpV4FailoverSetRelationship "DhcpV4FailoverSetRelationship" wstr, int, intptr ; res = DhcpV4FailoverSetRelationship(ServerIpAddress, Flags, varptr(pRelationship)) ; ServerIpAddress : LPWSTR optional -> "wstr" ; Flags : DWORD -> "int" ; pRelationship : DHCP_FAILOVER_RELATIONSHIP* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
procDhcpV4FailoverSetRelationship = dhcpsapi.NewProc("DhcpV4FailoverSetRelationship")
)
// ServerIpAddress (LPWSTR optional), Flags (DWORD), pRelationship (DHCP_FAILOVER_RELATIONSHIP*)
r1, _, err := procDhcpV4FailoverSetRelationship.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ServerIpAddress))),
uintptr(Flags),
uintptr(pRelationship),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction DhcpV4FailoverSetRelationship(
ServerIpAddress: PWideChar; // LPWSTR optional
Flags: DWORD; // DWORD
pRelationship: Pointer // DHCP_FAILOVER_RELATIONSHIP*
): DWORD; stdcall;
external 'DHCPSAPI.dll' name 'DhcpV4FailoverSetRelationship';result := DllCall("DHCPSAPI\DhcpV4FailoverSetRelationship"
, "WStr", ServerIpAddress ; LPWSTR optional
, "UInt", Flags ; DWORD
, "Ptr", pRelationship ; DHCP_FAILOVER_RELATIONSHIP*
, "UInt") ; return: DWORD●DhcpV4FailoverSetRelationship(ServerIpAddress, Flags, pRelationship) = DLL("DHCPSAPI.dll", "dword DhcpV4FailoverSetRelationship(char*, dword, void*)")
# 呼び出し: DhcpV4FailoverSetRelationship(ServerIpAddress, Flags, pRelationship)
# ServerIpAddress : LPWSTR optional -> "char*"
# Flags : DWORD -> "dword"
# pRelationship : DHCP_FAILOVER_RELATIONSHIP* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "dhcpsapi" fn DhcpV4FailoverSetRelationship(
ServerIpAddress: [*c]const u16, // LPWSTR optional
Flags: u32, // DWORD
pRelationship: [*c]DHCP_FAILOVER_RELATIONSHIP // DHCP_FAILOVER_RELATIONSHIP*
) callconv(std.os.windows.WINAPI) u32;proc DhcpV4FailoverSetRelationship(
ServerIpAddress: WideCString, # LPWSTR optional
Flags: uint32, # DWORD
pRelationship: ptr DHCP_FAILOVER_RELATIONSHIP # DHCP_FAILOVER_RELATIONSHIP*
): uint32 {.importc: "DhcpV4FailoverSetRelationship", stdcall, dynlib: "DHCPSAPI.dll".}pragma(lib, "dhcpsapi");
extern(Windows)
uint DhcpV4FailoverSetRelationship(
const(wchar)* ServerIpAddress, // LPWSTR optional
uint Flags, // DWORD
DHCP_FAILOVER_RELATIONSHIP* pRelationship // DHCP_FAILOVER_RELATIONSHIP*
);ccall((:DhcpV4FailoverSetRelationship, "DHCPSAPI.dll"), stdcall, UInt32,
(Cwstring, UInt32, Ptr{DHCP_FAILOVER_RELATIONSHIP}),
ServerIpAddress, Flags, pRelationship)
# ServerIpAddress : LPWSTR optional -> Cwstring
# Flags : DWORD -> UInt32
# pRelationship : DHCP_FAILOVER_RELATIONSHIP* -> Ptr{DHCP_FAILOVER_RELATIONSHIP}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t DhcpV4FailoverSetRelationship(
const uint16_t* ServerIpAddress,
uint32_t Flags,
void* pRelationship);
]]
local dhcpsapi = ffi.load("dhcpsapi")
-- dhcpsapi.DhcpV4FailoverSetRelationship(ServerIpAddress, Flags, pRelationship)
-- ServerIpAddress : LPWSTR optional
-- Flags : DWORD
-- pRelationship : DHCP_FAILOVER_RELATIONSHIP*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('DHCPSAPI.dll');
const DhcpV4FailoverSetRelationship = lib.func('__stdcall', 'DhcpV4FailoverSetRelationship', 'uint32_t', ['str16', 'uint32_t', 'void *']);
// DhcpV4FailoverSetRelationship(ServerIpAddress, Flags, pRelationship)
// ServerIpAddress : LPWSTR optional -> 'str16'
// Flags : DWORD -> 'uint32_t'
// pRelationship : DHCP_FAILOVER_RELATIONSHIP* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("DHCPSAPI.dll", {
DhcpV4FailoverSetRelationship: { parameters: ["buffer", "u32", "pointer"], result: "u32" },
});
// lib.symbols.DhcpV4FailoverSetRelationship(ServerIpAddress, Flags, pRelationship)
// ServerIpAddress : LPWSTR optional -> "buffer"
// Flags : DWORD -> "u32"
// pRelationship : DHCP_FAILOVER_RELATIONSHIP* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t DhcpV4FailoverSetRelationship(
const uint16_t* ServerIpAddress,
uint32_t Flags,
void* pRelationship);
C, "DHCPSAPI.dll");
// $ffi->DhcpV4FailoverSetRelationship(ServerIpAddress, Flags, pRelationship);
// ServerIpAddress : LPWSTR optional
// Flags : DWORD
// pRelationship : DHCP_FAILOVER_RELATIONSHIP*
// 構造体/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 DhcpV4FailoverSetRelationship(
WString ServerIpAddress, // LPWSTR optional
int Flags, // DWORD
Pointer pRelationship // DHCP_FAILOVER_RELATIONSHIP*
);
}@[Link("dhcpsapi")]
lib LibDHCPSAPI
fun DhcpV4FailoverSetRelationship = DhcpV4FailoverSetRelationship(
ServerIpAddress : UInt16*, # LPWSTR optional
Flags : UInt32, # DWORD
pRelationship : DHCP_FAILOVER_RELATIONSHIP* # DHCP_FAILOVER_RELATIONSHIP*
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DhcpV4FailoverSetRelationshipNative = Uint32 Function(Pointer<Utf16>, Uint32, Pointer<Void>);
typedef DhcpV4FailoverSetRelationshipDart = int Function(Pointer<Utf16>, int, Pointer<Void>);
final DhcpV4FailoverSetRelationship = DynamicLibrary.open('DHCPSAPI.dll')
.lookupFunction<DhcpV4FailoverSetRelationshipNative, DhcpV4FailoverSetRelationshipDart>('DhcpV4FailoverSetRelationship');
// ServerIpAddress : LPWSTR optional -> Pointer<Utf16>
// Flags : DWORD -> Uint32
// pRelationship : DHCP_FAILOVER_RELATIONSHIP* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DhcpV4FailoverSetRelationship(
ServerIpAddress: PWideChar; // LPWSTR optional
Flags: DWORD; // DWORD
pRelationship: Pointer // DHCP_FAILOVER_RELATIONSHIP*
): DWORD; stdcall;
external 'DHCPSAPI.dll' name 'DhcpV4FailoverSetRelationship';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DhcpV4FailoverSetRelationship"
c_DhcpV4FailoverSetRelationship :: CWString -> Word32 -> Ptr () -> IO Word32
-- ServerIpAddress : LPWSTR optional -> CWString
-- Flags : DWORD -> Word32
-- pRelationship : DHCP_FAILOVER_RELATIONSHIP* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let dhcpv4failoversetrelationship =
foreign "DhcpV4FailoverSetRelationship"
((ptr uint16_t) @-> uint32_t @-> (ptr void) @-> returning uint32_t)
(* ServerIpAddress : LPWSTR optional -> (ptr uint16_t) *)
(* Flags : DWORD -> uint32_t *)
(* pRelationship : DHCP_FAILOVER_RELATIONSHIP* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library dhcpsapi (t "DHCPSAPI.dll"))
(cffi:use-foreign-library dhcpsapi)
(cffi:defcfun ("DhcpV4FailoverSetRelationship" dhcp-v4-failover-set-relationship :convention :stdcall) :uint32
(server-ip-address (:string :encoding :utf-16le)) ; LPWSTR optional
(flags :uint32) ; DWORD
(p-relationship :pointer)) ; DHCP_FAILOVER_RELATIONSHIP*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DhcpV4FailoverSetRelationship = Win32::API::More->new('DHCPSAPI',
'DWORD DhcpV4FailoverSetRelationship(LPCWSTR ServerIpAddress, DWORD Flags, LPVOID pRelationship)');
# my $ret = $DhcpV4FailoverSetRelationship->Call($ServerIpAddress, $Flags, $pRelationship);
# ServerIpAddress : LPWSTR optional -> LPCWSTR
# Flags : DWORD -> DWORD
# pRelationship : DHCP_FAILOVER_RELATIONSHIP* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。