ホーム › Networking.WinInet › InternetSetOptionA
InternetSetOptionA
関数WinINetハンドルの指定したオプション値を設定する(ANSI)。
シグネチャ
// WININET.dll (ANSI / -A)
#include <windows.h>
BOOL InternetSetOptionA(
void* hInternet, // optional
DWORD dwOption,
void* lpBuffer, // optional
DWORD dwBufferLength
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hInternet | void* | inoptional | 情報を設定する対象のハンドル。 |
| dwOption | DWORD | in | 設定するインターネットオプション。 Option Flags の値のいずれかを指定できます。 |
| lpBuffer | void* | inoptional | オプション設定を格納したバッファーへのポインター。 |
| dwBufferLength | DWORD | in | lpBuffer バッファーのサイズ。 lpBuffer が文字列を格納している場合、 サイズは TCHAR 単位です。 lpBuffer が文字列以外を格納している場合、 サイズはバイト単位です。 |
戻り値の型: BOOL
公式ドキュメント
インターネットオプションを設定します。(ANSI)
戻り値
成功した場合は TRUE を、それ以外の場合は FALSE を返します。具体的なエラーメッセージを取得するには、 GetLastError を呼び出してください。
解説(Remarks)
設定できないオプションフラグが指定された場合、GetLastError はエラー ERROR_INVALID_PARAMETER を返します。
詳細については、 Setting and Retrieving Internet Options を参照してください。
WinINet API の他のすべての側面と同様に、この関数は DllMain やグローバルオブジェクトのコンストラクター・デストラクター内から安全に呼び出すことはできません。
注意 WinINet はサーバー実装をサポートしていません。さらに、サービスから使用すべきではありません。サーバー実装やサービスでは、Microsoft Windows HTTP Services (WinHTTP) を使用してください。
メモ
wininet.h ヘッダーは InternetSetOption を、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)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// WININET.dll (ANSI / -A)
#include <windows.h>
BOOL InternetSetOptionA(
void* hInternet, // optional
DWORD dwOption,
void* lpBuffer, // optional
DWORD dwBufferLength
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool InternetSetOptionA(
IntPtr hInternet, // void* optional
uint dwOption, // DWORD
IntPtr lpBuffer, // void* optional
uint dwBufferLength // DWORD
);<DllImport("WININET.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function InternetSetOptionA(
hInternet As IntPtr, ' void* optional
dwOption As UInteger, ' DWORD
lpBuffer As IntPtr, ' void* optional
dwBufferLength As UInteger ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hInternet : void* optional
' dwOption : DWORD
' lpBuffer : void* optional
' dwBufferLength : DWORD
Declare PtrSafe Function InternetSetOptionA Lib "wininet" ( _
ByVal hInternet As LongPtr, _
ByVal dwOption As Long, _
ByVal lpBuffer As LongPtr, _
ByVal dwBufferLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
InternetSetOptionA = ctypes.windll.wininet.InternetSetOptionA
InternetSetOptionA.restype = wintypes.BOOL
InternetSetOptionA.argtypes = [
ctypes.POINTER(None), # hInternet : void* optional
wintypes.DWORD, # dwOption : DWORD
ctypes.POINTER(None), # lpBuffer : void* optional
wintypes.DWORD, # dwBufferLength : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WININET.dll')
InternetSetOptionA = Fiddle::Function.new(
lib['InternetSetOptionA'],
[
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)#[link(name = "wininet")]
extern "system" {
fn InternetSetOptionA(
hInternet: *mut (), // void* optional
dwOption: u32, // DWORD
lpBuffer: *mut (), // void* optional
dwBufferLength: u32 // DWORD
) -> 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 InternetSetOptionA(IntPtr hInternet, uint dwOption, IntPtr lpBuffer, uint dwBufferLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_InternetSetOptionA' -Namespace Win32 -PassThru
# $api::InternetSetOptionA(hInternet, dwOption, lpBuffer, dwBufferLength)#uselib "WININET.dll"
#func global InternetSetOptionA "InternetSetOptionA" sptr, sptr, sptr, sptr
; InternetSetOptionA hInternet, dwOption, lpBuffer, dwBufferLength ; 戻り値は stat
; hInternet : void* optional -> "sptr"
; dwOption : DWORD -> "sptr"
; lpBuffer : void* optional -> "sptr"
; dwBufferLength : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WININET.dll"
#cfunc global InternetSetOptionA "InternetSetOptionA" sptr, int, sptr, int
; res = InternetSetOptionA(hInternet, dwOption, lpBuffer, dwBufferLength)
; hInternet : void* optional -> "sptr"
; dwOption : DWORD -> "int"
; lpBuffer : void* optional -> "sptr"
; dwBufferLength : DWORD -> "int"; BOOL InternetSetOptionA(void* hInternet, DWORD dwOption, void* lpBuffer, DWORD dwBufferLength)
#uselib "WININET.dll"
#cfunc global InternetSetOptionA "InternetSetOptionA" intptr, int, intptr, int
; res = InternetSetOptionA(hInternet, dwOption, lpBuffer, dwBufferLength)
; hInternet : void* optional -> "intptr"
; dwOption : DWORD -> "int"
; lpBuffer : void* optional -> "intptr"
; dwBufferLength : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wininet = windows.NewLazySystemDLL("WININET.dll")
procInternetSetOptionA = wininet.NewProc("InternetSetOptionA")
)
// hInternet (void* optional), dwOption (DWORD), lpBuffer (void* optional), dwBufferLength (DWORD)
r1, _, err := procInternetSetOptionA.Call(
uintptr(hInternet),
uintptr(dwOption),
uintptr(lpBuffer),
uintptr(dwBufferLength),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction InternetSetOptionA(
hInternet: Pointer; // void* optional
dwOption: DWORD; // DWORD
lpBuffer: Pointer; // void* optional
dwBufferLength: DWORD // DWORD
): BOOL; stdcall;
external 'WININET.dll' name 'InternetSetOptionA';result := DllCall("WININET\InternetSetOptionA"
, "Ptr", hInternet ; void* optional
, "UInt", dwOption ; DWORD
, "Ptr", lpBuffer ; void* optional
, "UInt", dwBufferLength ; DWORD
, "Int") ; return: BOOL●InternetSetOptionA(hInternet, dwOption, lpBuffer, dwBufferLength) = DLL("WININET.dll", "bool InternetSetOptionA(void*, dword, void*, dword)")
# 呼び出し: InternetSetOptionA(hInternet, dwOption, lpBuffer, dwBufferLength)
# hInternet : void* optional -> "void*"
# dwOption : DWORD -> "dword"
# lpBuffer : void* optional -> "void*"
# dwBufferLength : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "wininet" fn InternetSetOptionA(
hInternet: ?*anyopaque, // void* optional
dwOption: u32, // DWORD
lpBuffer: ?*anyopaque, // void* optional
dwBufferLength: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc InternetSetOptionA(
hInternet: pointer, # void* optional
dwOption: uint32, # DWORD
lpBuffer: pointer, # void* optional
dwBufferLength: uint32 # DWORD
): int32 {.importc: "InternetSetOptionA", stdcall, dynlib: "WININET.dll".}pragma(lib, "wininet");
extern(Windows)
int InternetSetOptionA(
void* hInternet, // void* optional
uint dwOption, // DWORD
void* lpBuffer, // void* optional
uint dwBufferLength // DWORD
);ccall((:InternetSetOptionA, "WININET.dll"), stdcall, Int32,
(Ptr{Cvoid}, UInt32, Ptr{Cvoid}, UInt32),
hInternet, dwOption, lpBuffer, dwBufferLength)
# hInternet : void* optional -> Ptr{Cvoid}
# dwOption : DWORD -> UInt32
# lpBuffer : void* optional -> Ptr{Cvoid}
# dwBufferLength : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t InternetSetOptionA(
void* hInternet,
uint32_t dwOption,
void* lpBuffer,
uint32_t dwBufferLength);
]]
local wininet = ffi.load("wininet")
-- wininet.InternetSetOptionA(hInternet, dwOption, lpBuffer, dwBufferLength)
-- hInternet : void* optional
-- dwOption : DWORD
-- lpBuffer : void* optional
-- dwBufferLength : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WININET.dll');
const InternetSetOptionA = lib.func('__stdcall', 'InternetSetOptionA', 'int32_t', ['void *', 'uint32_t', 'void *', 'uint32_t']);
// InternetSetOptionA(hInternet, dwOption, lpBuffer, dwBufferLength)
// hInternet : void* optional -> 'void *'
// dwOption : DWORD -> 'uint32_t'
// lpBuffer : void* optional -> 'void *'
// dwBufferLength : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WININET.dll", {
InternetSetOptionA: { parameters: ["pointer", "u32", "pointer", "u32"], result: "i32" },
});
// lib.symbols.InternetSetOptionA(hInternet, dwOption, lpBuffer, dwBufferLength)
// hInternet : void* optional -> "pointer"
// dwOption : DWORD -> "u32"
// lpBuffer : void* optional -> "pointer"
// dwBufferLength : DWORD -> "u32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t InternetSetOptionA(
void* hInternet,
uint32_t dwOption,
void* lpBuffer,
uint32_t dwBufferLength);
C, "WININET.dll");
// $ffi->InternetSetOptionA(hInternet, dwOption, lpBuffer, dwBufferLength);
// hInternet : void* optional
// dwOption : DWORD
// lpBuffer : void* optional
// dwBufferLength : 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.ASCII_OPTIONS);
boolean InternetSetOptionA(
Pointer hInternet, // void* optional
int dwOption, // DWORD
Pointer lpBuffer, // void* optional
int dwBufferLength // DWORD
);
}@[Link("wininet")]
lib LibWININET
fun InternetSetOptionA = InternetSetOptionA(
hInternet : Void*, # void* optional
dwOption : UInt32, # DWORD
lpBuffer : Void*, # void* optional
dwBufferLength : 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 InternetSetOptionANative = Int32 Function(Pointer<Void>, Uint32, Pointer<Void>, Uint32);
typedef InternetSetOptionADart = int Function(Pointer<Void>, int, Pointer<Void>, int);
final InternetSetOptionA = DynamicLibrary.open('WININET.dll')
.lookupFunction<InternetSetOptionANative, InternetSetOptionADart>('InternetSetOptionA');
// hInternet : void* optional -> Pointer<Void>
// dwOption : DWORD -> Uint32
// lpBuffer : void* optional -> Pointer<Void>
// dwBufferLength : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function InternetSetOptionA(
hInternet: Pointer; // void* optional
dwOption: DWORD; // DWORD
lpBuffer: Pointer; // void* optional
dwBufferLength: DWORD // DWORD
): BOOL; stdcall;
external 'WININET.dll' name 'InternetSetOptionA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "InternetSetOptionA"
c_InternetSetOptionA :: Ptr () -> Word32 -> Ptr () -> Word32 -> IO CInt
-- hInternet : void* optional -> Ptr ()
-- dwOption : DWORD -> Word32
-- lpBuffer : void* optional -> Ptr ()
-- dwBufferLength : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let internetsetoptiona =
foreign "InternetSetOptionA"
((ptr void) @-> uint32_t @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* hInternet : void* optional -> (ptr void) *)
(* dwOption : DWORD -> uint32_t *)
(* lpBuffer : void* optional -> (ptr void) *)
(* dwBufferLength : 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 ("InternetSetOptionA" internet-set-option-a :convention :stdcall) :int32
(h-internet :pointer) ; void* optional
(dw-option :uint32) ; DWORD
(lp-buffer :pointer) ; void* optional
(dw-buffer-length :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $InternetSetOptionA = Win32::API::More->new('WININET',
'BOOL InternetSetOptionA(LPVOID hInternet, DWORD dwOption, LPVOID lpBuffer, DWORD dwBufferLength)');
# my $ret = $InternetSetOptionA->Call($hInternet, $dwOption, $lpBuffer, $dwBufferLength);
# hInternet : void* optional -> LPVOID
# dwOption : DWORD -> DWORD
# lpBuffer : void* optional -> LPVOID
# dwBufferLength : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f InternetSetOptionW (Unicode版) — WinINetハンドルの指定したオプション値を設定する(Unicode)。
類似 API
- f InternetSetOptionExA — WinINetハンドルのオプション値を拡張フラグ付きで設定する(ANSI)。
公式の関連項目
- f FtpGetFileA — FTPサーバーからファイルをローカルに取得して保存する(ANSI版)。
- f FtpPutFileA — ローカルファイルをFTPサーバーへアップロードする(ANSI版)。
- f InternetConnectA — 指定サーバーへの接続を確立し接続ハンドルを返す(ANSI)。
- f InternetOpenA — WinINetを初期化しセッションハンドルを返す(ANSI)。
- f InternetQueryOptionA — WinINetハンドルの指定したオプション値を取得する(ANSI)。