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

HttpOpenRequestW

関数
HTTPリクエストハンドルを作成する(Unicode版)。
DLLWININET.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

void* HttpOpenRequestW(
    void* hConnect,
    LPCWSTR lpszVerb,   // optional
    LPCWSTR lpszObjectName,   // optional
    LPCWSTR lpszVersion,   // optional
    LPCWSTR lpszReferrer,   // optional
    LPCWSTR* lplpszAcceptTypes,   // optional
    DWORD dwFlags,
    UINT_PTR dwContext   // optional
);

パラメーター

名前方向
hConnectvoid*in
lpszVerbLPCWSTRinoptional
lpszObjectNameLPCWSTRinoptional
lpszVersionLPCWSTRinoptional
lpszReferrerLPCWSTRinoptional
lplpszAcceptTypesLPCWSTR*inoptional
dwFlagsDWORDin
dwContextUINT_PTRinoptional

戻り値の型: void*

各言語での呼び出し定義

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

void* HttpOpenRequestW(
    void* hConnect,
    LPCWSTR lpszVerb,   // optional
    LPCWSTR lpszObjectName,   // optional
    LPCWSTR lpszVersion,   // optional
    LPCWSTR lpszReferrer,   // optional
    LPCWSTR* lplpszAcceptTypes,   // optional
    DWORD dwFlags,
    UINT_PTR dwContext   // optional
);
[DllImport("WININET.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr HttpOpenRequestW(
    IntPtr hConnect,   // void*
    [MarshalAs(UnmanagedType.LPWStr)] string lpszVerb,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string lpszObjectName,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string lpszVersion,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string lpszReferrer,   // LPCWSTR optional
    IntPtr lplpszAcceptTypes,   // LPCWSTR* optional
    uint dwFlags,   // DWORD
    UIntPtr dwContext   // UINT_PTR optional
);
<DllImport("WININET.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function HttpOpenRequestW(
    hConnect As IntPtr,   ' void*
    <MarshalAs(UnmanagedType.LPWStr)> lpszVerb As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> lpszObjectName As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> lpszVersion As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> lpszReferrer As String,   ' LPCWSTR optional
    lplpszAcceptTypes As IntPtr,   ' LPCWSTR* optional
    dwFlags As UInteger,   ' DWORD
    dwContext As UIntPtr   ' UINT_PTR optional
) As IntPtr
End Function
' hConnect : void*
' lpszVerb : LPCWSTR optional
' lpszObjectName : LPCWSTR optional
' lpszVersion : LPCWSTR optional
' lpszReferrer : LPCWSTR optional
' lplpszAcceptTypes : LPCWSTR* optional
' dwFlags : DWORD
' dwContext : UINT_PTR optional
Declare PtrSafe Function HttpOpenRequestW Lib "wininet" ( _
    ByVal hConnect As LongPtr, _
    ByVal lpszVerb As LongPtr, _
    ByVal lpszObjectName As LongPtr, _
    ByVal lpszVersion As LongPtr, _
    ByVal lpszReferrer As LongPtr, _
    ByVal lplpszAcceptTypes As LongPtr, _
    ByVal dwFlags As Long, _
    ByVal dwContext As LongPtr) As LongPtr
' 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

HttpOpenRequestW = ctypes.windll.wininet.HttpOpenRequestW
HttpOpenRequestW.restype = ctypes.c_void_p
HttpOpenRequestW.argtypes = [
    ctypes.POINTER(None),  # hConnect : void*
    wintypes.LPCWSTR,  # lpszVerb : LPCWSTR optional
    wintypes.LPCWSTR,  # lpszObjectName : LPCWSTR optional
    wintypes.LPCWSTR,  # lpszVersion : LPCWSTR optional
    wintypes.LPCWSTR,  # lpszReferrer : LPCWSTR optional
    ctypes.c_void_p,  # lplpszAcceptTypes : LPCWSTR* optional
    wintypes.DWORD,  # dwFlags : DWORD
    ctypes.c_size_t,  # dwContext : UINT_PTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WININET.dll')
HttpOpenRequestW = Fiddle::Function.new(
  lib['HttpOpenRequestW'],
  [
    Fiddle::TYPE_VOIDP,  # hConnect : void*
    Fiddle::TYPE_VOIDP,  # lpszVerb : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # lpszObjectName : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # lpszVersion : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # lpszReferrer : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # lplpszAcceptTypes : LPCWSTR* optional
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
    Fiddle::TYPE_UINTPTR_T,  # dwContext : UINT_PTR optional
  ],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "wininet")]
extern "system" {
    fn HttpOpenRequestW(
        hConnect: *mut (),  // void*
        lpszVerb: *const u16,  // LPCWSTR optional
        lpszObjectName: *const u16,  // LPCWSTR optional
        lpszVersion: *const u16,  // LPCWSTR optional
        lpszReferrer: *const u16,  // LPCWSTR optional
        lplpszAcceptTypes: *const *const u16,  // LPCWSTR* optional
        dwFlags: u32,  // DWORD
        dwContext: usize  // UINT_PTR optional
    ) -> *mut ();
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WININET.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr HttpOpenRequestW(IntPtr hConnect, [MarshalAs(UnmanagedType.LPWStr)] string lpszVerb, [MarshalAs(UnmanagedType.LPWStr)] string lpszObjectName, [MarshalAs(UnmanagedType.LPWStr)] string lpszVersion, [MarshalAs(UnmanagedType.LPWStr)] string lpszReferrer, IntPtr lplpszAcceptTypes, uint dwFlags, UIntPtr dwContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_HttpOpenRequestW' -Namespace Win32 -PassThru
# $api::HttpOpenRequestW(hConnect, lpszVerb, lpszObjectName, lpszVersion, lpszReferrer, lplpszAcceptTypes, dwFlags, dwContext)
#uselib "WININET.dll"
#func global HttpOpenRequestW "HttpOpenRequestW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; HttpOpenRequestW hConnect, lpszVerb, lpszObjectName, lpszVersion, lpszReferrer, varptr(lplpszAcceptTypes), dwFlags, dwContext   ; 戻り値は stat
; hConnect : void* -> "wptr"
; lpszVerb : LPCWSTR optional -> "wptr"
; lpszObjectName : LPCWSTR optional -> "wptr"
; lpszVersion : LPCWSTR optional -> "wptr"
; lpszReferrer : LPCWSTR optional -> "wptr"
; lplpszAcceptTypes : LPCWSTR* optional -> "wptr"
; dwFlags : DWORD -> "wptr"
; dwContext : UINT_PTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WININET.dll"
#cfunc global HttpOpenRequestW "HttpOpenRequestW" sptr, wstr, wstr, wstr, wstr, var, int, sptr
; res = HttpOpenRequestW(hConnect, lpszVerb, lpszObjectName, lpszVersion, lpszReferrer, lplpszAcceptTypes, dwFlags, dwContext)
; hConnect : void* -> "sptr"
; lpszVerb : LPCWSTR optional -> "wstr"
; lpszObjectName : LPCWSTR optional -> "wstr"
; lpszVersion : LPCWSTR optional -> "wstr"
; lpszReferrer : LPCWSTR optional -> "wstr"
; lplpszAcceptTypes : LPCWSTR* optional -> "var"
; dwFlags : DWORD -> "int"
; dwContext : UINT_PTR optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; void* HttpOpenRequestW(void* hConnect, LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion, LPCWSTR lpszReferrer, LPCWSTR* lplpszAcceptTypes, DWORD dwFlags, UINT_PTR dwContext)
#uselib "WININET.dll"
#cfunc global HttpOpenRequestW "HttpOpenRequestW" intptr, wstr, wstr, wstr, wstr, var, int, intptr
; res = HttpOpenRequestW(hConnect, lpszVerb, lpszObjectName, lpszVersion, lpszReferrer, lplpszAcceptTypes, dwFlags, dwContext)
; hConnect : void* -> "intptr"
; lpszVerb : LPCWSTR optional -> "wstr"
; lpszObjectName : LPCWSTR optional -> "wstr"
; lpszVersion : LPCWSTR optional -> "wstr"
; lpszReferrer : LPCWSTR optional -> "wstr"
; lplpszAcceptTypes : LPCWSTR* optional -> "var"
; dwFlags : DWORD -> "int"
; dwContext : UINT_PTR optional -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wininet = windows.NewLazySystemDLL("WININET.dll")
	procHttpOpenRequestW = wininet.NewProc("HttpOpenRequestW")
)

// hConnect (void*), lpszVerb (LPCWSTR optional), lpszObjectName (LPCWSTR optional), lpszVersion (LPCWSTR optional), lpszReferrer (LPCWSTR optional), lplpszAcceptTypes (LPCWSTR* optional), dwFlags (DWORD), dwContext (UINT_PTR optional)
r1, _, err := procHttpOpenRequestW.Call(
	uintptr(hConnect),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszVerb))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszObjectName))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszVersion))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszReferrer))),
	uintptr(lplpszAcceptTypes),
	uintptr(dwFlags),
	uintptr(dwContext),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // void*
function HttpOpenRequestW(
  hConnect: Pointer;   // void*
  lpszVerb: PWideChar;   // LPCWSTR optional
  lpszObjectName: PWideChar;   // LPCWSTR optional
  lpszVersion: PWideChar;   // LPCWSTR optional
  lpszReferrer: PWideChar;   // LPCWSTR optional
  lplpszAcceptTypes: PPWideChar;   // LPCWSTR* optional
  dwFlags: DWORD;   // DWORD
  dwContext: NativeUInt   // UINT_PTR optional
): Pointer; stdcall;
  external 'WININET.dll' name 'HttpOpenRequestW';
result := DllCall("WININET\HttpOpenRequestW"
    , "Ptr", hConnect   ; void*
    , "WStr", lpszVerb   ; LPCWSTR optional
    , "WStr", lpszObjectName   ; LPCWSTR optional
    , "WStr", lpszVersion   ; LPCWSTR optional
    , "WStr", lpszReferrer   ; LPCWSTR optional
    , "Ptr", lplpszAcceptTypes   ; LPCWSTR* optional
    , "UInt", dwFlags   ; DWORD
    , "UPtr", dwContext   ; UINT_PTR optional
    , "Ptr")   ; return: void*
●HttpOpenRequestW(hConnect, lpszVerb, lpszObjectName, lpszVersion, lpszReferrer, lplpszAcceptTypes, dwFlags, dwContext) = DLL("WININET.dll", "void* HttpOpenRequestW(void*, char*, char*, char*, char*, void*, dword, int)")
# 呼び出し: HttpOpenRequestW(hConnect, lpszVerb, lpszObjectName, lpszVersion, lpszReferrer, lplpszAcceptTypes, dwFlags, dwContext)
# hConnect : void* -> "void*"
# lpszVerb : LPCWSTR optional -> "char*"
# lpszObjectName : LPCWSTR optional -> "char*"
# lpszVersion : LPCWSTR optional -> "char*"
# lpszReferrer : LPCWSTR optional -> "char*"
# lplpszAcceptTypes : LPCWSTR* optional -> "void*"
# dwFlags : DWORD -> "dword"
# dwContext : UINT_PTR optional -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。