Win32 API 日本語リファレンス
ホームNetworking.WinInet › InternetCheckConnectionW

InternetCheckConnectionW

関数
指定URLへの接続可否を確認する(Unicode版)。
DLLWININET.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL InternetCheckConnectionW(
    LPCWSTR lpszUrl,
    DWORD dwFlags,
    DWORD dwReserved
);

パラメーター

名前方向
lpszUrlLPCWSTRin
dwFlagsDWORDin
dwReservedDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL InternetCheckConnectionW(
    LPCWSTR lpszUrl,
    DWORD dwFlags,
    DWORD dwReserved
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool InternetCheckConnectionW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpszUrl,   // LPCWSTR
    uint dwFlags,   // DWORD
    uint dwReserved   // DWORD
);
<DllImport("WININET.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function InternetCheckConnectionW(
    <MarshalAs(UnmanagedType.LPWStr)> lpszUrl As String,   ' LPCWSTR
    dwFlags As UInteger,   ' DWORD
    dwReserved As UInteger   ' DWORD
) As Boolean
End Function
' lpszUrl : LPCWSTR
' dwFlags : DWORD
' dwReserved : DWORD
Declare PtrSafe Function InternetCheckConnectionW Lib "wininet" ( _
    ByVal lpszUrl As LongPtr, _
    ByVal dwFlags As Long, _
    ByVal dwReserved As Long) 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

InternetCheckConnectionW = ctypes.windll.wininet.InternetCheckConnectionW
InternetCheckConnectionW.restype = wintypes.BOOL
InternetCheckConnectionW.argtypes = [
    wintypes.LPCWSTR,  # lpszUrl : LPCWSTR
    wintypes.DWORD,  # dwFlags : DWORD
    wintypes.DWORD,  # dwReserved : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	wininet = windows.NewLazySystemDLL("WININET.dll")
	procInternetCheckConnectionW = wininet.NewProc("InternetCheckConnectionW")
)

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