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

InternetSetOptionExW

関数
WinINetハンドルのオプション値を拡張フラグ付きで設定する(Unicode)。
DLLWININET.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

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

パラメーター

名前方向説明
hInternetvoid*inoptional使用されません。
dwOptionDWORDin使用されません。
lpBuffervoid*inoptional使用されません。
dwBufferLengthDWORDin使用されません。
dwFlagsDWORDin使用されません。

戻り値の型: BOOL

公式ドキュメント

サポートされていません。InternetSetOption 関数を呼び出すスタブとしてのみ実装されており、InternetSetOptionEx 自体には機能がありません。現時点ではこの関数を使用しないでください。(Unicode)

戻り値

この関数は値を返しません。

解説(Remarks)

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

wininet.h ヘッダーは InternetSetOptionEx を、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  (Unicode / -W)
#include <windows.h>

BOOL InternetSetOptionExW(
    void* hInternet,   // optional
    DWORD dwOption,
    void* lpBuffer,   // optional
    DWORD dwBufferLength,
    DWORD dwFlags
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool InternetSetOptionExW(
    IntPtr hInternet,   // void* optional
    uint dwOption,   // DWORD
    IntPtr lpBuffer,   // void* optional
    uint dwBufferLength,   // DWORD
    uint dwFlags   // DWORD
);
<DllImport("WININET.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function InternetSetOptionExW(
    hInternet As IntPtr,   ' void* optional
    dwOption As UInteger,   ' DWORD
    lpBuffer As IntPtr,   ' void* optional
    dwBufferLength As UInteger,   ' DWORD
    dwFlags As UInteger   ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hInternet : void* optional
' dwOption : DWORD
' lpBuffer : void* optional
' dwBufferLength : DWORD
' dwFlags : DWORD
Declare PtrSafe Function InternetSetOptionExW Lib "wininet" ( _
    ByVal hInternet As LongPtr, _
    ByVal dwOption As Long, _
    ByVal lpBuffer As LongPtr, _
    ByVal dwBufferLength As Long, _
    ByVal dwFlags 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

InternetSetOptionExW = ctypes.windll.wininet.InternetSetOptionExW
InternetSetOptionExW.restype = wintypes.BOOL
InternetSetOptionExW.argtypes = [
    ctypes.POINTER(None),  # hInternet : void* optional
    wintypes.DWORD,  # dwOption : DWORD
    ctypes.POINTER(None),  # lpBuffer : void* optional
    wintypes.DWORD,  # dwBufferLength : DWORD
    wintypes.DWORD,  # dwFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WININET.dll')
InternetSetOptionExW = Fiddle::Function.new(
  lib['InternetSetOptionExW'],
  [
    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,  # dwFlags : DWORD
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "wininet")]
extern "system" {
    fn InternetSetOptionExW(
        hInternet: *mut (),  // void* optional
        dwOption: u32,  // DWORD
        lpBuffer: *mut (),  // void* optional
        dwBufferLength: u32,  // DWORD
        dwFlags: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Unicode)]
public static extern bool InternetSetOptionExW(IntPtr hInternet, uint dwOption, IntPtr lpBuffer, uint dwBufferLength, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_InternetSetOptionExW' -Namespace Win32 -PassThru
# $api::InternetSetOptionExW(hInternet, dwOption, lpBuffer, dwBufferLength, dwFlags)
#uselib "WININET.dll"
#func global InternetSetOptionExW "InternetSetOptionExW" wptr, wptr, wptr, wptr, wptr
; InternetSetOptionExW hInternet, dwOption, lpBuffer, dwBufferLength, dwFlags   ; 戻り値は stat
; hInternet : void* optional -> "wptr"
; dwOption : DWORD -> "wptr"
; lpBuffer : void* optional -> "wptr"
; dwBufferLength : DWORD -> "wptr"
; dwFlags : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WININET.dll"
#cfunc global InternetSetOptionExW "InternetSetOptionExW" sptr, int, sptr, int, int
; res = InternetSetOptionExW(hInternet, dwOption, lpBuffer, dwBufferLength, dwFlags)
; hInternet : void* optional -> "sptr"
; dwOption : DWORD -> "int"
; lpBuffer : void* optional -> "sptr"
; dwBufferLength : DWORD -> "int"
; dwFlags : DWORD -> "int"
; BOOL InternetSetOptionExW(void* hInternet, DWORD dwOption, void* lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
#uselib "WININET.dll"
#cfunc global InternetSetOptionExW "InternetSetOptionExW" intptr, int, intptr, int, int
; res = InternetSetOptionExW(hInternet, dwOption, lpBuffer, dwBufferLength, dwFlags)
; hInternet : void* optional -> "intptr"
; dwOption : DWORD -> "int"
; lpBuffer : void* optional -> "intptr"
; dwBufferLength : DWORD -> "int"
; dwFlags : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wininet = windows.NewLazySystemDLL("WININET.dll")
	procInternetSetOptionExW = wininet.NewProc("InternetSetOptionExW")
)

// hInternet (void* optional), dwOption (DWORD), lpBuffer (void* optional), dwBufferLength (DWORD), dwFlags (DWORD)
r1, _, err := procInternetSetOptionExW.Call(
	uintptr(hInternet),
	uintptr(dwOption),
	uintptr(lpBuffer),
	uintptr(dwBufferLength),
	uintptr(dwFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function InternetSetOptionExW(
  hInternet: Pointer;   // void* optional
  dwOption: DWORD;   // DWORD
  lpBuffer: Pointer;   // void* optional
  dwBufferLength: DWORD;   // DWORD
  dwFlags: DWORD   // DWORD
): BOOL; stdcall;
  external 'WININET.dll' name 'InternetSetOptionExW';
result := DllCall("WININET\InternetSetOptionExW"
    , "Ptr", hInternet   ; void* optional
    , "UInt", dwOption   ; DWORD
    , "Ptr", lpBuffer   ; void* optional
    , "UInt", dwBufferLength   ; DWORD
    , "UInt", dwFlags   ; DWORD
    , "Int")   ; return: BOOL
●InternetSetOptionExW(hInternet, dwOption, lpBuffer, dwBufferLength, dwFlags) = DLL("WININET.dll", "bool InternetSetOptionExW(void*, dword, void*, dword, dword)")
# 呼び出し: InternetSetOptionExW(hInternet, dwOption, lpBuffer, dwBufferLength, dwFlags)
# hInternet : void* optional -> "void*"
# dwOption : DWORD -> "dword"
# lpBuffer : void* optional -> "void*"
# dwBufferLength : DWORD -> "dword"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "wininet" fn InternetSetOptionExW(
    hInternet: ?*anyopaque, // void* optional
    dwOption: u32, // DWORD
    lpBuffer: ?*anyopaque, // void* optional
    dwBufferLength: u32, // DWORD
    dwFlags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc InternetSetOptionExW(
    hInternet: pointer,  # void* optional
    dwOption: uint32,  # DWORD
    lpBuffer: pointer,  # void* optional
    dwBufferLength: uint32,  # DWORD
    dwFlags: uint32  # DWORD
): int32 {.importc: "InternetSetOptionExW", stdcall, dynlib: "WININET.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "wininet");
extern(Windows)
int InternetSetOptionExW(
    void* hInternet,   // void* optional
    uint dwOption,   // DWORD
    void* lpBuffer,   // void* optional
    uint dwBufferLength,   // DWORD
    uint dwFlags   // DWORD
);
ccall((:InternetSetOptionExW, "WININET.dll"), stdcall, Int32,
      (Ptr{Cvoid}, UInt32, Ptr{Cvoid}, UInt32, UInt32),
      hInternet, dwOption, lpBuffer, dwBufferLength, dwFlags)
# hInternet : void* optional -> Ptr{Cvoid}
# dwOption : DWORD -> UInt32
# lpBuffer : void* optional -> Ptr{Cvoid}
# dwBufferLength : DWORD -> UInt32
# dwFlags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t InternetSetOptionExW(
    void* hInternet,
    uint32_t dwOption,
    void* lpBuffer,
    uint32_t dwBufferLength,
    uint32_t dwFlags);
]]
local wininet = ffi.load("wininet")
-- wininet.InternetSetOptionExW(hInternet, dwOption, lpBuffer, dwBufferLength, dwFlags)
-- hInternet : void* optional
-- dwOption : DWORD
-- lpBuffer : void* optional
-- dwBufferLength : DWORD
-- dwFlags : DWORD
-- 構造体/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 InternetSetOptionExW = lib.func('__stdcall', 'InternetSetOptionExW', 'int32_t', ['void *', 'uint32_t', 'void *', 'uint32_t', 'uint32_t']);
// InternetSetOptionExW(hInternet, dwOption, lpBuffer, dwBufferLength, dwFlags)
// hInternet : void* optional -> 'void *'
// dwOption : DWORD -> 'uint32_t'
// lpBuffer : void* optional -> 'void *'
// dwBufferLength : DWORD -> 'uint32_t'
// dwFlags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WININET.dll", {
  InternetSetOptionExW: { parameters: ["pointer", "u32", "pointer", "u32", "u32"], result: "i32" },
});
// lib.symbols.InternetSetOptionExW(hInternet, dwOption, lpBuffer, dwBufferLength, dwFlags)
// hInternet : void* optional -> "pointer"
// dwOption : DWORD -> "u32"
// lpBuffer : void* optional -> "pointer"
// dwBufferLength : DWORD -> "u32"
// dwFlags : DWORD -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t InternetSetOptionExW(
    void* hInternet,
    uint32_t dwOption,
    void* lpBuffer,
    uint32_t dwBufferLength,
    uint32_t dwFlags);
C, "WININET.dll");
// $ffi->InternetSetOptionExW(hInternet, dwOption, lpBuffer, dwBufferLength, dwFlags);
// hInternet : void* optional
// dwOption : DWORD
// lpBuffer : void* optional
// dwBufferLength : DWORD
// dwFlags : DWORD
// 構造体/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 InternetSetOptionExW(
        Pointer hInternet,   // void* optional
        int dwOption,   // DWORD
        Pointer lpBuffer,   // void* optional
        int dwBufferLength,   // DWORD
        int dwFlags   // DWORD
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("wininet")]
lib LibWININET
  fun InternetSetOptionExW = InternetSetOptionExW(
    hInternet : Void*,   # void* optional
    dwOption : UInt32,   # DWORD
    lpBuffer : Void*,   # void* optional
    dwBufferLength : UInt32,   # DWORD
    dwFlags : UInt32   # DWORD
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef InternetSetOptionExWNative = Int32 Function(Pointer<Void>, Uint32, Pointer<Void>, Uint32, Uint32);
typedef InternetSetOptionExWDart = int Function(Pointer<Void>, int, Pointer<Void>, int, int);
final InternetSetOptionExW = DynamicLibrary.open('WININET.dll')
    .lookupFunction<InternetSetOptionExWNative, InternetSetOptionExWDart>('InternetSetOptionExW');
// hInternet : void* optional -> Pointer<Void>
// dwOption : DWORD -> Uint32
// lpBuffer : void* optional -> Pointer<Void>
// dwBufferLength : DWORD -> Uint32
// dwFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function InternetSetOptionExW(
  hInternet: Pointer;   // void* optional
  dwOption: DWORD;   // DWORD
  lpBuffer: Pointer;   // void* optional
  dwBufferLength: DWORD;   // DWORD
  dwFlags: DWORD   // DWORD
): BOOL; stdcall;
  external 'WININET.dll' name 'InternetSetOptionExW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let internetsetoptionexw =
  foreign "InternetSetOptionExW"
    ((ptr void) @-> uint32_t @-> (ptr void) @-> uint32_t @-> uint32_t @-> returning int32_t)
(* hInternet : void* optional -> (ptr void) *)
(* dwOption : DWORD -> uint32_t *)
(* lpBuffer : void* optional -> (ptr void) *)
(* dwBufferLength : DWORD -> uint32_t *)
(* dwFlags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library wininet (t "WININET.dll"))
(cffi:use-foreign-library wininet)

(cffi:defcfun ("InternetSetOptionExW" internet-set-option-ex-w :convention :stdcall) :int32
  (h-internet :pointer)   ; void* optional
  (dw-option :uint32)   ; DWORD
  (lp-buffer :pointer)   ; void* optional
  (dw-buffer-length :uint32)   ; DWORD
  (dw-flags :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $InternetSetOptionExW = Win32::API::More->new('WININET',
    'BOOL InternetSetOptionExW(LPVOID hInternet, DWORD dwOption, LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)');
# my $ret = $InternetSetOptionExW->Call($hInternet, $dwOption, $lpBuffer, $dwBufferLength, $dwFlags);
# hInternet : void* optional -> LPVOID
# dwOption : DWORD -> DWORD
# lpBuffer : void* optional -> LPVOID
# dwBufferLength : DWORD -> DWORD
# dwFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
類似 API