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

DnsServiceConstructInstance

関数
DNS-SDサービスインスタンス構造体を構築して生成する。
DLLDNSAPI.dll呼出規約winapi対応OSWindows 10 以降

シグネチャ

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

DNS_SERVICE_INSTANCE* DnsServiceConstructInstance(
    LPCWSTR pServiceName,
    LPCWSTR pHostName,
    DWORD* pIp4,   // optional
    IP6_ADDRESS* pIp6,   // optional
    WORD wPort,
    WORD wPriority,
    WORD wWeight,
    DWORD dwPropertiesCount,
    LPCWSTR* keys,
    LPCWSTR* values
);

パラメーター

名前方向
pServiceNameLPCWSTRin
pHostNameLPCWSTRin
pIp4DWORD*inoptional
pIp6IP6_ADDRESS*inoptional
wPortWORDin
wPriorityWORDin
wWeightWORDin
dwPropertiesCountDWORDin
keysLPCWSTR*in
valuesLPCWSTR*in

戻り値の型: DNS_SERVICE_INSTANCE*

各言語での呼び出し定義

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

DNS_SERVICE_INSTANCE* DnsServiceConstructInstance(
    LPCWSTR pServiceName,
    LPCWSTR pHostName,
    DWORD* pIp4,   // optional
    IP6_ADDRESS* pIp6,   // optional
    WORD wPort,
    WORD wPriority,
    WORD wWeight,
    DWORD dwPropertiesCount,
    LPCWSTR* keys,
    LPCWSTR* values
);
[DllImport("DNSAPI.dll", ExactSpelling = true)]
static extern IntPtr DnsServiceConstructInstance(
    [MarshalAs(UnmanagedType.LPWStr)] string pServiceName,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string pHostName,   // LPCWSTR
    IntPtr pIp4,   // DWORD* optional
    IntPtr pIp6,   // IP6_ADDRESS* optional
    ushort wPort,   // WORD
    ushort wPriority,   // WORD
    ushort wWeight,   // WORD
    uint dwPropertiesCount,   // DWORD
    IntPtr keys,   // LPCWSTR*
    IntPtr values   // LPCWSTR*
);
<DllImport("DNSAPI.dll", ExactSpelling:=True)>
Public Shared Function DnsServiceConstructInstance(
    <MarshalAs(UnmanagedType.LPWStr)> pServiceName As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> pHostName As String,   ' LPCWSTR
    pIp4 As IntPtr,   ' DWORD* optional
    pIp6 As IntPtr,   ' IP6_ADDRESS* optional
    wPort As UShort,   ' WORD
    wPriority As UShort,   ' WORD
    wWeight As UShort,   ' WORD
    dwPropertiesCount As UInteger,   ' DWORD
    keys As IntPtr,   ' LPCWSTR*
    values As IntPtr   ' LPCWSTR*
) As IntPtr
End Function
' pServiceName : LPCWSTR
' pHostName : LPCWSTR
' pIp4 : DWORD* optional
' pIp6 : IP6_ADDRESS* optional
' wPort : WORD
' wPriority : WORD
' wWeight : WORD
' dwPropertiesCount : DWORD
' keys : LPCWSTR*
' values : LPCWSTR*
Declare PtrSafe Function DnsServiceConstructInstance Lib "dnsapi" ( _
    ByVal pServiceName As LongPtr, _
    ByVal pHostName As LongPtr, _
    ByVal pIp4 As LongPtr, _
    ByVal pIp6 As LongPtr, _
    ByVal wPort As Integer, _
    ByVal wPriority As Integer, _
    ByVal wWeight As Integer, _
    ByVal dwPropertiesCount As Long, _
    ByVal keys As LongPtr, _
    ByVal values As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DnsServiceConstructInstance = ctypes.windll.dnsapi.DnsServiceConstructInstance
DnsServiceConstructInstance.restype = ctypes.c_void_p
DnsServiceConstructInstance.argtypes = [
    wintypes.LPCWSTR,  # pServiceName : LPCWSTR
    wintypes.LPCWSTR,  # pHostName : LPCWSTR
    ctypes.POINTER(wintypes.DWORD),  # pIp4 : DWORD* optional
    ctypes.c_void_p,  # pIp6 : IP6_ADDRESS* optional
    ctypes.c_ushort,  # wPort : WORD
    ctypes.c_ushort,  # wPriority : WORD
    ctypes.c_ushort,  # wWeight : WORD
    wintypes.DWORD,  # dwPropertiesCount : DWORD
    ctypes.c_void_p,  # keys : LPCWSTR*
    ctypes.c_void_p,  # values : LPCWSTR*
]
require 'fiddle'
require 'fiddle/import'

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

var (
	dnsapi = windows.NewLazySystemDLL("DNSAPI.dll")
	procDnsServiceConstructInstance = dnsapi.NewProc("DnsServiceConstructInstance")
)

// pServiceName (LPCWSTR), pHostName (LPCWSTR), pIp4 (DWORD* optional), pIp6 (IP6_ADDRESS* optional), wPort (WORD), wPriority (WORD), wWeight (WORD), dwPropertiesCount (DWORD), keys (LPCWSTR*), values (LPCWSTR*)
r1, _, err := procDnsServiceConstructInstance.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pServiceName))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pHostName))),
	uintptr(pIp4),
	uintptr(pIp6),
	uintptr(wPort),
	uintptr(wPriority),
	uintptr(wWeight),
	uintptr(dwPropertiesCount),
	uintptr(keys),
	uintptr(values),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DNS_SERVICE_INSTANCE*
function DnsServiceConstructInstance(
  pServiceName: PWideChar;   // LPCWSTR
  pHostName: PWideChar;   // LPCWSTR
  pIp4: Pointer;   // DWORD* optional
  pIp6: Pointer;   // IP6_ADDRESS* optional
  wPort: Word;   // WORD
  wPriority: Word;   // WORD
  wWeight: Word;   // WORD
  dwPropertiesCount: DWORD;   // DWORD
  keys: PPWideChar;   // LPCWSTR*
  values: PPWideChar   // LPCWSTR*
): Pointer; stdcall;
  external 'DNSAPI.dll' name 'DnsServiceConstructInstance';
result := DllCall("DNSAPI\DnsServiceConstructInstance"
    , "WStr", pServiceName   ; LPCWSTR
    , "WStr", pHostName   ; LPCWSTR
    , "Ptr", pIp4   ; DWORD* optional
    , "Ptr", pIp6   ; IP6_ADDRESS* optional
    , "UShort", wPort   ; WORD
    , "UShort", wPriority   ; WORD
    , "UShort", wWeight   ; WORD
    , "UInt", dwPropertiesCount   ; DWORD
    , "Ptr", keys   ; LPCWSTR*
    , "Ptr", values   ; LPCWSTR*
    , "Ptr")   ; return: DNS_SERVICE_INSTANCE*
●DnsServiceConstructInstance(pServiceName, pHostName, pIp4, pIp6, wPort, wPriority, wWeight, dwPropertiesCount, keys, values) = DLL("DNSAPI.dll", "void* DnsServiceConstructInstance(char*, char*, void*, void*, int, int, int, dword, void*, void*)")
# 呼び出し: DnsServiceConstructInstance(pServiceName, pHostName, pIp4, pIp6, wPort, wPriority, wWeight, dwPropertiesCount, keys, values)
# pServiceName : LPCWSTR -> "char*"
# pHostName : LPCWSTR -> "char*"
# pIp4 : DWORD* optional -> "void*"
# pIp6 : IP6_ADDRESS* optional -> "void*"
# wPort : WORD -> "int"
# wPriority : WORD -> "int"
# wWeight : WORD -> "int"
# dwPropertiesCount : DWORD -> "dword"
# keys : LPCWSTR* -> "void*"
# values : LPCWSTR* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。