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

InternetQueryOptionA

関数
WinINetハンドルの指定したオプション値を取得する(ANSI)。
DLLWININET.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

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

パラメーター

名前方向説明
hInternetvoid*inoptional情報を照会する対象のハンドル。
dwOptionDWORDin照会するインターネットオプション。 Option Flags の値のいずれかを指定できます。
lpBuffervoid*outoptionalオプション設定を受け取るバッファーへのポインター。 InternetQueryOption が返す文字列はグローバルに割り当てられるため、呼び出し側アプリケーションは使用を終えたら解放する必要があります。
lpdwBufferLengthDWORD*inoutlpBuffer のサイズ(バイト単位)を格納する変数へのポインター。 InternetQueryOption が返ると、 lpdwBufferLength には lpBuffer に格納されたデータのサイズが設定されます。 GetLastErrorERROR_INSUFFICIENT_BUFFER を返す場合、このパラメーターは要求された情報を保持するために必要なバイト数を指します。

戻り値の型: BOOL

公式ドキュメント

指定したハンドルに対してインターネットオプションを照会します。(ANSI)

戻り値

成功した場合は TRUE、それ以外の場合は FALSE を返します。具体的なエラーメッセージを取得するには、 GetLastError を呼び出します。

解説(Remarks)

指定したハンドルの種類に対して無効なオプションフラグが dwOption パラメーターに渡された場合、 GetLastErrorERROR_INVALID_PARAMETER を返します。

詳細については、 Setting and Retrieving Internet Options を参照してください。

WinINet API の他のすべての側面と同様に、この関数は DllMain やグローバルオブジェクトのコンストラクター・デストラクター内から安全に呼び出すことはできません。

WinINet はサーバー実装をサポートしていません。また、サービスから使用しないでください。サーバー実装やサービスでは Microsoft Windows HTTP Services (WinHTTP) を使用してください。
メモ

wininet.h ヘッダーは InternetQueryOption を、UNICODE プリプロセッサー定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディングに依存しないこのエイリアスの使用を、エンコーディングに依存しないわけではないコードと混在させると、不一致が生じ、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、Conventions for Function Prototypes を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

BOOL InternetQueryOptionA(
    void* hInternet,   // optional
    DWORD dwOption,
    void* lpBuffer,   // optional
    DWORD* lpdwBufferLength
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool InternetQueryOptionA(
    IntPtr hInternet,   // void* optional
    uint dwOption,   // DWORD
    IntPtr lpBuffer,   // void* optional, out
    ref uint lpdwBufferLength   // DWORD* in/out
);
<DllImport("WININET.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function InternetQueryOptionA(
    hInternet As IntPtr,   ' void* optional
    dwOption As UInteger,   ' DWORD
    lpBuffer As IntPtr,   ' void* optional, out
    ByRef lpdwBufferLength As UInteger   ' DWORD* in/out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hInternet : void* optional
' dwOption : DWORD
' lpBuffer : void* optional, out
' lpdwBufferLength : DWORD* in/out
Declare PtrSafe Function InternetQueryOptionA Lib "wininet" ( _
    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

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

var (
	wininet = windows.NewLazySystemDLL("WININET.dll")
	procInternetQueryOptionA = wininet.NewProc("InternetQueryOptionA")
)

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

extern "wininet" fn InternetQueryOptionA(
    hInternet: ?*anyopaque, // void* optional
    dwOption: u32, // DWORD
    lpBuffer: ?*anyopaque, // void* optional, out
    lpdwBufferLength: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) i32;
proc InternetQueryOptionA(
    hInternet: pointer,  # void* optional
    dwOption: uint32,  # DWORD
    lpBuffer: pointer,  # void* optional, out
    lpdwBufferLength: ptr uint32  # DWORD* in/out
): int32 {.importc: "InternetQueryOptionA", stdcall, dynlib: "WININET.dll".}
pragma(lib, "wininet");
extern(Windows)
int InternetQueryOptionA(
    void* hInternet,   // void* optional
    uint dwOption,   // DWORD
    void* lpBuffer,   // void* optional, out
    uint* lpdwBufferLength   // DWORD* in/out
);
ccall((:InternetQueryOptionA, "WININET.dll"), stdcall, Int32,
      (Ptr{Cvoid}, UInt32, Ptr{Cvoid}, Ptr{UInt32}),
      hInternet, dwOption, lpBuffer, lpdwBufferLength)
# hInternet : void* optional -> Ptr{Cvoid}
# dwOption : DWORD -> UInt32
# lpBuffer : void* optional, out -> Ptr{Cvoid}
# lpdwBufferLength : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t InternetQueryOptionA(
    void* hInternet,
    uint32_t dwOption,
    void* lpBuffer,
    uint32_t* lpdwBufferLength);
]]
local wininet = ffi.load("wininet")
-- wininet.InternetQueryOptionA(hInternet, dwOption, lpBuffer, lpdwBufferLength)
-- hInternet : void* optional
-- dwOption : DWORD
-- lpBuffer : void* optional, out
-- lpdwBufferLength : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('WININET.dll');
const InternetQueryOptionA = lib.func('__stdcall', 'InternetQueryOptionA', 'int32_t', ['void *', 'uint32_t', 'void *', 'uint32_t *']);
// InternetQueryOptionA(hInternet, dwOption, lpBuffer, lpdwBufferLength)
// hInternet : void* optional -> 'void *'
// dwOption : DWORD -> 'uint32_t'
// lpBuffer : void* optional, out -> 'void *'
// lpdwBufferLength : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WININET.dll", {
  InternetQueryOptionA: { parameters: ["pointer", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.InternetQueryOptionA(hInternet, dwOption, lpBuffer, lpdwBufferLength)
// hInternet : void* optional -> "pointer"
// dwOption : DWORD -> "u32"
// lpBuffer : void* optional, out -> "pointer"
// lpdwBufferLength : DWORD* in/out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t InternetQueryOptionA(
    void* hInternet,
    uint32_t dwOption,
    void* lpBuffer,
    uint32_t* lpdwBufferLength);
C, "WININET.dll");
// $ffi->InternetQueryOptionA(hInternet, dwOption, lpBuffer, lpdwBufferLength);
// hInternet : void* optional
// dwOption : DWORD
// lpBuffer : void* optional, out
// lpdwBufferLength : DWORD* 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 InternetQueryOptionA(
        Pointer hInternet,   // void* optional
        int dwOption,   // DWORD
        Pointer lpBuffer,   // void* optional, out
        IntByReference lpdwBufferLength   // DWORD* in/out
    );
}
@[Link("wininet")]
lib LibWININET
  fun InternetQueryOptionA = InternetQueryOptionA(
    hInternet : Void*,   # void* optional
    dwOption : UInt32,   # DWORD
    lpBuffer : Void*,   # void* optional, out
    lpdwBufferLength : UInt32*   # DWORD* 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 InternetQueryOptionANative = Int32 Function(Pointer<Void>, Uint32, Pointer<Void>, Pointer<Uint32>);
typedef InternetQueryOptionADart = int Function(Pointer<Void>, int, Pointer<Void>, Pointer<Uint32>);
final InternetQueryOptionA = DynamicLibrary.open('WININET.dll')
    .lookupFunction<InternetQueryOptionANative, InternetQueryOptionADart>('InternetQueryOptionA');
// hInternet : void* optional -> Pointer<Void>
// dwOption : DWORD -> Uint32
// lpBuffer : void* optional, out -> Pointer<Void>
// lpdwBufferLength : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function InternetQueryOptionA(
  hInternet: Pointer;   // void* optional
  dwOption: DWORD;   // DWORD
  lpBuffer: Pointer;   // void* optional, out
  lpdwBufferLength: Pointer   // DWORD* in/out
): BOOL; stdcall;
  external 'WININET.dll' name 'InternetQueryOptionA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "InternetQueryOptionA"
  c_InternetQueryOptionA :: Ptr () -> Word32 -> Ptr () -> Ptr Word32 -> IO CInt
-- hInternet : void* optional -> Ptr ()
-- dwOption : DWORD -> Word32
-- lpBuffer : void* optional, out -> Ptr ()
-- lpdwBufferLength : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let internetqueryoptiona =
  foreign "InternetQueryOptionA"
    ((ptr void) @-> uint32_t @-> (ptr void) @-> (ptr uint32_t) @-> returning int32_t)
(* hInternet : void* optional -> (ptr void) *)
(* dwOption : DWORD -> uint32_t *)
(* lpBuffer : void* optional, out -> (ptr void) *)
(* lpdwBufferLength : DWORD* 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 ("InternetQueryOptionA" internet-query-option-a :convention :stdcall) :int32
  (h-internet :pointer)   ; void* optional
  (dw-option :uint32)   ; DWORD
  (lp-buffer :pointer)   ; void* optional, out
  (lpdw-buffer-length :pointer))   ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $InternetQueryOptionA = Win32::API::More->new('WININET',
    'BOOL InternetQueryOptionA(LPVOID hInternet, DWORD dwOption, LPVOID lpBuffer, LPVOID lpdwBufferLength)');
# my $ret = $InternetQueryOptionA->Call($hInternet, $dwOption, $lpBuffer, $lpdwBufferLength);
# hInternet : void* optional -> LPVOID
# dwOption : DWORD -> DWORD
# lpBuffer : void* optional, out -> LPVOID
# lpdwBufferLength : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
公式の関連項目