HttpQueryInfoA
関数シグネチャ
// WININET.dll (ANSI / -A)
#include <windows.h>
BOOL HttpQueryInfoA(
void* hRequest,
DWORD dwInfoLevel,
void* lpBuffer, // optional
DWORD* lpdwBufferLength,
DWORD* lpdwIndex // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hRequest | void* | in | HttpOpenRequest または InternetOpenUrl 関数の呼び出しによって返されたハンドル。 |
| dwInfoLevel | DWORD | in | 取得する属性と、リクエストを変更するフラグの組み合わせ。指定可能な属性および修飾子の値の一覧については、Query Info Flags を参照してください。 |
| lpBuffer | void* | inoutoptional | 要求した情報を受け取るバッファーへのポインター。このパラメーターを NULL にすることはできません。 |
| lpdwBufferLength | DWORD* | inout | 呼び出し時に、lpvBuffer が指すバッファーのサイズ(バイト単位)を格納する変数へのポインター。 関数が正常に終了すると、この変数にはバッファーに書き込まれた情報のバイト数が格納されます。文字列の場合、このバイト数には文字列終端の null 文字は含まれません。 関数が拡張エラーコード ERROR_INSUFFICIENT_BUFFER で失敗した場合、終了時に lpdwBufferLength が指す変数には、要求した情報を受け取るのに十分な大きさのバッファーのサイズ(バイト単位)が格納されます。呼び出し側アプリケーションは、このサイズ以上のバッファーを割り当てて関数を再度呼び出すことができます。 |
| lpdwIndex | DWORD* | inoutoptional | 同じ名前を持つ複数のヘッダーを列挙するために使用する、ゼロ始まりのヘッダーインデックスへのポインター。関数を呼び出すとき、このパラメーターは返す対象ヘッダーのインデックスです。関数が返るとき、このパラメーターは次のヘッダーのインデックスになります。次のインデックスが見つからない場合は、ERROR_HTTP_HEADER_NOT_FOUND が返されます。 |
戻り値の型: BOOL
公式ドキュメント
HTTP リクエストに関連付けられたヘッダー情報を取得します。(ANSI)
戻り値
成功した場合は TRUE を、それ以外の場合は FALSE を返します。拡張エラー情報を取得するには、GetLastError を呼び出します。
解説(Remarks)
HttpQueryInfo からは、次の種類のデータを取得できます。
- 文字列(既定)
- SYSTEMTIME(日付の場合)
- DWORD(HTTP_QUERY_FLAG_NUMBER が使用された場合の STATUS_CODE、CONTENT_LENGTH など)
アプリケーションが文字列以外のデータ型でデータを返すことを必要とする場合は、dwInfoLevel に渡す属性に適切な修飾子を含める必要があります。
HttpQueryInfo 関数は、Microsoft Internet Explorer 3.0 では ISO-8859-1 文字に対して(HttpQueryInfoA 関数)、Internet Explorer 4.0 以降では ISO-8859-1 文字に対して(HttpQueryInfoA 関数)、および ISO-8859-1 文字を UTF-16LE 文字に変換したものに対して(HttpQueryInfoW 関数)利用できます。
WinINet API の他のすべての側面と同様に、この関数を DllMain やグローバルオブジェクトのコンストラクター/デストラクターの内部から安全に呼び出すことはできません。
wininet.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして HttpQueryInfo を定義しています。エンコーディング中立なエイリアスの使用を、エンコーディング中立でないコードと混在させると、コンパイルエラーや実行時エラーを引き起こす不整合が生じる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// WININET.dll (ANSI / -A)
#include <windows.h>
BOOL HttpQueryInfoA(
void* hRequest,
DWORD dwInfoLevel,
void* lpBuffer, // optional
DWORD* lpdwBufferLength,
DWORD* lpdwIndex // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool HttpQueryInfoA(
IntPtr hRequest, // void*
uint dwInfoLevel, // DWORD
IntPtr lpBuffer, // void* optional, in/out
ref uint lpdwBufferLength, // DWORD* in/out
IntPtr lpdwIndex // DWORD* optional, in/out
);<DllImport("WININET.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function HttpQueryInfoA(
hRequest As IntPtr, ' void*
dwInfoLevel As UInteger, ' DWORD
lpBuffer As IntPtr, ' void* optional, in/out
ByRef lpdwBufferLength As UInteger, ' DWORD* in/out
lpdwIndex As IntPtr ' DWORD* optional, in/out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hRequest : void*
' dwInfoLevel : DWORD
' lpBuffer : void* optional, in/out
' lpdwBufferLength : DWORD* in/out
' lpdwIndex : DWORD* optional, in/out
Declare PtrSafe Function HttpQueryInfoA Lib "wininet" ( _
ByVal hRequest As LongPtr, _
ByVal dwInfoLevel As Long, _
ByVal lpBuffer As LongPtr, _
ByRef lpdwBufferLength As Long, _
ByVal lpdwIndex As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
HttpQueryInfoA = ctypes.windll.wininet.HttpQueryInfoA
HttpQueryInfoA.restype = wintypes.BOOL
HttpQueryInfoA.argtypes = [
ctypes.POINTER(None), # hRequest : void*
wintypes.DWORD, # dwInfoLevel : DWORD
ctypes.POINTER(None), # lpBuffer : void* optional, in/out
ctypes.POINTER(wintypes.DWORD), # lpdwBufferLength : DWORD* in/out
ctypes.POINTER(wintypes.DWORD), # lpdwIndex : DWORD* optional, in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WININET.dll')
HttpQueryInfoA = Fiddle::Function.new(
lib['HttpQueryInfoA'],
[
Fiddle::TYPE_VOIDP, # hRequest : void*
-Fiddle::TYPE_INT, # dwInfoLevel : DWORD
Fiddle::TYPE_VOIDP, # lpBuffer : void* optional, in/out
Fiddle::TYPE_VOIDP, # lpdwBufferLength : DWORD* in/out
Fiddle::TYPE_VOIDP, # lpdwIndex : DWORD* optional, in/out
],
Fiddle::TYPE_INT)#[link(name = "wininet")]
extern "system" {
fn HttpQueryInfoA(
hRequest: *mut (), // void*
dwInfoLevel: u32, // DWORD
lpBuffer: *mut (), // void* optional, in/out
lpdwBufferLength: *mut u32, // DWORD* in/out
lpdwIndex: *mut u32 // DWORD* optional, in/out
) -> 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 HttpQueryInfoA(IntPtr hRequest, uint dwInfoLevel, IntPtr lpBuffer, ref uint lpdwBufferLength, IntPtr lpdwIndex);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_HttpQueryInfoA' -Namespace Win32 -PassThru
# $api::HttpQueryInfoA(hRequest, dwInfoLevel, lpBuffer, lpdwBufferLength, lpdwIndex)#uselib "WININET.dll"
#func global HttpQueryInfoA "HttpQueryInfoA" sptr, sptr, sptr, sptr, sptr
; HttpQueryInfoA hRequest, dwInfoLevel, lpBuffer, varptr(lpdwBufferLength), varptr(lpdwIndex) ; 戻り値は stat
; hRequest : void* -> "sptr"
; dwInfoLevel : DWORD -> "sptr"
; lpBuffer : void* optional, in/out -> "sptr"
; lpdwBufferLength : DWORD* in/out -> "sptr"
; lpdwIndex : DWORD* optional, in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WININET.dll" #cfunc global HttpQueryInfoA "HttpQueryInfoA" sptr, int, sptr, var, var ; res = HttpQueryInfoA(hRequest, dwInfoLevel, lpBuffer, lpdwBufferLength, lpdwIndex) ; hRequest : void* -> "sptr" ; dwInfoLevel : DWORD -> "int" ; lpBuffer : void* optional, in/out -> "sptr" ; lpdwBufferLength : DWORD* in/out -> "var" ; lpdwIndex : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WININET.dll" #cfunc global HttpQueryInfoA "HttpQueryInfoA" sptr, int, sptr, sptr, sptr ; res = HttpQueryInfoA(hRequest, dwInfoLevel, lpBuffer, varptr(lpdwBufferLength), varptr(lpdwIndex)) ; hRequest : void* -> "sptr" ; dwInfoLevel : DWORD -> "int" ; lpBuffer : void* optional, in/out -> "sptr" ; lpdwBufferLength : DWORD* in/out -> "sptr" ; lpdwIndex : DWORD* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; BOOL HttpQueryInfoA(void* hRequest, DWORD dwInfoLevel, void* lpBuffer, DWORD* lpdwBufferLength, DWORD* lpdwIndex) #uselib "WININET.dll" #cfunc global HttpQueryInfoA "HttpQueryInfoA" intptr, int, intptr, var, var ; res = HttpQueryInfoA(hRequest, dwInfoLevel, lpBuffer, lpdwBufferLength, lpdwIndex) ; hRequest : void* -> "intptr" ; dwInfoLevel : DWORD -> "int" ; lpBuffer : void* optional, in/out -> "intptr" ; lpdwBufferLength : DWORD* in/out -> "var" ; lpdwIndex : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL HttpQueryInfoA(void* hRequest, DWORD dwInfoLevel, void* lpBuffer, DWORD* lpdwBufferLength, DWORD* lpdwIndex) #uselib "WININET.dll" #cfunc global HttpQueryInfoA "HttpQueryInfoA" intptr, int, intptr, intptr, intptr ; res = HttpQueryInfoA(hRequest, dwInfoLevel, lpBuffer, varptr(lpdwBufferLength), varptr(lpdwIndex)) ; hRequest : void* -> "intptr" ; dwInfoLevel : DWORD -> "int" ; lpBuffer : void* optional, in/out -> "intptr" ; lpdwBufferLength : DWORD* in/out -> "intptr" ; lpdwIndex : DWORD* optional, in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wininet = windows.NewLazySystemDLL("WININET.dll")
procHttpQueryInfoA = wininet.NewProc("HttpQueryInfoA")
)
// hRequest (void*), dwInfoLevel (DWORD), lpBuffer (void* optional, in/out), lpdwBufferLength (DWORD* in/out), lpdwIndex (DWORD* optional, in/out)
r1, _, err := procHttpQueryInfoA.Call(
uintptr(hRequest),
uintptr(dwInfoLevel),
uintptr(lpBuffer),
uintptr(lpdwBufferLength),
uintptr(lpdwIndex),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction HttpQueryInfoA(
hRequest: Pointer; // void*
dwInfoLevel: DWORD; // DWORD
lpBuffer: Pointer; // void* optional, in/out
lpdwBufferLength: Pointer; // DWORD* in/out
lpdwIndex: Pointer // DWORD* optional, in/out
): BOOL; stdcall;
external 'WININET.dll' name 'HttpQueryInfoA';result := DllCall("WININET\HttpQueryInfoA"
, "Ptr", hRequest ; void*
, "UInt", dwInfoLevel ; DWORD
, "Ptr", lpBuffer ; void* optional, in/out
, "Ptr", lpdwBufferLength ; DWORD* in/out
, "Ptr", lpdwIndex ; DWORD* optional, in/out
, "Int") ; return: BOOL●HttpQueryInfoA(hRequest, dwInfoLevel, lpBuffer, lpdwBufferLength, lpdwIndex) = DLL("WININET.dll", "bool HttpQueryInfoA(void*, dword, void*, void*, void*)")
# 呼び出し: HttpQueryInfoA(hRequest, dwInfoLevel, lpBuffer, lpdwBufferLength, lpdwIndex)
# hRequest : void* -> "void*"
# dwInfoLevel : DWORD -> "dword"
# lpBuffer : void* optional, in/out -> "void*"
# lpdwBufferLength : DWORD* in/out -> "void*"
# lpdwIndex : DWORD* optional, in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "wininet" fn HttpQueryInfoA(
hRequest: ?*anyopaque, // void*
dwInfoLevel: u32, // DWORD
lpBuffer: ?*anyopaque, // void* optional, in/out
lpdwBufferLength: [*c]u32, // DWORD* in/out
lpdwIndex: [*c]u32 // DWORD* optional, in/out
) callconv(std.os.windows.WINAPI) i32;proc HttpQueryInfoA(
hRequest: pointer, # void*
dwInfoLevel: uint32, # DWORD
lpBuffer: pointer, # void* optional, in/out
lpdwBufferLength: ptr uint32, # DWORD* in/out
lpdwIndex: ptr uint32 # DWORD* optional, in/out
): int32 {.importc: "HttpQueryInfoA", stdcall, dynlib: "WININET.dll".}pragma(lib, "wininet");
extern(Windows)
int HttpQueryInfoA(
void* hRequest, // void*
uint dwInfoLevel, // DWORD
void* lpBuffer, // void* optional, in/out
uint* lpdwBufferLength, // DWORD* in/out
uint* lpdwIndex // DWORD* optional, in/out
);ccall((:HttpQueryInfoA, "WININET.dll"), stdcall, Int32,
(Ptr{Cvoid}, UInt32, Ptr{Cvoid}, Ptr{UInt32}, Ptr{UInt32}),
hRequest, dwInfoLevel, lpBuffer, lpdwBufferLength, lpdwIndex)
# hRequest : void* -> Ptr{Cvoid}
# dwInfoLevel : DWORD -> UInt32
# lpBuffer : void* optional, in/out -> Ptr{Cvoid}
# lpdwBufferLength : DWORD* in/out -> Ptr{UInt32}
# lpdwIndex : DWORD* optional, in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t HttpQueryInfoA(
void* hRequest,
uint32_t dwInfoLevel,
void* lpBuffer,
uint32_t* lpdwBufferLength,
uint32_t* lpdwIndex);
]]
local wininet = ffi.load("wininet")
-- wininet.HttpQueryInfoA(hRequest, dwInfoLevel, lpBuffer, lpdwBufferLength, lpdwIndex)
-- hRequest : void*
-- dwInfoLevel : DWORD
-- lpBuffer : void* optional, in/out
-- lpdwBufferLength : DWORD* in/out
-- lpdwIndex : DWORD* optional, in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WININET.dll');
const HttpQueryInfoA = lib.func('__stdcall', 'HttpQueryInfoA', 'int32_t', ['void *', 'uint32_t', 'void *', 'uint32_t *', 'uint32_t *']);
// HttpQueryInfoA(hRequest, dwInfoLevel, lpBuffer, lpdwBufferLength, lpdwIndex)
// hRequest : void* -> 'void *'
// dwInfoLevel : DWORD -> 'uint32_t'
// lpBuffer : void* optional, in/out -> 'void *'
// lpdwBufferLength : DWORD* in/out -> 'uint32_t *'
// lpdwIndex : DWORD* optional, in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WININET.dll", {
HttpQueryInfoA: { parameters: ["pointer", "u32", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.HttpQueryInfoA(hRequest, dwInfoLevel, lpBuffer, lpdwBufferLength, lpdwIndex)
// hRequest : void* -> "pointer"
// dwInfoLevel : DWORD -> "u32"
// lpBuffer : void* optional, in/out -> "pointer"
// lpdwBufferLength : DWORD* in/out -> "pointer"
// lpdwIndex : DWORD* optional, in/out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t HttpQueryInfoA(
void* hRequest,
uint32_t dwInfoLevel,
void* lpBuffer,
uint32_t* lpdwBufferLength,
uint32_t* lpdwIndex);
C, "WININET.dll");
// $ffi->HttpQueryInfoA(hRequest, dwInfoLevel, lpBuffer, lpdwBufferLength, lpdwIndex);
// hRequest : void*
// dwInfoLevel : DWORD
// lpBuffer : void* optional, in/out
// lpdwBufferLength : DWORD* in/out
// lpdwIndex : DWORD* optional, in/out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Wininet extends StdCallLibrary {
Wininet INSTANCE = Native.load("wininet", Wininet.class, W32APIOptions.ASCII_OPTIONS);
boolean HttpQueryInfoA(
Pointer hRequest, // void*
int dwInfoLevel, // DWORD
Pointer lpBuffer, // void* optional, in/out
IntByReference lpdwBufferLength, // DWORD* in/out
IntByReference lpdwIndex // DWORD* optional, in/out
);
}@[Link("wininet")]
lib LibWININET
fun HttpQueryInfoA = HttpQueryInfoA(
hRequest : Void*, # void*
dwInfoLevel : UInt32, # DWORD
lpBuffer : Void*, # void* optional, in/out
lpdwBufferLength : UInt32*, # DWORD* in/out
lpdwIndex : UInt32* # DWORD* optional, in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef HttpQueryInfoANative = Int32 Function(Pointer<Void>, Uint32, Pointer<Void>, Pointer<Uint32>, Pointer<Uint32>);
typedef HttpQueryInfoADart = int Function(Pointer<Void>, int, Pointer<Void>, Pointer<Uint32>, Pointer<Uint32>);
final HttpQueryInfoA = DynamicLibrary.open('WININET.dll')
.lookupFunction<HttpQueryInfoANative, HttpQueryInfoADart>('HttpQueryInfoA');
// hRequest : void* -> Pointer<Void>
// dwInfoLevel : DWORD -> Uint32
// lpBuffer : void* optional, in/out -> Pointer<Void>
// lpdwBufferLength : DWORD* in/out -> Pointer<Uint32>
// lpdwIndex : DWORD* optional, in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function HttpQueryInfoA(
hRequest: Pointer; // void*
dwInfoLevel: DWORD; // DWORD
lpBuffer: Pointer; // void* optional, in/out
lpdwBufferLength: Pointer; // DWORD* in/out
lpdwIndex: Pointer // DWORD* optional, in/out
): BOOL; stdcall;
external 'WININET.dll' name 'HttpQueryInfoA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "HttpQueryInfoA"
c_HttpQueryInfoA :: Ptr () -> Word32 -> Ptr () -> Ptr Word32 -> Ptr Word32 -> IO CInt
-- hRequest : void* -> Ptr ()
-- dwInfoLevel : DWORD -> Word32
-- lpBuffer : void* optional, in/out -> Ptr ()
-- lpdwBufferLength : DWORD* in/out -> Ptr Word32
-- lpdwIndex : DWORD* optional, in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let httpqueryinfoa =
foreign "HttpQueryInfoA"
((ptr void) @-> uint32_t @-> (ptr void) @-> (ptr uint32_t) @-> (ptr uint32_t) @-> returning int32_t)
(* hRequest : void* -> (ptr void) *)
(* dwInfoLevel : DWORD -> uint32_t *)
(* lpBuffer : void* optional, in/out -> (ptr void) *)
(* lpdwBufferLength : DWORD* in/out -> (ptr uint32_t) *)
(* lpdwIndex : DWORD* optional, in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library wininet (t "WININET.dll"))
(cffi:use-foreign-library wininet)
(cffi:defcfun ("HttpQueryInfoA" http-query-info-a :convention :stdcall) :int32
(h-request :pointer) ; void*
(dw-info-level :uint32) ; DWORD
(lp-buffer :pointer) ; void* optional, in/out
(lpdw-buffer-length :pointer) ; DWORD* in/out
(lpdw-index :pointer)) ; DWORD* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $HttpQueryInfoA = Win32::API::More->new('WININET',
'BOOL HttpQueryInfoA(LPVOID hRequest, DWORD dwInfoLevel, LPVOID lpBuffer, LPVOID lpdwBufferLength, LPVOID lpdwIndex)');
# my $ret = $HttpQueryInfoA->Call($hRequest, $dwInfoLevel, $lpBuffer, $lpdwBufferLength, $lpdwIndex);
# hRequest : void* -> LPVOID
# dwInfoLevel : DWORD -> DWORD
# lpBuffer : void* optional, in/out -> LPVOID
# lpdwBufferLength : DWORD* in/out -> LPVOID
# lpdwIndex : DWORD* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f HttpQueryInfoW (Unicode版) — HTTP応答のヘッダーや状態情報を問い合わせる(Unicode版)。