ホーム › NetworkManagement.Dns › DnsServiceConstructInstance
DnsServiceConstructInstance
関数DNS-SDサービスインスタンス構造体を構築して生成する。
シグネチャ
// 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
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pServiceName | LPCWSTR | in | DNS-SDサービスインスタンス名を表すUnicode文字列へのポインタ。 |
| pHostName | LPCWSTR | in | サービスを提供するホスト名を表すUnicode文字列へのポインタ。 |
| pIp4 | DWORD* | inoptional | サービスのIPv4アドレスを示すDWORDへのポインタ。なければNULL可。 |
| pIp6 | IP6_ADDRESS* | inoptional | サービスのIPv6アドレスを示すIP6_ADDRESS構造体へのポインタ。なければNULL可。 |
| wPort | WORD | in | サービスが待ち受けるポート番号(ネットワークバイト順のWORD)。 |
| wPriority | WORD | in | SRVレコードの優先度を示すWORD値。 |
| wWeight | WORD | in | SRVレコードの重みを示すWORD値。 |
| dwPropertiesCount | DWORD | in | TXTプロパティのキー/値ペアの個数。 |
| keys | LPCWSTR* | in | TXTプロパティのキー文字列(Unicode)配列へのポインタ。 |
| values | LPCWSTR* | in | TXTプロパティの値文字列(Unicode)配列へのポインタ。keysと対応する。 |
戻り値の型: 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 方式にも切替可。#uselib "DNSAPI.dll" #cfunc global DnsServiceConstructInstance "DnsServiceConstructInstance" wstr, wstr, sptr, sptr, int, int, int, int, sptr, sptr ; res = DnsServiceConstructInstance(pServiceName, pHostName, varptr(pIp4), varptr(pIp6), wPort, wPriority, wWeight, dwPropertiesCount, varptr(keys), varptr(values)) ; pServiceName : LPCWSTR -> "wstr" ; pHostName : LPCWSTR -> "wstr" ; pIp4 : DWORD* optional -> "sptr" ; pIp6 : IP6_ADDRESS* optional -> "sptr" ; wPort : WORD -> "int" ; wPriority : WORD -> "int" ; wWeight : WORD -> "int" ; dwPropertiesCount : DWORD -> "int" ; keys : LPCWSTR* -> "sptr" ; values : LPCWSTR* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; 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, intptr, intptr, int, int, int, int, intptr, intptr ; res = DnsServiceConstructInstance(pServiceName, pHostName, varptr(pIp4), varptr(pIp6), wPort, wPriority, wWeight, dwPropertiesCount, varptr(keys), varptr(values)) ; pServiceName : LPCWSTR -> "wstr" ; pHostName : LPCWSTR -> "wstr" ; pIp4 : DWORD* optional -> "intptr" ; pIp6 : IP6_ADDRESS* optional -> "intptr" ; wPort : WORD -> "int" ; wPriority : WORD -> "int" ; wWeight : WORD -> "int" ; dwPropertiesCount : DWORD -> "int" ; keys : LPCWSTR* -> "intptr" ; values : LPCWSTR* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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)。const std = @import("std");
extern "dnsapi" fn DnsServiceConstructInstance(
pServiceName: [*c]const u16, // LPCWSTR
pHostName: [*c]const u16, // LPCWSTR
pIp4: [*c]u32, // DWORD* optional
pIp6: [*c]IP6_ADDRESS, // IP6_ADDRESS* optional
wPort: u16, // WORD
wPriority: u16, // WORD
wWeight: u16, // WORD
dwPropertiesCount: u32, // DWORD
keys: [*c][*c]u16, // LPCWSTR*
values: [*c][*c]u16 // LPCWSTR*
) callconv(std.os.windows.WINAPI) [*c]DNS_SERVICE_INSTANCE;proc DnsServiceConstructInstance(
pServiceName: WideCString, # LPCWSTR
pHostName: WideCString, # LPCWSTR
pIp4: ptr uint32, # DWORD* optional
pIp6: ptr IP6_ADDRESS, # IP6_ADDRESS* optional
wPort: uint16, # WORD
wPriority: uint16, # WORD
wWeight: uint16, # WORD
dwPropertiesCount: uint32, # DWORD
keys: ptr WideCString, # LPCWSTR*
values: ptr WideCString # LPCWSTR*
): ptr DNS_SERVICE_INSTANCE {.importc: "DnsServiceConstructInstance", stdcall, dynlib: "DNSAPI.dll".}pragma(lib, "dnsapi");
extern(Windows)
DNS_SERVICE_INSTANCE* DnsServiceConstructInstance(
const(wchar)* pServiceName, // LPCWSTR
const(wchar)* pHostName, // LPCWSTR
uint* pIp4, // DWORD* optional
IP6_ADDRESS* pIp6, // IP6_ADDRESS* optional
ushort wPort, // WORD
ushort wPriority, // WORD
ushort wWeight, // WORD
uint dwPropertiesCount, // DWORD
wchar** keys, // LPCWSTR*
wchar** values // LPCWSTR*
);ccall((:DnsServiceConstructInstance, "DNSAPI.dll"), stdcall, Ptr{DNS_SERVICE_INSTANCE},
(Cwstring, Cwstring, Ptr{UInt32}, Ptr{IP6_ADDRESS}, UInt16, UInt16, UInt16, UInt32, Ptr{Ptr{UInt16}}, Ptr{Ptr{UInt16}}),
pServiceName, pHostName, pIp4, pIp6, wPort, wPriority, wWeight, dwPropertiesCount, keys, values)
# pServiceName : LPCWSTR -> Cwstring
# pHostName : LPCWSTR -> Cwstring
# pIp4 : DWORD* optional -> Ptr{UInt32}
# pIp6 : IP6_ADDRESS* optional -> Ptr{IP6_ADDRESS}
# wPort : WORD -> UInt16
# wPriority : WORD -> UInt16
# wWeight : WORD -> UInt16
# dwPropertiesCount : DWORD -> UInt32
# keys : LPCWSTR* -> Ptr{Ptr{UInt16}}
# values : LPCWSTR* -> Ptr{Ptr{UInt16}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* DnsServiceConstructInstance(
const uint16_t* pServiceName,
const uint16_t* pHostName,
uint32_t* pIp4,
void* pIp6,
uint16_t wPort,
uint16_t wPriority,
uint16_t wWeight,
uint32_t dwPropertiesCount,
uint16_t** keys,
uint16_t** values);
]]
local dnsapi = ffi.load("dnsapi")
-- dnsapi.DnsServiceConstructInstance(pServiceName, pHostName, pIp4, pIp6, wPort, wPriority, wWeight, dwPropertiesCount, keys, values)
-- pServiceName : LPCWSTR
-- pHostName : LPCWSTR
-- pIp4 : DWORD* optional
-- pIp6 : IP6_ADDRESS* optional
-- wPort : WORD
-- wPriority : WORD
-- wWeight : WORD
-- dwPropertiesCount : DWORD
-- keys : LPCWSTR*
-- values : LPCWSTR*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('DNSAPI.dll');
const DnsServiceConstructInstance = lib.func('__stdcall', 'DnsServiceConstructInstance', 'void *', ['str16', 'str16', 'uint32_t *', 'void *', 'uint16_t', 'uint16_t', 'uint16_t', 'uint32_t', 'void *', 'void *']);
// DnsServiceConstructInstance(pServiceName, pHostName, pIp4, pIp6, wPort, wPriority, wWeight, dwPropertiesCount, keys, values)
// pServiceName : LPCWSTR -> 'str16'
// pHostName : LPCWSTR -> 'str16'
// pIp4 : DWORD* optional -> 'uint32_t *'
// pIp6 : IP6_ADDRESS* optional -> 'void *'
// wPort : WORD -> 'uint16_t'
// wPriority : WORD -> 'uint16_t'
// wWeight : WORD -> 'uint16_t'
// dwPropertiesCount : DWORD -> 'uint32_t'
// keys : LPCWSTR* -> 'void *'
// values : LPCWSTR* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("DNSAPI.dll", {
DnsServiceConstructInstance: { parameters: ["buffer", "buffer", "pointer", "pointer", "u16", "u16", "u16", "u32", "pointer", "pointer"], result: "pointer" },
});
// lib.symbols.DnsServiceConstructInstance(pServiceName, pHostName, pIp4, pIp6, wPort, wPriority, wWeight, dwPropertiesCount, keys, values)
// pServiceName : LPCWSTR -> "buffer"
// pHostName : LPCWSTR -> "buffer"
// pIp4 : DWORD* optional -> "pointer"
// pIp6 : IP6_ADDRESS* optional -> "pointer"
// wPort : WORD -> "u16"
// wPriority : WORD -> "u16"
// wWeight : WORD -> "u16"
// dwPropertiesCount : DWORD -> "u32"
// keys : LPCWSTR* -> "pointer"
// values : LPCWSTR* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* DnsServiceConstructInstance(
const uint16_t* pServiceName,
const uint16_t* pHostName,
uint32_t* pIp4,
void* pIp6,
uint16_t wPort,
uint16_t wPriority,
uint16_t wWeight,
uint32_t dwPropertiesCount,
uint16_t** keys,
uint16_t** values);
C, "DNSAPI.dll");
// $ffi->DnsServiceConstructInstance(pServiceName, pHostName, pIp4, pIp6, wPort, wPriority, wWeight, dwPropertiesCount, keys, values);
// pServiceName : LPCWSTR
// pHostName : LPCWSTR
// pIp4 : DWORD* optional
// pIp6 : IP6_ADDRESS* optional
// wPort : WORD
// wPriority : WORD
// wWeight : WORD
// dwPropertiesCount : DWORD
// keys : LPCWSTR*
// values : LPCWSTR*
// 構造体/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 Dnsapi extends StdCallLibrary {
Dnsapi INSTANCE = Native.load("dnsapi", Dnsapi.class);
Pointer DnsServiceConstructInstance(
WString pServiceName, // LPCWSTR
WString pHostName, // LPCWSTR
IntByReference pIp4, // DWORD* optional
Pointer pIp6, // IP6_ADDRESS* optional
short wPort, // WORD
short wPriority, // WORD
short wWeight, // WORD
int dwPropertiesCount, // DWORD
PointerByReference keys, // LPCWSTR*
PointerByReference values // LPCWSTR*
);
}@[Link("dnsapi")]
lib LibDNSAPI
fun DnsServiceConstructInstance = DnsServiceConstructInstance(
pServiceName : UInt16*, # LPCWSTR
pHostName : UInt16*, # LPCWSTR
pIp4 : UInt32*, # DWORD* optional
pIp6 : IP6_ADDRESS*, # IP6_ADDRESS* optional
wPort : UInt16, # WORD
wPriority : UInt16, # WORD
wWeight : UInt16, # WORD
dwPropertiesCount : UInt32, # DWORD
keys : UInt16**, # LPCWSTR*
values : UInt16** # LPCWSTR*
) : DNS_SERVICE_INSTANCE*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DnsServiceConstructInstanceNative = Pointer<Void> Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>, Pointer<Void>, Uint16, Uint16, Uint16, Uint32, Pointer<Pointer<Utf16>>, Pointer<Pointer<Utf16>>);
typedef DnsServiceConstructInstanceDart = Pointer<Void> Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>, Pointer<Void>, int, int, int, int, Pointer<Pointer<Utf16>>, Pointer<Pointer<Utf16>>);
final DnsServiceConstructInstance = DynamicLibrary.open('DNSAPI.dll')
.lookupFunction<DnsServiceConstructInstanceNative, DnsServiceConstructInstanceDart>('DnsServiceConstructInstance');
// pServiceName : LPCWSTR -> Pointer<Utf16>
// pHostName : LPCWSTR -> Pointer<Utf16>
// pIp4 : DWORD* optional -> Pointer<Uint32>
// pIp6 : IP6_ADDRESS* optional -> Pointer<Void>
// wPort : WORD -> Uint16
// wPriority : WORD -> Uint16
// wWeight : WORD -> Uint16
// dwPropertiesCount : DWORD -> Uint32
// keys : LPCWSTR* -> Pointer<Pointer<Utf16>>
// values : LPCWSTR* -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DnsServiceConstructInstance"
c_DnsServiceConstructInstance :: CWString -> CWString -> Ptr Word32 -> Ptr () -> Word16 -> Word16 -> Word16 -> Word32 -> Ptr CWString -> Ptr CWString -> IO (Ptr ())
-- pServiceName : LPCWSTR -> CWString
-- pHostName : LPCWSTR -> CWString
-- pIp4 : DWORD* optional -> Ptr Word32
-- pIp6 : IP6_ADDRESS* optional -> Ptr ()
-- wPort : WORD -> Word16
-- wPriority : WORD -> Word16
-- wWeight : WORD -> Word16
-- dwPropertiesCount : DWORD -> Word32
-- keys : LPCWSTR* -> Ptr CWString
-- values : LPCWSTR* -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let dnsserviceconstructinstance =
foreign "DnsServiceConstructInstance"
((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> (ptr void) @-> uint16_t @-> uint16_t @-> uint16_t @-> uint32_t @-> (ptr (ptr uint16_t)) @-> (ptr (ptr uint16_t)) @-> returning (ptr void))
(* pServiceName : LPCWSTR -> (ptr uint16_t) *)
(* pHostName : LPCWSTR -> (ptr uint16_t) *)
(* pIp4 : DWORD* optional -> (ptr uint32_t) *)
(* pIp6 : IP6_ADDRESS* optional -> (ptr void) *)
(* wPort : WORD -> uint16_t *)
(* wPriority : WORD -> uint16_t *)
(* wWeight : WORD -> uint16_t *)
(* dwPropertiesCount : DWORD -> uint32_t *)
(* keys : LPCWSTR* -> (ptr (ptr uint16_t)) *)
(* values : LPCWSTR* -> (ptr (ptr uint16_t)) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library dnsapi (t "DNSAPI.dll"))
(cffi:use-foreign-library dnsapi)
(cffi:defcfun ("DnsServiceConstructInstance" dns-service-construct-instance :convention :stdcall) :pointer
(p-service-name (:string :encoding :utf-16le)) ; LPCWSTR
(p-host-name (:string :encoding :utf-16le)) ; LPCWSTR
(p-ip4 :pointer) ; DWORD* optional
(p-ip6 :pointer) ; IP6_ADDRESS* optional
(w-port :uint16) ; WORD
(w-priority :uint16) ; WORD
(w-weight :uint16) ; WORD
(dw-properties-count :uint32) ; DWORD
(keys :pointer) ; LPCWSTR*
(values :pointer)) ; LPCWSTR*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DnsServiceConstructInstance = Win32::API::More->new('DNSAPI',
'LPVOID DnsServiceConstructInstance(LPCWSTR pServiceName, LPCWSTR pHostName, LPVOID pIp4, LPVOID pIp6, WORD wPort, WORD wPriority, WORD wWeight, DWORD dwPropertiesCount, LPVOID keys, LPVOID values)');
# my $ret = $DnsServiceConstructInstance->Call($pServiceName, $pHostName, $pIp4, $pIp6, $wPort, $wPriority, $wWeight, $dwPropertiesCount, $keys, $values);
# pServiceName : LPCWSTR -> LPCWSTR
# pHostName : LPCWSTR -> LPCWSTR
# pIp4 : DWORD* optional -> LPVOID
# pIp6 : IP6_ADDRESS* optional -> LPVOID
# wPort : WORD -> WORD
# wPriority : WORD -> WORD
# wWeight : WORD -> WORD
# dwPropertiesCount : DWORD -> DWORD
# keys : LPCWSTR* -> LPVOID
# values : LPCWSTR* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。