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

WinHttpSetTimeouts

関数
WinHTTP操作の各種タイムアウト値を設定する。
DLLWINHTTP.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// WINHTTP.dll
#include <windows.h>

BOOL WinHttpSetTimeouts(
    void* hInternet,
    INT nResolveTimeout,
    INT nConnectTimeout,
    INT nSendTimeout,
    INT nReceiveTimeout
);

パラメーター

名前方向
hInternetvoid*inout
nResolveTimeoutINTin
nConnectTimeoutINTin
nSendTimeoutINTin
nReceiveTimeoutINTin

戻り値の型: BOOL

各言語での呼び出し定義

// WINHTTP.dll
#include <windows.h>

BOOL WinHttpSetTimeouts(
    void* hInternet,
    INT nResolveTimeout,
    INT nConnectTimeout,
    INT nSendTimeout,
    INT nReceiveTimeout
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WINHTTP.dll", SetLastError = true, ExactSpelling = true)]
static extern bool WinHttpSetTimeouts(
    IntPtr hInternet,   // void* in/out
    int nResolveTimeout,   // INT
    int nConnectTimeout,   // INT
    int nSendTimeout,   // INT
    int nReceiveTimeout   // INT
);
<DllImport("WINHTTP.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WinHttpSetTimeouts(
    hInternet As IntPtr,   ' void* in/out
    nResolveTimeout As Integer,   ' INT
    nConnectTimeout As Integer,   ' INT
    nSendTimeout As Integer,   ' INT
    nReceiveTimeout As Integer   ' INT
) As Boolean
End Function
' hInternet : void* in/out
' nResolveTimeout : INT
' nConnectTimeout : INT
' nSendTimeout : INT
' nReceiveTimeout : INT
Declare PtrSafe Function WinHttpSetTimeouts Lib "winhttp" ( _
    ByVal hInternet As LongPtr, _
    ByVal nResolveTimeout As Long, _
    ByVal nConnectTimeout As Long, _
    ByVal nSendTimeout As Long, _
    ByVal nReceiveTimeout As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WinHttpSetTimeouts = ctypes.windll.winhttp.WinHttpSetTimeouts
WinHttpSetTimeouts.restype = wintypes.BOOL
WinHttpSetTimeouts.argtypes = [
    ctypes.POINTER(None),  # hInternet : void* in/out
    ctypes.c_int,  # nResolveTimeout : INT
    ctypes.c_int,  # nConnectTimeout : INT
    ctypes.c_int,  # nSendTimeout : INT
    ctypes.c_int,  # nReceiveTimeout : INT
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WINHTTP.dll')
WinHttpSetTimeouts = Fiddle::Function.new(
  lib['WinHttpSetTimeouts'],
  [
    Fiddle::TYPE_VOIDP,  # hInternet : void* in/out
    Fiddle::TYPE_INT,  # nResolveTimeout : INT
    Fiddle::TYPE_INT,  # nConnectTimeout : INT
    Fiddle::TYPE_INT,  # nSendTimeout : INT
    Fiddle::TYPE_INT,  # nReceiveTimeout : INT
  ],
  Fiddle::TYPE_INT)
#[link(name = "winhttp")]
extern "system" {
    fn WinHttpSetTimeouts(
        hInternet: *mut (),  // void* in/out
        nResolveTimeout: i32,  // INT
        nConnectTimeout: i32,  // INT
        nSendTimeout: i32,  // INT
        nReceiveTimeout: i32  // INT
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WINHTTP.dll", SetLastError = true)]
public static extern bool WinHttpSetTimeouts(IntPtr hInternet, int nResolveTimeout, int nConnectTimeout, int nSendTimeout, int nReceiveTimeout);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WINHTTP_WinHttpSetTimeouts' -Namespace Win32 -PassThru
# $api::WinHttpSetTimeouts(hInternet, nResolveTimeout, nConnectTimeout, nSendTimeout, nReceiveTimeout)
#uselib "WINHTTP.dll"
#func global WinHttpSetTimeouts "WinHttpSetTimeouts" sptr, sptr, sptr, sptr, sptr
; WinHttpSetTimeouts hInternet, nResolveTimeout, nConnectTimeout, nSendTimeout, nReceiveTimeout   ; 戻り値は stat
; hInternet : void* in/out -> "sptr"
; nResolveTimeout : INT -> "sptr"
; nConnectTimeout : INT -> "sptr"
; nSendTimeout : INT -> "sptr"
; nReceiveTimeout : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WINHTTP.dll"
#cfunc global WinHttpSetTimeouts "WinHttpSetTimeouts" sptr, int, int, int, int
; res = WinHttpSetTimeouts(hInternet, nResolveTimeout, nConnectTimeout, nSendTimeout, nReceiveTimeout)
; hInternet : void* in/out -> "sptr"
; nResolveTimeout : INT -> "int"
; nConnectTimeout : INT -> "int"
; nSendTimeout : INT -> "int"
; nReceiveTimeout : INT -> "int"
; BOOL WinHttpSetTimeouts(void* hInternet, INT nResolveTimeout, INT nConnectTimeout, INT nSendTimeout, INT nReceiveTimeout)
#uselib "WINHTTP.dll"
#cfunc global WinHttpSetTimeouts "WinHttpSetTimeouts" intptr, int, int, int, int
; res = WinHttpSetTimeouts(hInternet, nResolveTimeout, nConnectTimeout, nSendTimeout, nReceiveTimeout)
; hInternet : void* in/out -> "intptr"
; nResolveTimeout : INT -> "int"
; nConnectTimeout : INT -> "int"
; nSendTimeout : INT -> "int"
; nReceiveTimeout : INT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winhttp = windows.NewLazySystemDLL("WINHTTP.dll")
	procWinHttpSetTimeouts = winhttp.NewProc("WinHttpSetTimeouts")
)

// hInternet (void* in/out), nResolveTimeout (INT), nConnectTimeout (INT), nSendTimeout (INT), nReceiveTimeout (INT)
r1, _, err := procWinHttpSetTimeouts.Call(
	uintptr(hInternet),
	uintptr(nResolveTimeout),
	uintptr(nConnectTimeout),
	uintptr(nSendTimeout),
	uintptr(nReceiveTimeout),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function WinHttpSetTimeouts(
  hInternet: Pointer;   // void* in/out
  nResolveTimeout: Integer;   // INT
  nConnectTimeout: Integer;   // INT
  nSendTimeout: Integer;   // INT
  nReceiveTimeout: Integer   // INT
): BOOL; stdcall;
  external 'WINHTTP.dll' name 'WinHttpSetTimeouts';
result := DllCall("WINHTTP\WinHttpSetTimeouts"
    , "Ptr", hInternet   ; void* in/out
    , "Int", nResolveTimeout   ; INT
    , "Int", nConnectTimeout   ; INT
    , "Int", nSendTimeout   ; INT
    , "Int", nReceiveTimeout   ; INT
    , "Int")   ; return: BOOL
●WinHttpSetTimeouts(hInternet, nResolveTimeout, nConnectTimeout, nSendTimeout, nReceiveTimeout) = DLL("WINHTTP.dll", "bool WinHttpSetTimeouts(void*, int, int, int, int)")
# 呼び出し: WinHttpSetTimeouts(hInternet, nResolveTimeout, nConnectTimeout, nSendTimeout, nReceiveTimeout)
# hInternet : void* in/out -> "void*"
# nResolveTimeout : INT -> "int"
# nConnectTimeout : INT -> "int"
# nSendTimeout : INT -> "int"
# nReceiveTimeout : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。