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

InternetGetConnectedStateEx

関数
接続状態と接続名を取得する拡張版。
DLLWININET.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// WININET.dll  (ANSI / -A)
#include <windows.h>

BOOL InternetGetConnectedStateEx(
    INTERNET_CONNECTION* lpdwFlags,
    LPSTR lpszConnectionName,   // optional
    DWORD dwNameLen,
    DWORD dwReserved
);

パラメーター

名前方向
lpdwFlagsINTERNET_CONNECTION*out
lpszConnectionNameLPSTRoutoptional
dwNameLenDWORDin
dwReservedDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

// WININET.dll  (ANSI / -A)
#include <windows.h>

BOOL InternetGetConnectedStateEx(
    INTERNET_CONNECTION* lpdwFlags,
    LPSTR lpszConnectionName,   // optional
    DWORD dwNameLen,
    DWORD dwReserved
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool InternetGetConnectedStateEx(
    out uint lpdwFlags,   // INTERNET_CONNECTION* out
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpszConnectionName,   // LPSTR optional, out
    uint dwNameLen,   // DWORD
    uint dwReserved   // DWORD
);
<DllImport("WININET.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function InternetGetConnectedStateEx(
    <Out> ByRef lpdwFlags As UInteger,   ' INTERNET_CONNECTION* out
    <MarshalAs(UnmanagedType.LPStr)> lpszConnectionName As System.Text.StringBuilder,   ' LPSTR optional, out
    dwNameLen As UInteger,   ' DWORD
    dwReserved As UInteger   ' DWORD
) As Boolean
End Function
' lpdwFlags : INTERNET_CONNECTION* out
' lpszConnectionName : LPSTR optional, out
' dwNameLen : DWORD
' dwReserved : DWORD
Declare PtrSafe Function InternetGetConnectedStateEx Lib "wininet" ( _
    ByRef lpdwFlags As Long, _
    ByVal lpszConnectionName As String, _
    ByVal dwNameLen As Long, _
    ByVal dwReserved As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

InternetGetConnectedStateEx = ctypes.windll.wininet.InternetGetConnectedStateEx
InternetGetConnectedStateEx.restype = wintypes.BOOL
InternetGetConnectedStateEx.argtypes = [
    ctypes.c_void_p,  # lpdwFlags : INTERNET_CONNECTION* out
    wintypes.LPSTR,  # lpszConnectionName : LPSTR optional, out
    wintypes.DWORD,  # dwNameLen : 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')
InternetGetConnectedStateEx = Fiddle::Function.new(
  lib['InternetGetConnectedStateEx'],
  [
    Fiddle::TYPE_VOIDP,  # lpdwFlags : INTERNET_CONNECTION* out
    Fiddle::TYPE_VOIDP,  # lpszConnectionName : LPSTR optional, out
    -Fiddle::TYPE_INT,  # dwNameLen : DWORD
    -Fiddle::TYPE_INT,  # dwReserved : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "wininet")]
extern "system" {
    fn InternetGetConnectedStateEx(
        lpdwFlags: *mut u32,  // INTERNET_CONNECTION* out
        lpszConnectionName: *mut u8,  // LPSTR optional, out
        dwNameLen: 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.Ansi, SetLastError = true)]
public static extern bool InternetGetConnectedStateEx(out uint lpdwFlags, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpszConnectionName, uint dwNameLen, uint dwReserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_InternetGetConnectedStateEx' -Namespace Win32 -PassThru
# $api::InternetGetConnectedStateEx(lpdwFlags, lpszConnectionName, dwNameLen, dwReserved)
#uselib "WININET.dll"
#func global InternetGetConnectedStateEx "InternetGetConnectedStateEx" sptr, sptr, sptr, sptr
; InternetGetConnectedStateEx lpdwFlags, varptr(lpszConnectionName), dwNameLen, dwReserved   ; 戻り値は stat
; lpdwFlags : INTERNET_CONNECTION* out -> "sptr"
; lpszConnectionName : LPSTR optional, out -> "sptr"
; dwNameLen : DWORD -> "sptr"
; dwReserved : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WININET.dll"
#cfunc global InternetGetConnectedStateEx "InternetGetConnectedStateEx" int, var, int, int
; res = InternetGetConnectedStateEx(lpdwFlags, lpszConnectionName, dwNameLen, dwReserved)
; lpdwFlags : INTERNET_CONNECTION* out -> "int"
; lpszConnectionName : LPSTR optional, out -> "var"
; dwNameLen : DWORD -> "int"
; dwReserved : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL InternetGetConnectedStateEx(INTERNET_CONNECTION* lpdwFlags, LPSTR lpszConnectionName, DWORD dwNameLen, DWORD dwReserved)
#uselib "WININET.dll"
#cfunc global InternetGetConnectedStateEx "InternetGetConnectedStateEx" int, var, int, int
; res = InternetGetConnectedStateEx(lpdwFlags, lpszConnectionName, dwNameLen, dwReserved)
; lpdwFlags : INTERNET_CONNECTION* out -> "int"
; lpszConnectionName : LPSTR optional, out -> "var"
; dwNameLen : DWORD -> "int"
; dwReserved : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wininet = windows.NewLazySystemDLL("WININET.dll")
	procInternetGetConnectedStateEx = wininet.NewProc("InternetGetConnectedStateEx")
)

// lpdwFlags (INTERNET_CONNECTION* out), lpszConnectionName (LPSTR optional, out), dwNameLen (DWORD), dwReserved (DWORD)
r1, _, err := procInternetGetConnectedStateEx.Call(
	uintptr(lpdwFlags),
	uintptr(lpszConnectionName),
	uintptr(dwNameLen),
	uintptr(dwReserved),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function InternetGetConnectedStateEx(
  lpdwFlags: Pointer;   // INTERNET_CONNECTION* out
  lpszConnectionName: PAnsiChar;   // LPSTR optional, out
  dwNameLen: DWORD;   // DWORD
  dwReserved: DWORD   // DWORD
): BOOL; stdcall;
  external 'WININET.dll' name 'InternetGetConnectedStateEx';
result := DllCall("WININET\InternetGetConnectedStateEx"
    , "Ptr", lpdwFlags   ; INTERNET_CONNECTION* out
    , "Ptr", lpszConnectionName   ; LPSTR optional, out
    , "UInt", dwNameLen   ; DWORD
    , "UInt", dwReserved   ; DWORD
    , "Int")   ; return: BOOL
●InternetGetConnectedStateEx(lpdwFlags, lpszConnectionName, dwNameLen, dwReserved) = DLL("WININET.dll", "bool InternetGetConnectedStateEx(void*, char*, dword, dword)")
# 呼び出し: InternetGetConnectedStateEx(lpdwFlags, lpszConnectionName, dwNameLen, dwReserved)
# lpdwFlags : INTERNET_CONNECTION* out -> "void*"
# lpszConnectionName : LPSTR optional, out -> "char*"
# dwNameLen : DWORD -> "dword"
# dwReserved : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。