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