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

WinHttpQueryOption

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

シグネチャ

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

BOOL WinHttpQueryOption(
    void* hInternet,
    DWORD dwOption,
    void* lpBuffer,   // optional
    DWORD* lpdwBufferLength
);

パラメーター

名前方向
hInternetvoid*inout
dwOptionDWORDin
lpBuffervoid*outoptional
lpdwBufferLengthDWORD*inout

戻り値の型: BOOL

各言語での呼び出し定義

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

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

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

lib = Fiddle.dlopen('WINHTTP.dll')
WinHttpQueryOption = Fiddle::Function.new(
  lib['WinHttpQueryOption'],
  [
    Fiddle::TYPE_VOIDP,  # hInternet : void* in/out
    -Fiddle::TYPE_INT,  # dwOption : DWORD
    Fiddle::TYPE_VOIDP,  # lpBuffer : void* optional, out
    Fiddle::TYPE_VOIDP,  # lpdwBufferLength : DWORD* in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "winhttp")]
extern "system" {
    fn WinHttpQueryOption(
        hInternet: *mut (),  // void* in/out
        dwOption: u32,  // DWORD
        lpBuffer: *mut (),  // void* optional, out
        lpdwBufferLength: *mut u32  // DWORD* in/out
    ) -> 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 WinHttpQueryOption(IntPtr hInternet, uint dwOption, IntPtr lpBuffer, ref uint lpdwBufferLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WINHTTP_WinHttpQueryOption' -Namespace Win32 -PassThru
# $api::WinHttpQueryOption(hInternet, dwOption, lpBuffer, lpdwBufferLength)
#uselib "WINHTTP.dll"
#func global WinHttpQueryOption "WinHttpQueryOption" sptr, sptr, sptr, sptr
; WinHttpQueryOption hInternet, dwOption, lpBuffer, varptr(lpdwBufferLength)   ; 戻り値は stat
; hInternet : void* in/out -> "sptr"
; dwOption : DWORD -> "sptr"
; lpBuffer : void* optional, out -> "sptr"
; lpdwBufferLength : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WINHTTP.dll"
#cfunc global WinHttpQueryOption "WinHttpQueryOption" sptr, int, sptr, var
; res = WinHttpQueryOption(hInternet, dwOption, lpBuffer, lpdwBufferLength)
; hInternet : void* in/out -> "sptr"
; dwOption : DWORD -> "int"
; lpBuffer : void* optional, out -> "sptr"
; lpdwBufferLength : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL WinHttpQueryOption(void* hInternet, DWORD dwOption, void* lpBuffer, DWORD* lpdwBufferLength)
#uselib "WINHTTP.dll"
#cfunc global WinHttpQueryOption "WinHttpQueryOption" intptr, int, intptr, var
; res = WinHttpQueryOption(hInternet, dwOption, lpBuffer, lpdwBufferLength)
; hInternet : void* in/out -> "intptr"
; dwOption : DWORD -> "int"
; lpBuffer : void* optional, out -> "intptr"
; lpdwBufferLength : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winhttp = windows.NewLazySystemDLL("WINHTTP.dll")
	procWinHttpQueryOption = winhttp.NewProc("WinHttpQueryOption")
)

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