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