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

InternetQueryOptionW

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

シグネチャ

// WININET.dll  (Unicode / -W)
#include <windows.h>

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

パラメーター

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

戻り値の型: BOOL

公式ドキュメント

指定したハンドルに対して Internet オプションを照会します。(Unicode)

戻り値

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

解説(Remarks)

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

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

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

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

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

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

各言語での呼び出し定義

// WININET.dll  (Unicode / -W)
#include <windows.h>

BOOL InternetQueryOptionW(
    void* hInternet,   // optional
    DWORD dwOption,
    void* lpBuffer,   // optional
    DWORD* lpdwBufferLength
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool InternetQueryOptionW(
    IntPtr hInternet,   // void* optional
    uint dwOption,   // DWORD
    IntPtr lpBuffer,   // void* optional, out
    ref uint lpdwBufferLength   // DWORD* in/out
);
<DllImport("WININET.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function InternetQueryOptionW(
    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 InternetQueryOptionW Lib "wininet" ( _
    ByVal hInternet As LongPtr, _
    ByVal dwOption As Long, _
    ByVal lpBuffer As LongPtr, _
    ByRef lpdwBufferLength As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

InternetQueryOptionW = ctypes.windll.wininet.InternetQueryOptionW
InternetQueryOptionW.restype = wintypes.BOOL
InternetQueryOptionW.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')
InternetQueryOptionW = Fiddle::Function.new(
  lib['InternetQueryOptionW'],
  [
    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)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "wininet")]
extern "system" {
    fn InternetQueryOptionW(
        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.Unicode, SetLastError = true)]
public static extern bool InternetQueryOptionW(IntPtr hInternet, uint dwOption, IntPtr lpBuffer, ref uint lpdwBufferLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_InternetQueryOptionW' -Namespace Win32 -PassThru
# $api::InternetQueryOptionW(hInternet, dwOption, lpBuffer, lpdwBufferLength)
#uselib "WININET.dll"
#func global InternetQueryOptionW "InternetQueryOptionW" wptr, wptr, wptr, wptr
; InternetQueryOptionW hInternet, dwOption, lpBuffer, varptr(lpdwBufferLength)   ; 戻り値は stat
; hInternet : void* optional -> "wptr"
; dwOption : DWORD -> "wptr"
; lpBuffer : void* optional, out -> "wptr"
; lpdwBufferLength : DWORD* in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WININET.dll"
#cfunc global InternetQueryOptionW "InternetQueryOptionW" sptr, int, sptr, var
; res = InternetQueryOptionW(hInternet, dwOption, lpBuffer, lpdwBufferLength)
; hInternet : void* optional -> "sptr"
; dwOption : DWORD -> "int"
; lpBuffer : void* optional, out -> "sptr"
; lpdwBufferLength : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL InternetQueryOptionW(void* hInternet, DWORD dwOption, void* lpBuffer, DWORD* lpdwBufferLength)
#uselib "WININET.dll"
#cfunc global InternetQueryOptionW "InternetQueryOptionW" intptr, int, intptr, var
; res = InternetQueryOptionW(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")
	procInternetQueryOptionW = wininet.NewProc("InternetQueryOptionW")
)

// hInternet (void* optional), dwOption (DWORD), lpBuffer (void* optional, out), lpdwBufferLength (DWORD* in/out)
r1, _, err := procInternetQueryOptionW.Call(
	uintptr(hInternet),
	uintptr(dwOption),
	uintptr(lpBuffer),
	uintptr(lpdwBufferLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function InternetQueryOptionW(
  hInternet: Pointer;   // void* optional
  dwOption: DWORD;   // DWORD
  lpBuffer: Pointer;   // void* optional, out
  lpdwBufferLength: Pointer   // DWORD* in/out
): BOOL; stdcall;
  external 'WININET.dll' name 'InternetQueryOptionW';
result := DllCall("WININET\InternetQueryOptionW"
    , "Ptr", hInternet   ; void* optional
    , "UInt", dwOption   ; DWORD
    , "Ptr", lpBuffer   ; void* optional, out
    , "Ptr", lpdwBufferLength   ; DWORD* in/out
    , "Int")   ; return: BOOL
●InternetQueryOptionW(hInternet, dwOption, lpBuffer, lpdwBufferLength) = DLL("WININET.dll", "bool InternetQueryOptionW(void*, dword, void*, void*)")
# 呼び出し: InternetQueryOptionW(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)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "wininet" fn InternetQueryOptionW(
    hInternet: ?*anyopaque, // void* optional
    dwOption: u32, // DWORD
    lpBuffer: ?*anyopaque, // void* optional, out
    lpdwBufferLength: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc InternetQueryOptionW(
    hInternet: pointer,  # void* optional
    dwOption: uint32,  # DWORD
    lpBuffer: pointer,  # void* optional, out
    lpdwBufferLength: ptr uint32  # DWORD* in/out
): int32 {.importc: "InternetQueryOptionW", stdcall, dynlib: "WININET.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "wininet");
extern(Windows)
int InternetQueryOptionW(
    void* hInternet,   // void* optional
    uint dwOption,   // DWORD
    void* lpBuffer,   // void* optional, out
    uint* lpdwBufferLength   // DWORD* in/out
);
ccall((:InternetQueryOptionW, "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 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t InternetQueryOptionW(
    void* hInternet,
    uint32_t dwOption,
    void* lpBuffer,
    uint32_t* lpdwBufferLength);
]]
local wininet = ffi.load("wininet")
-- wininet.InternetQueryOptionW(hInternet, dwOption, lpBuffer, lpdwBufferLength)
-- hInternet : void* optional
-- dwOption : DWORD
-- lpBuffer : void* optional, out
-- lpdwBufferLength : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('WININET.dll');
const InternetQueryOptionW = lib.func('__stdcall', 'InternetQueryOptionW', 'int32_t', ['void *', 'uint32_t', 'void *', 'uint32_t *']);
// InternetQueryOptionW(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", {
  InternetQueryOptionW: { parameters: ["pointer", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.InternetQueryOptionW(hInternet, dwOption, lpBuffer, lpdwBufferLength)
// hInternet : void* optional -> "pointer"
// dwOption : DWORD -> "u32"
// lpBuffer : void* optional, out -> "pointer"
// lpdwBufferLength : DWORD* in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t InternetQueryOptionW(
    void* hInternet,
    uint32_t dwOption,
    void* lpBuffer,
    uint32_t* lpdwBufferLength);
C, "WININET.dll");
// $ffi->InternetQueryOptionW(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.UNICODE_OPTIONS);
    boolean InternetQueryOptionW(
        Pointer hInternet,   // void* optional
        int dwOption,   // DWORD
        Pointer lpBuffer,   // void* optional, out
        IntByReference lpdwBufferLength   // DWORD* in/out
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("wininet")]
lib LibWININET
  fun InternetQueryOptionW = InternetQueryOptionW(
    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 InternetQueryOptionWNative = Int32 Function(Pointer<Void>, Uint32, Pointer<Void>, Pointer<Uint32>);
typedef InternetQueryOptionWDart = int Function(Pointer<Void>, int, Pointer<Void>, Pointer<Uint32>);
final InternetQueryOptionW = DynamicLibrary.open('WININET.dll')
    .lookupFunction<InternetQueryOptionWNative, InternetQueryOptionWDart>('InternetQueryOptionW');
// 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 InternetQueryOptionW(
  hInternet: Pointer;   // void* optional
  dwOption: DWORD;   // DWORD
  lpBuffer: Pointer;   // void* optional, out
  lpdwBufferLength: Pointer   // DWORD* in/out
): BOOL; stdcall;
  external 'WININET.dll' name 'InternetQueryOptionW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "InternetQueryOptionW"
  c_InternetQueryOptionW :: 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 internetqueryoptionw =
  foreign "InternetQueryOptionW"
    ((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 ("InternetQueryOptionW" internet-query-option-w :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 $InternetQueryOptionW = Win32::API::More->new('WININET',
    'BOOL InternetQueryOptionW(LPVOID hInternet, DWORD dwOption, LPVOID lpBuffer, LPVOID lpdwBufferLength)');
# my $ret = $InternetQueryOptionW->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 を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

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