Win32 API 日本語リファレンス
ホームSystem.EventNotificationService › IsDestinationReachableW

IsDestinationReachableW

関数
指定宛先への到達可能性を確認する(Unicode版)。
DLLSensApi.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL IsDestinationReachableW(
    LPCWSTR lpszDestination,
    QOCINFO* lpQOCInfo
);

パラメーター

名前方向
lpszDestinationLPCWSTRin
lpQOCInfoQOCINFO*inout

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL IsDestinationReachableW(
    LPCWSTR lpszDestination,
    QOCINFO* lpQOCInfo
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SensApi.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool IsDestinationReachableW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpszDestination,   // LPCWSTR
    IntPtr lpQOCInfo   // QOCINFO* in/out
);
<DllImport("SensApi.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function IsDestinationReachableW(
    <MarshalAs(UnmanagedType.LPWStr)> lpszDestination As String,   ' LPCWSTR
    lpQOCInfo As IntPtr   ' QOCINFO* in/out
) As Boolean
End Function
' lpszDestination : LPCWSTR
' lpQOCInfo : QOCINFO* in/out
Declare PtrSafe Function IsDestinationReachableW Lib "sensapi" ( _
    ByVal lpszDestination As LongPtr, _
    ByVal lpQOCInfo 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

IsDestinationReachableW = ctypes.windll.sensapi.IsDestinationReachableW
IsDestinationReachableW.restype = wintypes.BOOL
IsDestinationReachableW.argtypes = [
    wintypes.LPCWSTR,  # lpszDestination : LPCWSTR
    ctypes.c_void_p,  # lpQOCInfo : QOCINFO* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SensApi.dll')
IsDestinationReachableW = Fiddle::Function.new(
  lib['IsDestinationReachableW'],
  [
    Fiddle::TYPE_VOIDP,  # lpszDestination : LPCWSTR
    Fiddle::TYPE_VOIDP,  # lpQOCInfo : QOCINFO* in/out
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "sensapi")]
extern "system" {
    fn IsDestinationReachableW(
        lpszDestination: *const u16,  // LPCWSTR
        lpQOCInfo: *mut QOCINFO  // QOCINFO* in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SensApi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool IsDestinationReachableW([MarshalAs(UnmanagedType.LPWStr)] string lpszDestination, IntPtr lpQOCInfo);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SensApi_IsDestinationReachableW' -Namespace Win32 -PassThru
# $api::IsDestinationReachableW(lpszDestination, lpQOCInfo)
#uselib "SensApi.dll"
#func global IsDestinationReachableW "IsDestinationReachableW" wptr, wptr
; IsDestinationReachableW lpszDestination, varptr(lpQOCInfo)   ; 戻り値は stat
; lpszDestination : LPCWSTR -> "wptr"
; lpQOCInfo : QOCINFO* in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SensApi.dll"
#cfunc global IsDestinationReachableW "IsDestinationReachableW" wstr, var
; res = IsDestinationReachableW(lpszDestination, lpQOCInfo)
; lpszDestination : LPCWSTR -> "wstr"
; lpQOCInfo : QOCINFO* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL IsDestinationReachableW(LPCWSTR lpszDestination, QOCINFO* lpQOCInfo)
#uselib "SensApi.dll"
#cfunc global IsDestinationReachableW "IsDestinationReachableW" wstr, var
; res = IsDestinationReachableW(lpszDestination, lpQOCInfo)
; lpszDestination : LPCWSTR -> "wstr"
; lpQOCInfo : QOCINFO* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	sensapi = windows.NewLazySystemDLL("SensApi.dll")
	procIsDestinationReachableW = sensapi.NewProc("IsDestinationReachableW")
)

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