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