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

DnsNameCompare_W

関数
二つのDNS名が等しいかどうかを比較する(Unicode)。
DLLDNSAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// DNSAPI.dll  (Unicode / -W)
#include <windows.h>

BOOL DnsNameCompare_W(
    LPCWSTR pName1,
    LPCWSTR pName2
);

パラメーター

名前方向
pName1LPCWSTRin
pName2LPCWSTRin

戻り値の型: BOOL

各言語での呼び出し定義

// DNSAPI.dll  (Unicode / -W)
#include <windows.h>

BOOL DnsNameCompare_W(
    LPCWSTR pName1,
    LPCWSTR pName2
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("DNSAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool DnsNameCompare_W(
    [MarshalAs(UnmanagedType.LPWStr)] string pName1,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string pName2   // LPCWSTR
);
<DllImport("DNSAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function DnsNameCompare_W(
    <MarshalAs(UnmanagedType.LPWStr)> pName1 As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> pName2 As String   ' LPCWSTR
) As Boolean
End Function
' pName1 : LPCWSTR
' pName2 : LPCWSTR
Declare PtrSafe Function DnsNameCompare_W Lib "dnsapi" ( _
    ByVal pName1 As LongPtr, _
    ByVal pName2 As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DnsNameCompare_W = ctypes.windll.dnsapi.DnsNameCompare_W
DnsNameCompare_W.restype = wintypes.BOOL
DnsNameCompare_W.argtypes = [
    wintypes.LPCWSTR,  # pName1 : LPCWSTR
    wintypes.LPCWSTR,  # pName2 : LPCWSTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('DNSAPI.dll')
DnsNameCompare_W = Fiddle::Function.new(
  lib['DnsNameCompare_W'],
  [
    Fiddle::TYPE_VOIDP,  # pName1 : LPCWSTR
    Fiddle::TYPE_VOIDP,  # pName2 : LPCWSTR
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "dnsapi")]
extern "system" {
    fn DnsNameCompare_W(
        pName1: *const u16,  // LPCWSTR
        pName2: *const u16  // LPCWSTR
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("DNSAPI.dll", CharSet = CharSet.Unicode)]
public static extern bool DnsNameCompare_W([MarshalAs(UnmanagedType.LPWStr)] string pName1, [MarshalAs(UnmanagedType.LPWStr)] string pName2);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DNSAPI_DnsNameCompare_W' -Namespace Win32 -PassThru
# $api::DnsNameCompare_W(pName1, pName2)
#uselib "DNSAPI.dll"
#func global DnsNameCompare_W "DnsNameCompare_W" wptr, wptr
; DnsNameCompare_W pName1, pName2   ; 戻り値は stat
; pName1 : LPCWSTR -> "wptr"
; pName2 : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "DNSAPI.dll"
#cfunc global DnsNameCompare_W "DnsNameCompare_W" wstr, wstr
; res = DnsNameCompare_W(pName1, pName2)
; pName1 : LPCWSTR -> "wstr"
; pName2 : LPCWSTR -> "wstr"
; BOOL DnsNameCompare_W(LPCWSTR pName1, LPCWSTR pName2)
#uselib "DNSAPI.dll"
#cfunc global DnsNameCompare_W "DnsNameCompare_W" wstr, wstr
; res = DnsNameCompare_W(pName1, pName2)
; pName1 : LPCWSTR -> "wstr"
; pName2 : LPCWSTR -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dnsapi = windows.NewLazySystemDLL("DNSAPI.dll")
	procDnsNameCompare_W = dnsapi.NewProc("DnsNameCompare_W")
)

// pName1 (LPCWSTR), pName2 (LPCWSTR)
r1, _, err := procDnsNameCompare_W.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pName1))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pName2))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function DnsNameCompare_W(
  pName1: PWideChar;   // LPCWSTR
  pName2: PWideChar   // LPCWSTR
): BOOL; stdcall;
  external 'DNSAPI.dll' name 'DnsNameCompare_W';
result := DllCall("DNSAPI\DnsNameCompare_W"
    , "WStr", pName1   ; LPCWSTR
    , "WStr", pName2   ; LPCWSTR
    , "Int")   ; return: BOOL
●DnsNameCompare_W(pName1, pName2) = DLL("DNSAPI.dll", "bool DnsNameCompare_W(char*, char*)")
# 呼び出し: DnsNameCompare_W(pName1, pName2)
# pName1 : LPCWSTR -> "char*"
# pName2 : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。