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

WinHttpWriteProxySettings

関数
WinHTTPのプロキシ設定を書き込んで保存する。
DLLWINHTTP.dll呼出規約winapi

シグネチャ

// WINHTTP.dll
#include <windows.h>

DWORD WinHttpWriteProxySettings(
    void* hSession,
    BOOL fForceUpdate,
    WINHTTP_PROXY_SETTINGS* pWinHttpProxySettings
);

パラメーター

名前方向説明
hSessionvoid*inWinHttpOpenで取得したセッションハンドル。プロキシ設定の書き込み対象。
fForceUpdateBOOLinTRUEならバージョン番号を更新して強制的に上書きする。FALSEで通常更新。
pWinHttpProxySettingsWINHTTP_PROXY_SETTINGS*in書き込むプロキシ設定を格納したWINHTTP_PROXY_SETTINGS構造体へのポインタ。

戻り値の型: DWORD

各言語での呼び出し定義

// WINHTTP.dll
#include <windows.h>

DWORD WinHttpWriteProxySettings(
    void* hSession,
    BOOL fForceUpdate,
    WINHTTP_PROXY_SETTINGS* pWinHttpProxySettings
);
[DllImport("WINHTTP.dll", ExactSpelling = true)]
static extern uint WinHttpWriteProxySettings(
    IntPtr hSession,   // void*
    bool fForceUpdate,   // BOOL
    IntPtr pWinHttpProxySettings   // WINHTTP_PROXY_SETTINGS*
);
<DllImport("WINHTTP.dll", ExactSpelling:=True)>
Public Shared Function WinHttpWriteProxySettings(
    hSession As IntPtr,   ' void*
    fForceUpdate As Boolean,   ' BOOL
    pWinHttpProxySettings As IntPtr   ' WINHTTP_PROXY_SETTINGS*
) As UInteger
End Function
' hSession : void*
' fForceUpdate : BOOL
' pWinHttpProxySettings : WINHTTP_PROXY_SETTINGS*
Declare PtrSafe Function WinHttpWriteProxySettings Lib "winhttp" ( _
    ByVal hSession As LongPtr, _
    ByVal fForceUpdate As Long, _
    ByVal pWinHttpProxySettings As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WinHttpWriteProxySettings = ctypes.windll.winhttp.WinHttpWriteProxySettings
WinHttpWriteProxySettings.restype = wintypes.DWORD
WinHttpWriteProxySettings.argtypes = [
    ctypes.POINTER(None),  # hSession : void*
    wintypes.BOOL,  # fForceUpdate : BOOL
    ctypes.c_void_p,  # pWinHttpProxySettings : WINHTTP_PROXY_SETTINGS*
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WINHTTP.dll')
WinHttpWriteProxySettings = Fiddle::Function.new(
  lib['WinHttpWriteProxySettings'],
  [
    Fiddle::TYPE_VOIDP,  # hSession : void*
    Fiddle::TYPE_INT,  # fForceUpdate : BOOL
    Fiddle::TYPE_VOIDP,  # pWinHttpProxySettings : WINHTTP_PROXY_SETTINGS*
  ],
  -Fiddle::TYPE_INT)
#[link(name = "winhttp")]
extern "system" {
    fn WinHttpWriteProxySettings(
        hSession: *mut (),  // void*
        fForceUpdate: i32,  // BOOL
        pWinHttpProxySettings: *mut WINHTTP_PROXY_SETTINGS  // WINHTTP_PROXY_SETTINGS*
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WINHTTP.dll")]
public static extern uint WinHttpWriteProxySettings(IntPtr hSession, bool fForceUpdate, IntPtr pWinHttpProxySettings);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WINHTTP_WinHttpWriteProxySettings' -Namespace Win32 -PassThru
# $api::WinHttpWriteProxySettings(hSession, fForceUpdate, pWinHttpProxySettings)
#uselib "WINHTTP.dll"
#func global WinHttpWriteProxySettings "WinHttpWriteProxySettings" sptr, sptr, sptr
; WinHttpWriteProxySettings hSession, fForceUpdate, varptr(pWinHttpProxySettings)   ; 戻り値は stat
; hSession : void* -> "sptr"
; fForceUpdate : BOOL -> "sptr"
; pWinHttpProxySettings : WINHTTP_PROXY_SETTINGS* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WINHTTP.dll"
#cfunc global WinHttpWriteProxySettings "WinHttpWriteProxySettings" sptr, int, var
; res = WinHttpWriteProxySettings(hSession, fForceUpdate, pWinHttpProxySettings)
; hSession : void* -> "sptr"
; fForceUpdate : BOOL -> "int"
; pWinHttpProxySettings : WINHTTP_PROXY_SETTINGS* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD WinHttpWriteProxySettings(void* hSession, BOOL fForceUpdate, WINHTTP_PROXY_SETTINGS* pWinHttpProxySettings)
#uselib "WINHTTP.dll"
#cfunc global WinHttpWriteProxySettings "WinHttpWriteProxySettings" intptr, int, var
; res = WinHttpWriteProxySettings(hSession, fForceUpdate, pWinHttpProxySettings)
; hSession : void* -> "intptr"
; fForceUpdate : BOOL -> "int"
; pWinHttpProxySettings : WINHTTP_PROXY_SETTINGS* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winhttp = windows.NewLazySystemDLL("WINHTTP.dll")
	procWinHttpWriteProxySettings = winhttp.NewProc("WinHttpWriteProxySettings")
)

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

extern "winhttp" fn WinHttpWriteProxySettings(
    hSession: ?*anyopaque, // void*
    fForceUpdate: i32, // BOOL
    pWinHttpProxySettings: [*c]WINHTTP_PROXY_SETTINGS // WINHTTP_PROXY_SETTINGS*
) callconv(std.os.windows.WINAPI) u32;
proc WinHttpWriteProxySettings(
    hSession: pointer,  # void*
    fForceUpdate: int32,  # BOOL
    pWinHttpProxySettings: ptr WINHTTP_PROXY_SETTINGS  # WINHTTP_PROXY_SETTINGS*
): uint32 {.importc: "WinHttpWriteProxySettings", stdcall, dynlib: "WINHTTP.dll".}
pragma(lib, "winhttp");
extern(Windows)
uint WinHttpWriteProxySettings(
    void* hSession,   // void*
    int fForceUpdate,   // BOOL
    WINHTTP_PROXY_SETTINGS* pWinHttpProxySettings   // WINHTTP_PROXY_SETTINGS*
);
ccall((:WinHttpWriteProxySettings, "WINHTTP.dll"), stdcall, UInt32,
      (Ptr{Cvoid}, Int32, Ptr{WINHTTP_PROXY_SETTINGS}),
      hSession, fForceUpdate, pWinHttpProxySettings)
# hSession : void* -> Ptr{Cvoid}
# fForceUpdate : BOOL -> Int32
# pWinHttpProxySettings : WINHTTP_PROXY_SETTINGS* -> Ptr{WINHTTP_PROXY_SETTINGS}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t WinHttpWriteProxySettings(
    void* hSession,
    int32_t fForceUpdate,
    void* pWinHttpProxySettings);
]]
local winhttp = ffi.load("winhttp")
-- winhttp.WinHttpWriteProxySettings(hSession, fForceUpdate, pWinHttpProxySettings)
-- hSession : void*
-- fForceUpdate : BOOL
-- pWinHttpProxySettings : WINHTTP_PROXY_SETTINGS*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('WINHTTP.dll');
const WinHttpWriteProxySettings = lib.func('__stdcall', 'WinHttpWriteProxySettings', 'uint32_t', ['void *', 'int32_t', 'void *']);
// WinHttpWriteProxySettings(hSession, fForceUpdate, pWinHttpProxySettings)
// hSession : void* -> 'void *'
// fForceUpdate : BOOL -> 'int32_t'
// pWinHttpProxySettings : WINHTTP_PROXY_SETTINGS* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WINHTTP.dll", {
  WinHttpWriteProxySettings: { parameters: ["pointer", "i32", "pointer"], result: "u32" },
});
// lib.symbols.WinHttpWriteProxySettings(hSession, fForceUpdate, pWinHttpProxySettings)
// hSession : void* -> "pointer"
// fForceUpdate : BOOL -> "i32"
// pWinHttpProxySettings : WINHTTP_PROXY_SETTINGS* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t WinHttpWriteProxySettings(
    void* hSession,
    int32_t fForceUpdate,
    void* pWinHttpProxySettings);
C, "WINHTTP.dll");
// $ffi->WinHttpWriteProxySettings(hSession, fForceUpdate, pWinHttpProxySettings);
// hSession : void*
// fForceUpdate : BOOL
// pWinHttpProxySettings : WINHTTP_PROXY_SETTINGS*
// 構造体/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 Winhttp extends StdCallLibrary {
    Winhttp INSTANCE = Native.load("winhttp", Winhttp.class);
    int WinHttpWriteProxySettings(
        Pointer hSession,   // void*
        boolean fForceUpdate,   // BOOL
        Pointer pWinHttpProxySettings   // WINHTTP_PROXY_SETTINGS*
    );
}
@[Link("winhttp")]
lib LibWINHTTP
  fun WinHttpWriteProxySettings = WinHttpWriteProxySettings(
    hSession : Void*,   # void*
    fForceUpdate : Int32,   # BOOL
    pWinHttpProxySettings : WINHTTP_PROXY_SETTINGS*   # WINHTTP_PROXY_SETTINGS*
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef WinHttpWriteProxySettingsNative = Uint32 Function(Pointer<Void>, Int32, Pointer<Void>);
typedef WinHttpWriteProxySettingsDart = int Function(Pointer<Void>, int, Pointer<Void>);
final WinHttpWriteProxySettings = DynamicLibrary.open('WINHTTP.dll')
    .lookupFunction<WinHttpWriteProxySettingsNative, WinHttpWriteProxySettingsDart>('WinHttpWriteProxySettings');
// hSession : void* -> Pointer<Void>
// fForceUpdate : BOOL -> Int32
// pWinHttpProxySettings : WINHTTP_PROXY_SETTINGS* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function WinHttpWriteProxySettings(
  hSession: Pointer;   // void*
  fForceUpdate: BOOL;   // BOOL
  pWinHttpProxySettings: Pointer   // WINHTTP_PROXY_SETTINGS*
): DWORD; stdcall;
  external 'WINHTTP.dll' name 'WinHttpWriteProxySettings';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "WinHttpWriteProxySettings"
  c_WinHttpWriteProxySettings :: Ptr () -> CInt -> Ptr () -> IO Word32
-- hSession : void* -> Ptr ()
-- fForceUpdate : BOOL -> CInt
-- pWinHttpProxySettings : WINHTTP_PROXY_SETTINGS* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let winhttpwriteproxysettings =
  foreign "WinHttpWriteProxySettings"
    ((ptr void) @-> int32_t @-> (ptr void) @-> returning uint32_t)
(* hSession : void* -> (ptr void) *)
(* fForceUpdate : BOOL -> int32_t *)
(* pWinHttpProxySettings : WINHTTP_PROXY_SETTINGS* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library winhttp (t "WINHTTP.dll"))
(cffi:use-foreign-library winhttp)

(cffi:defcfun ("WinHttpWriteProxySettings" win-http-write-proxy-settings :convention :stdcall) :uint32
  (h-session :pointer)   ; void*
  (f-force-update :int32)   ; BOOL
  (p-win-http-proxy-settings :pointer))   ; WINHTTP_PROXY_SETTINGS*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WinHttpWriteProxySettings = Win32::API::More->new('WINHTTP',
    'DWORD WinHttpWriteProxySettings(LPVOID hSession, BOOL fForceUpdate, LPVOID pWinHttpProxySettings)');
# my $ret = $WinHttpWriteProxySettings->Call($hSession, $fForceUpdate, $pWinHttpProxySettings);
# hSession : void* -> LPVOID
# fForceUpdate : BOOL -> BOOL
# pWinHttpProxySettings : WINHTTP_PROXY_SETTINGS* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型