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