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