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

DhcpV4CreatePolicyEx

関数
DHCPサーバーに新しい拡張IPv4ポリシーを作成する。
DLLDHCPSAPI.dll呼出規約winapi

シグネチャ

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

DWORD DhcpV4CreatePolicyEx(
    LPWSTR ServerIpAddress,   // optional
    DHCP_POLICY_EX* PolicyEx
);

パラメーター

名前方向
ServerIpAddressLPWSTRinoptional
PolicyExDHCP_POLICY_EX*in

戻り値の型: DWORD

各言語での呼び出し定義

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

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

DhcpV4CreatePolicyEx = ctypes.windll.dhcpsapi.DhcpV4CreatePolicyEx
DhcpV4CreatePolicyEx.restype = wintypes.DWORD
DhcpV4CreatePolicyEx.argtypes = [
    wintypes.LPCWSTR,  # ServerIpAddress : LPWSTR optional
    ctypes.c_void_p,  # PolicyEx : DHCP_POLICY_EX*
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('DHCPSAPI.dll')
DhcpV4CreatePolicyEx = Fiddle::Function.new(
  lib['DhcpV4CreatePolicyEx'],
  [
    Fiddle::TYPE_VOIDP,  # ServerIpAddress : LPWSTR optional
    Fiddle::TYPE_VOIDP,  # PolicyEx : DHCP_POLICY_EX*
  ],
  -Fiddle::TYPE_INT)
#[link(name = "dhcpsapi")]
extern "system" {
    fn DhcpV4CreatePolicyEx(
        ServerIpAddress: *mut u16,  // LPWSTR optional
        PolicyEx: *mut DHCP_POLICY_EX  // DHCP_POLICY_EX*
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("DHCPSAPI.dll")]
public static extern uint DhcpV4CreatePolicyEx([MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress, IntPtr PolicyEx);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DHCPSAPI_DhcpV4CreatePolicyEx' -Namespace Win32 -PassThru
# $api::DhcpV4CreatePolicyEx(ServerIpAddress, PolicyEx)
#uselib "DHCPSAPI.dll"
#func global DhcpV4CreatePolicyEx "DhcpV4CreatePolicyEx" sptr, sptr
; DhcpV4CreatePolicyEx ServerIpAddress, varptr(PolicyEx)   ; 戻り値は stat
; ServerIpAddress : LPWSTR optional -> "sptr"
; PolicyEx : DHCP_POLICY_EX* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "DHCPSAPI.dll"
#cfunc global DhcpV4CreatePolicyEx "DhcpV4CreatePolicyEx" wstr, var
; res = DhcpV4CreatePolicyEx(ServerIpAddress, PolicyEx)
; ServerIpAddress : LPWSTR optional -> "wstr"
; PolicyEx : DHCP_POLICY_EX* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD DhcpV4CreatePolicyEx(LPWSTR ServerIpAddress, DHCP_POLICY_EX* PolicyEx)
#uselib "DHCPSAPI.dll"
#cfunc global DhcpV4CreatePolicyEx "DhcpV4CreatePolicyEx" wstr, var
; res = DhcpV4CreatePolicyEx(ServerIpAddress, PolicyEx)
; ServerIpAddress : LPWSTR optional -> "wstr"
; PolicyEx : DHCP_POLICY_EX* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
	procDhcpV4CreatePolicyEx = dhcpsapi.NewProc("DhcpV4CreatePolicyEx")
)

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