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

WinHttpSetOption

関数
WinHTTPハンドルの指定したオプション値を設定する。
DLLWINHTTP.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL WinHttpSetOption(
    void* hInternet,   // optional
    DWORD dwOption,
    void* lpBuffer,   // optional
    DWORD dwBufferLength
);

パラメーター

名前方向
hInternetvoid*inoptional
dwOptionDWORDin
lpBuffervoid*inoptional
dwBufferLengthDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL WinHttpSetOption(
    void* hInternet,   // optional
    DWORD dwOption,
    void* lpBuffer,   // optional
    DWORD dwBufferLength
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WINHTTP.dll", SetLastError = true, ExactSpelling = true)]
static extern bool WinHttpSetOption(
    IntPtr hInternet,   // void* optional
    uint dwOption,   // DWORD
    IntPtr lpBuffer,   // void* optional
    uint dwBufferLength   // DWORD
);
<DllImport("WINHTTP.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WinHttpSetOption(
    hInternet As IntPtr,   ' void* optional
    dwOption As UInteger,   ' DWORD
    lpBuffer As IntPtr,   ' void* optional
    dwBufferLength As UInteger   ' DWORD
) As Boolean
End Function
' hInternet : void* optional
' dwOption : DWORD
' lpBuffer : void* optional
' dwBufferLength : DWORD
Declare PtrSafe Function WinHttpSetOption Lib "winhttp" ( _
    ByVal hInternet As LongPtr, _
    ByVal dwOption As Long, _
    ByVal lpBuffer As LongPtr, _
    ByVal dwBufferLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WinHttpSetOption = ctypes.windll.winhttp.WinHttpSetOption
WinHttpSetOption.restype = wintypes.BOOL
WinHttpSetOption.argtypes = [
    ctypes.POINTER(None),  # hInternet : void* optional
    wintypes.DWORD,  # dwOption : DWORD
    ctypes.POINTER(None),  # lpBuffer : void* optional
    wintypes.DWORD,  # dwBufferLength : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WINHTTP.dll')
WinHttpSetOption = Fiddle::Function.new(
  lib['WinHttpSetOption'],
  [
    Fiddle::TYPE_VOIDP,  # hInternet : void* optional
    -Fiddle::TYPE_INT,  # dwOption : DWORD
    Fiddle::TYPE_VOIDP,  # lpBuffer : void* optional
    -Fiddle::TYPE_INT,  # dwBufferLength : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "winhttp")]
extern "system" {
    fn WinHttpSetOption(
        hInternet: *mut (),  // void* optional
        dwOption: u32,  // DWORD
        lpBuffer: *mut (),  // void* optional
        dwBufferLength: u32  // DWORD
    ) -> 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 WinHttpSetOption(IntPtr hInternet, uint dwOption, IntPtr lpBuffer, uint dwBufferLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WINHTTP_WinHttpSetOption' -Namespace Win32 -PassThru
# $api::WinHttpSetOption(hInternet, dwOption, lpBuffer, dwBufferLength)
#uselib "WINHTTP.dll"
#func global WinHttpSetOption "WinHttpSetOption" sptr, sptr, sptr, sptr
; WinHttpSetOption hInternet, dwOption, lpBuffer, dwBufferLength   ; 戻り値は stat
; hInternet : void* optional -> "sptr"
; dwOption : DWORD -> "sptr"
; lpBuffer : void* optional -> "sptr"
; dwBufferLength : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WINHTTP.dll"
#cfunc global WinHttpSetOption "WinHttpSetOption" sptr, int, sptr, int
; res = WinHttpSetOption(hInternet, dwOption, lpBuffer, dwBufferLength)
; hInternet : void* optional -> "sptr"
; dwOption : DWORD -> "int"
; lpBuffer : void* optional -> "sptr"
; dwBufferLength : DWORD -> "int"
; BOOL WinHttpSetOption(void* hInternet, DWORD dwOption, void* lpBuffer, DWORD dwBufferLength)
#uselib "WINHTTP.dll"
#cfunc global WinHttpSetOption "WinHttpSetOption" intptr, int, intptr, int
; res = WinHttpSetOption(hInternet, dwOption, lpBuffer, dwBufferLength)
; hInternet : void* optional -> "intptr"
; dwOption : DWORD -> "int"
; lpBuffer : void* optional -> "intptr"
; dwBufferLength : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winhttp = windows.NewLazySystemDLL("WINHTTP.dll")
	procWinHttpSetOption = winhttp.NewProc("WinHttpSetOption")
)

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