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

DhcpServerSetDnsRegCredentialsV5

関数
DHCPサーバーのDNS登録用資格情報をV5拡張で設定する。
DLLDHCPSAPI.dll呼出規約winapi対応OSwindowsserver2008

シグネチャ

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

DWORD DhcpServerSetDnsRegCredentialsV5(
    LPWSTR ServerIpAddress,   // optional
    LPWSTR Uname,   // optional
    LPWSTR Domain,   // optional
    LPWSTR Passwd   // optional
);

パラメーター

名前方向説明
ServerIpAddressLPWSTRinoptional対象DHCPサーバーのIPアドレスを示すUnicode文字列。ローカルならNULL可。
UnameLPWSTRinoptionalDNS動的登録に使うユーザー名文字列。
DomainLPWSTRinoptionalDNS動的登録に使うドメイン名文字列。
PasswdLPWSTRinoptionalDNS動的登録に使うパスワード文字列。

戻り値の型: DWORD

各言語での呼び出し定義

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

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

DhcpServerSetDnsRegCredentialsV5 = ctypes.windll.dhcpsapi.DhcpServerSetDnsRegCredentialsV5
DhcpServerSetDnsRegCredentialsV5.restype = wintypes.DWORD
DhcpServerSetDnsRegCredentialsV5.argtypes = [
    wintypes.LPCWSTR,  # ServerIpAddress : LPWSTR optional
    wintypes.LPCWSTR,  # Uname : LPWSTR optional
    wintypes.LPCWSTR,  # Domain : LPWSTR optional
    wintypes.LPCWSTR,  # Passwd : LPWSTR optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('DHCPSAPI.dll')
DhcpServerSetDnsRegCredentialsV5 = Fiddle::Function.new(
  lib['DhcpServerSetDnsRegCredentialsV5'],
  [
    Fiddle::TYPE_VOIDP,  # ServerIpAddress : LPWSTR optional
    Fiddle::TYPE_VOIDP,  # Uname : LPWSTR optional
    Fiddle::TYPE_VOIDP,  # Domain : LPWSTR optional
    Fiddle::TYPE_VOIDP,  # Passwd : LPWSTR optional
  ],
  -Fiddle::TYPE_INT)
#[link(name = "dhcpsapi")]
extern "system" {
    fn DhcpServerSetDnsRegCredentialsV5(
        ServerIpAddress: *mut u16,  // LPWSTR optional
        Uname: *mut u16,  // LPWSTR optional
        Domain: *mut u16,  // LPWSTR optional
        Passwd: *mut u16  // LPWSTR optional
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("DHCPSAPI.dll")]
public static extern uint DhcpServerSetDnsRegCredentialsV5([MarshalAs(UnmanagedType.LPWStr)] string ServerIpAddress, [MarshalAs(UnmanagedType.LPWStr)] string Uname, [MarshalAs(UnmanagedType.LPWStr)] string Domain, [MarshalAs(UnmanagedType.LPWStr)] string Passwd);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DHCPSAPI_DhcpServerSetDnsRegCredentialsV5' -Namespace Win32 -PassThru
# $api::DhcpServerSetDnsRegCredentialsV5(ServerIpAddress, Uname, Domain, Passwd)
#uselib "DHCPSAPI.dll"
#func global DhcpServerSetDnsRegCredentialsV5 "DhcpServerSetDnsRegCredentialsV5" sptr, sptr, sptr, sptr
; DhcpServerSetDnsRegCredentialsV5 ServerIpAddress, Uname, Domain, Passwd   ; 戻り値は stat
; ServerIpAddress : LPWSTR optional -> "sptr"
; Uname : LPWSTR optional -> "sptr"
; Domain : LPWSTR optional -> "sptr"
; Passwd : LPWSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "DHCPSAPI.dll"
#cfunc global DhcpServerSetDnsRegCredentialsV5 "DhcpServerSetDnsRegCredentialsV5" wstr, wstr, wstr, wstr
; res = DhcpServerSetDnsRegCredentialsV5(ServerIpAddress, Uname, Domain, Passwd)
; ServerIpAddress : LPWSTR optional -> "wstr"
; Uname : LPWSTR optional -> "wstr"
; Domain : LPWSTR optional -> "wstr"
; Passwd : LPWSTR optional -> "wstr"
; DWORD DhcpServerSetDnsRegCredentialsV5(LPWSTR ServerIpAddress, LPWSTR Uname, LPWSTR Domain, LPWSTR Passwd)
#uselib "DHCPSAPI.dll"
#cfunc global DhcpServerSetDnsRegCredentialsV5 "DhcpServerSetDnsRegCredentialsV5" wstr, wstr, wstr, wstr
; res = DhcpServerSetDnsRegCredentialsV5(ServerIpAddress, Uname, Domain, Passwd)
; ServerIpAddress : LPWSTR optional -> "wstr"
; Uname : LPWSTR optional -> "wstr"
; Domain : LPWSTR optional -> "wstr"
; Passwd : LPWSTR optional -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dhcpsapi = windows.NewLazySystemDLL("DHCPSAPI.dll")
	procDhcpServerSetDnsRegCredentialsV5 = dhcpsapi.NewProc("DhcpServerSetDnsRegCredentialsV5")
)

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

extern "dhcpsapi" fn DhcpServerSetDnsRegCredentialsV5(
    ServerIpAddress: [*c]const u16, // LPWSTR optional
    Uname: [*c]const u16, // LPWSTR optional
    Domain: [*c]const u16, // LPWSTR optional
    Passwd: [*c]const u16 // LPWSTR optional
) callconv(std.os.windows.WINAPI) u32;
proc DhcpServerSetDnsRegCredentialsV5(
    ServerIpAddress: WideCString,  # LPWSTR optional
    Uname: WideCString,  # LPWSTR optional
    Domain: WideCString,  # LPWSTR optional
    Passwd: WideCString  # LPWSTR optional
): uint32 {.importc: "DhcpServerSetDnsRegCredentialsV5", stdcall, dynlib: "DHCPSAPI.dll".}
pragma(lib, "dhcpsapi");
extern(Windows)
uint DhcpServerSetDnsRegCredentialsV5(
    const(wchar)* ServerIpAddress,   // LPWSTR optional
    const(wchar)* Uname,   // LPWSTR optional
    const(wchar)* Domain,   // LPWSTR optional
    const(wchar)* Passwd   // LPWSTR optional
);
ccall((:DhcpServerSetDnsRegCredentialsV5, "DHCPSAPI.dll"), stdcall, UInt32,
      (Cwstring, Cwstring, Cwstring, Cwstring),
      ServerIpAddress, Uname, Domain, Passwd)
# ServerIpAddress : LPWSTR optional -> Cwstring
# Uname : LPWSTR optional -> Cwstring
# Domain : LPWSTR optional -> Cwstring
# Passwd : LPWSTR optional -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t DhcpServerSetDnsRegCredentialsV5(
    const uint16_t* ServerIpAddress,
    const uint16_t* Uname,
    const uint16_t* Domain,
    const uint16_t* Passwd);
]]
local dhcpsapi = ffi.load("dhcpsapi")
-- dhcpsapi.DhcpServerSetDnsRegCredentialsV5(ServerIpAddress, Uname, Domain, Passwd)
-- ServerIpAddress : LPWSTR optional
-- Uname : LPWSTR optional
-- Domain : LPWSTR optional
-- Passwd : LPWSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('DHCPSAPI.dll');
const DhcpServerSetDnsRegCredentialsV5 = lib.func('__stdcall', 'DhcpServerSetDnsRegCredentialsV5', 'uint32_t', ['str16', 'str16', 'str16', 'str16']);
// DhcpServerSetDnsRegCredentialsV5(ServerIpAddress, Uname, Domain, Passwd)
// ServerIpAddress : LPWSTR optional -> 'str16'
// Uname : LPWSTR optional -> 'str16'
// Domain : LPWSTR optional -> 'str16'
// Passwd : LPWSTR optional -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("DHCPSAPI.dll", {
  DhcpServerSetDnsRegCredentialsV5: { parameters: ["buffer", "buffer", "buffer", "buffer"], result: "u32" },
});
// lib.symbols.DhcpServerSetDnsRegCredentialsV5(ServerIpAddress, Uname, Domain, Passwd)
// ServerIpAddress : LPWSTR optional -> "buffer"
// Uname : LPWSTR optional -> "buffer"
// Domain : LPWSTR optional -> "buffer"
// Passwd : LPWSTR optional -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t DhcpServerSetDnsRegCredentialsV5(
    const uint16_t* ServerIpAddress,
    const uint16_t* Uname,
    const uint16_t* Domain,
    const uint16_t* Passwd);
C, "DHCPSAPI.dll");
// $ffi->DhcpServerSetDnsRegCredentialsV5(ServerIpAddress, Uname, Domain, Passwd);
// ServerIpAddress : LPWSTR optional
// Uname : LPWSTR optional
// Domain : LPWSTR optional
// Passwd : 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 DhcpServerSetDnsRegCredentialsV5(
        WString ServerIpAddress,   // LPWSTR optional
        WString Uname,   // LPWSTR optional
        WString Domain,   // LPWSTR optional
        WString Passwd   // LPWSTR optional
    );
}
@[Link("dhcpsapi")]
lib LibDHCPSAPI
  fun DhcpServerSetDnsRegCredentialsV5 = DhcpServerSetDnsRegCredentialsV5(
    ServerIpAddress : UInt16*,   # LPWSTR optional
    Uname : UInt16*,   # LPWSTR optional
    Domain : UInt16*,   # LPWSTR optional
    Passwd : 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 DhcpServerSetDnsRegCredentialsV5Native = Uint32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>);
typedef DhcpServerSetDnsRegCredentialsV5Dart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>);
final DhcpServerSetDnsRegCredentialsV5 = DynamicLibrary.open('DHCPSAPI.dll')
    .lookupFunction<DhcpServerSetDnsRegCredentialsV5Native, DhcpServerSetDnsRegCredentialsV5Dart>('DhcpServerSetDnsRegCredentialsV5');
// ServerIpAddress : LPWSTR optional -> Pointer<Utf16>
// Uname : LPWSTR optional -> Pointer<Utf16>
// Domain : LPWSTR optional -> Pointer<Utf16>
// Passwd : LPWSTR optional -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DhcpServerSetDnsRegCredentialsV5(
  ServerIpAddress: PWideChar;   // LPWSTR optional
  Uname: PWideChar;   // LPWSTR optional
  Domain: PWideChar;   // LPWSTR optional
  Passwd: PWideChar   // LPWSTR optional
): DWORD; stdcall;
  external 'DHCPSAPI.dll' name 'DhcpServerSetDnsRegCredentialsV5';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DhcpServerSetDnsRegCredentialsV5"
  c_DhcpServerSetDnsRegCredentialsV5 :: CWString -> CWString -> CWString -> CWString -> IO Word32
-- ServerIpAddress : LPWSTR optional -> CWString
-- Uname : LPWSTR optional -> CWString
-- Domain : LPWSTR optional -> CWString
-- Passwd : LPWSTR optional -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let dhcpserversetdnsregcredentialsv5 =
  foreign "DhcpServerSetDnsRegCredentialsV5"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> returning uint32_t)
(* ServerIpAddress : LPWSTR optional -> (ptr uint16_t) *)
(* Uname : LPWSTR optional -> (ptr uint16_t) *)
(* Domain : LPWSTR optional -> (ptr uint16_t) *)
(* Passwd : 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 ("DhcpServerSetDnsRegCredentialsV5" dhcp-server-set-dns-reg-credentials-v5 :convention :stdcall) :uint32
  (server-ip-address (:string :encoding :utf-16le))   ; LPWSTR optional
  (uname (:string :encoding :utf-16le))   ; LPWSTR optional
  (domain (:string :encoding :utf-16le))   ; LPWSTR optional
  (passwd (:string :encoding :utf-16le)))   ; LPWSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DhcpServerSetDnsRegCredentialsV5 = Win32::API::More->new('DHCPSAPI',
    'DWORD DhcpServerSetDnsRegCredentialsV5(LPCWSTR ServerIpAddress, LPCWSTR Uname, LPCWSTR Domain, LPCWSTR Passwd)');
# my $ret = $DhcpServerSetDnsRegCredentialsV5->Call($ServerIpAddress, $Uname, $Domain, $Passwd);
# ServerIpAddress : LPWSTR optional -> LPCWSTR
# Uname : LPWSTR optional -> LPCWSTR
# Domain : LPWSTR optional -> LPCWSTR
# Passwd : LPWSTR optional -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。