ホーム › Networking.WinHttp › WinHttpGetProxyForUrl
WinHttpGetProxyForUrl
関数指定URLに使用すべきプロキシ情報を取得する。
シグネチャ
// WINHTTP.dll
#include <windows.h>
BOOL WinHttpGetProxyForUrl(
void* hSession,
LPCWSTR lpcwszUrl,
WINHTTP_AUTOPROXY_OPTIONS* pAutoProxyOptions,
WINHTTP_PROXY_INFO* pProxyInfo
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hSession | void* | inout |
| lpcwszUrl | LPCWSTR | in |
| pAutoProxyOptions | WINHTTP_AUTOPROXY_OPTIONS* | inout |
| pProxyInfo | WINHTTP_PROXY_INFO* | inout |
戻り値の型: BOOL
各言語での呼び出し定義
// WINHTTP.dll
#include <windows.h>
BOOL WinHttpGetProxyForUrl(
void* hSession,
LPCWSTR lpcwszUrl,
WINHTTP_AUTOPROXY_OPTIONS* pAutoProxyOptions,
WINHTTP_PROXY_INFO* pProxyInfo
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WINHTTP.dll", SetLastError = true, ExactSpelling = true)]
static extern bool WinHttpGetProxyForUrl(
IntPtr hSession, // void* in/out
[MarshalAs(UnmanagedType.LPWStr)] string lpcwszUrl, // LPCWSTR
IntPtr pAutoProxyOptions, // WINHTTP_AUTOPROXY_OPTIONS* in/out
IntPtr pProxyInfo // WINHTTP_PROXY_INFO* in/out
);<DllImport("WINHTTP.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WinHttpGetProxyForUrl(
hSession As IntPtr, ' void* in/out
<MarshalAs(UnmanagedType.LPWStr)> lpcwszUrl As String, ' LPCWSTR
pAutoProxyOptions As IntPtr, ' WINHTTP_AUTOPROXY_OPTIONS* in/out
pProxyInfo As IntPtr ' WINHTTP_PROXY_INFO* in/out
) As Boolean
End Function' hSession : void* in/out
' lpcwszUrl : LPCWSTR
' pAutoProxyOptions : WINHTTP_AUTOPROXY_OPTIONS* in/out
' pProxyInfo : WINHTTP_PROXY_INFO* in/out
Declare PtrSafe Function WinHttpGetProxyForUrl Lib "winhttp" ( _
ByVal hSession As LongPtr, _
ByVal lpcwszUrl As LongPtr, _
ByVal pAutoProxyOptions As LongPtr, _
ByVal pProxyInfo As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WinHttpGetProxyForUrl = ctypes.windll.winhttp.WinHttpGetProxyForUrl
WinHttpGetProxyForUrl.restype = wintypes.BOOL
WinHttpGetProxyForUrl.argtypes = [
ctypes.POINTER(None), # hSession : void* in/out
wintypes.LPCWSTR, # lpcwszUrl : LPCWSTR
ctypes.c_void_p, # pAutoProxyOptions : WINHTTP_AUTOPROXY_OPTIONS* in/out
ctypes.c_void_p, # pProxyInfo : WINHTTP_PROXY_INFO* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WINHTTP.dll')
WinHttpGetProxyForUrl = Fiddle::Function.new(
lib['WinHttpGetProxyForUrl'],
[
Fiddle::TYPE_VOIDP, # hSession : void* in/out
Fiddle::TYPE_VOIDP, # lpcwszUrl : LPCWSTR
Fiddle::TYPE_VOIDP, # pAutoProxyOptions : WINHTTP_AUTOPROXY_OPTIONS* in/out
Fiddle::TYPE_VOIDP, # pProxyInfo : WINHTTP_PROXY_INFO* in/out
],
Fiddle::TYPE_INT)#[link(name = "winhttp")]
extern "system" {
fn WinHttpGetProxyForUrl(
hSession: *mut (), // void* in/out
lpcwszUrl: *const u16, // LPCWSTR
pAutoProxyOptions: *mut WINHTTP_AUTOPROXY_OPTIONS, // WINHTTP_AUTOPROXY_OPTIONS* in/out
pProxyInfo: *mut WINHTTP_PROXY_INFO // WINHTTP_PROXY_INFO* in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WINHTTP.dll", SetLastError = true)]
public static extern bool WinHttpGetProxyForUrl(IntPtr hSession, [MarshalAs(UnmanagedType.LPWStr)] string lpcwszUrl, IntPtr pAutoProxyOptions, IntPtr pProxyInfo);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WINHTTP_WinHttpGetProxyForUrl' -Namespace Win32 -PassThru
# $api::WinHttpGetProxyForUrl(hSession, lpcwszUrl, pAutoProxyOptions, pProxyInfo)#uselib "WINHTTP.dll"
#func global WinHttpGetProxyForUrl "WinHttpGetProxyForUrl" sptr, sptr, sptr, sptr
; WinHttpGetProxyForUrl hSession, lpcwszUrl, varptr(pAutoProxyOptions), varptr(pProxyInfo) ; 戻り値は stat
; hSession : void* in/out -> "sptr"
; lpcwszUrl : LPCWSTR -> "sptr"
; pAutoProxyOptions : WINHTTP_AUTOPROXY_OPTIONS* in/out -> "sptr"
; pProxyInfo : WINHTTP_PROXY_INFO* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "WINHTTP.dll" #cfunc global WinHttpGetProxyForUrl "WinHttpGetProxyForUrl" sptr, wstr, var, var ; res = WinHttpGetProxyForUrl(hSession, lpcwszUrl, pAutoProxyOptions, pProxyInfo) ; hSession : void* in/out -> "sptr" ; lpcwszUrl : LPCWSTR -> "wstr" ; pAutoProxyOptions : WINHTTP_AUTOPROXY_OPTIONS* in/out -> "var" ; pProxyInfo : WINHTTP_PROXY_INFO* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WINHTTP.dll" #cfunc global WinHttpGetProxyForUrl "WinHttpGetProxyForUrl" sptr, wstr, sptr, sptr ; res = WinHttpGetProxyForUrl(hSession, lpcwszUrl, varptr(pAutoProxyOptions), varptr(pProxyInfo)) ; hSession : void* in/out -> "sptr" ; lpcwszUrl : LPCWSTR -> "wstr" ; pAutoProxyOptions : WINHTTP_AUTOPROXY_OPTIONS* in/out -> "sptr" ; pProxyInfo : WINHTTP_PROXY_INFO* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL WinHttpGetProxyForUrl(void* hSession, LPCWSTR lpcwszUrl, WINHTTP_AUTOPROXY_OPTIONS* pAutoProxyOptions, WINHTTP_PROXY_INFO* pProxyInfo) #uselib "WINHTTP.dll" #cfunc global WinHttpGetProxyForUrl "WinHttpGetProxyForUrl" intptr, wstr, var, var ; res = WinHttpGetProxyForUrl(hSession, lpcwszUrl, pAutoProxyOptions, pProxyInfo) ; hSession : void* in/out -> "intptr" ; lpcwszUrl : LPCWSTR -> "wstr" ; pAutoProxyOptions : WINHTTP_AUTOPROXY_OPTIONS* in/out -> "var" ; pProxyInfo : WINHTTP_PROXY_INFO* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL WinHttpGetProxyForUrl(void* hSession, LPCWSTR lpcwszUrl, WINHTTP_AUTOPROXY_OPTIONS* pAutoProxyOptions, WINHTTP_PROXY_INFO* pProxyInfo) #uselib "WINHTTP.dll" #cfunc global WinHttpGetProxyForUrl "WinHttpGetProxyForUrl" intptr, wstr, intptr, intptr ; res = WinHttpGetProxyForUrl(hSession, lpcwszUrl, varptr(pAutoProxyOptions), varptr(pProxyInfo)) ; hSession : void* in/out -> "intptr" ; lpcwszUrl : LPCWSTR -> "wstr" ; pAutoProxyOptions : WINHTTP_AUTOPROXY_OPTIONS* in/out -> "intptr" ; pProxyInfo : WINHTTP_PROXY_INFO* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
winhttp = windows.NewLazySystemDLL("WINHTTP.dll")
procWinHttpGetProxyForUrl = winhttp.NewProc("WinHttpGetProxyForUrl")
)
// hSession (void* in/out), lpcwszUrl (LPCWSTR), pAutoProxyOptions (WINHTTP_AUTOPROXY_OPTIONS* in/out), pProxyInfo (WINHTTP_PROXY_INFO* in/out)
r1, _, err := procWinHttpGetProxyForUrl.Call(
uintptr(hSession),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpcwszUrl))),
uintptr(pAutoProxyOptions),
uintptr(pProxyInfo),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction WinHttpGetProxyForUrl(
hSession: Pointer; // void* in/out
lpcwszUrl: PWideChar; // LPCWSTR
pAutoProxyOptions: Pointer; // WINHTTP_AUTOPROXY_OPTIONS* in/out
pProxyInfo: Pointer // WINHTTP_PROXY_INFO* in/out
): BOOL; stdcall;
external 'WINHTTP.dll' name 'WinHttpGetProxyForUrl';result := DllCall("WINHTTP\WinHttpGetProxyForUrl"
, "Ptr", hSession ; void* in/out
, "WStr", lpcwszUrl ; LPCWSTR
, "Ptr", pAutoProxyOptions ; WINHTTP_AUTOPROXY_OPTIONS* in/out
, "Ptr", pProxyInfo ; WINHTTP_PROXY_INFO* in/out
, "Int") ; return: BOOL●WinHttpGetProxyForUrl(hSession, lpcwszUrl, pAutoProxyOptions, pProxyInfo) = DLL("WINHTTP.dll", "bool WinHttpGetProxyForUrl(void*, char*, void*, void*)")
# 呼び出し: WinHttpGetProxyForUrl(hSession, lpcwszUrl, pAutoProxyOptions, pProxyInfo)
# hSession : void* in/out -> "void*"
# lpcwszUrl : LPCWSTR -> "char*"
# pAutoProxyOptions : WINHTTP_AUTOPROXY_OPTIONS* in/out -> "void*"
# pProxyInfo : WINHTTP_PROXY_INFO* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。