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

HttpOpenRequestA

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

シグネチャ

// WININET.dll  (ANSI / -A)
#include <windows.h>

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

パラメーター

名前方向
hConnectvoid*in
lpszVerbLPCSTRinoptional
lpszObjectNameLPCSTRinoptional
lpszVersionLPCSTRinoptional
lpszReferrerLPCSTRinoptional
lplpszAcceptTypesLPCSTR*inoptional
dwFlagsDWORDin
dwContextUINT_PTRinoptional

戻り値の型: void*

各言語での呼び出し定義

// WININET.dll  (ANSI / -A)
#include <windows.h>

void* HttpOpenRequestA(
    void* hConnect,
    LPCSTR lpszVerb,   // optional
    LPCSTR lpszObjectName,   // optional
    LPCSTR lpszVersion,   // optional
    LPCSTR lpszReferrer,   // optional
    LPCSTR* lplpszAcceptTypes,   // optional
    DWORD dwFlags,
    UINT_PTR dwContext   // optional
);
[DllImport("WININET.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern IntPtr HttpOpenRequestA(
    IntPtr hConnect,   // void*
    [MarshalAs(UnmanagedType.LPStr)] string lpszVerb,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string lpszObjectName,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string lpszVersion,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string lpszReferrer,   // LPCSTR optional
    IntPtr lplpszAcceptTypes,   // LPCSTR* optional
    uint dwFlags,   // DWORD
    UIntPtr dwContext   // UINT_PTR optional
);
<DllImport("WININET.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function HttpOpenRequestA(
    hConnect As IntPtr,   ' void*
    <MarshalAs(UnmanagedType.LPStr)> lpszVerb As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> lpszObjectName As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> lpszVersion As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> lpszReferrer As String,   ' LPCSTR optional
    lplpszAcceptTypes As IntPtr,   ' LPCSTR* optional
    dwFlags As UInteger,   ' DWORD
    dwContext As UIntPtr   ' UINT_PTR optional
) As IntPtr
End Function
' hConnect : void*
' lpszVerb : LPCSTR optional
' lpszObjectName : LPCSTR optional
' lpszVersion : LPCSTR optional
' lpszReferrer : LPCSTR optional
' lplpszAcceptTypes : LPCSTR* optional
' dwFlags : DWORD
' dwContext : UINT_PTR optional
Declare PtrSafe Function HttpOpenRequestA Lib "wininet" ( _
    ByVal hConnect As LongPtr, _
    ByVal lpszVerb As String, _
    ByVal lpszObjectName As String, _
    ByVal lpszVersion As String, _
    ByVal lpszReferrer As String, _
    ByVal lplpszAcceptTypes As LongPtr, _
    ByVal dwFlags As Long, _
    ByVal dwContext As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

HttpOpenRequestA = ctypes.windll.wininet.HttpOpenRequestA
HttpOpenRequestA.restype = ctypes.c_void_p
HttpOpenRequestA.argtypes = [
    ctypes.POINTER(None),  # hConnect : void*
    wintypes.LPCSTR,  # lpszVerb : LPCSTR optional
    wintypes.LPCSTR,  # lpszObjectName : LPCSTR optional
    wintypes.LPCSTR,  # lpszVersion : LPCSTR optional
    wintypes.LPCSTR,  # lpszReferrer : LPCSTR optional
    ctypes.c_void_p,  # lplpszAcceptTypes : LPCSTR* 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')
HttpOpenRequestA = Fiddle::Function.new(
  lib['HttpOpenRequestA'],
  [
    Fiddle::TYPE_VOIDP,  # hConnect : void*
    Fiddle::TYPE_VOIDP,  # lpszVerb : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # lpszObjectName : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # lpszVersion : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # lpszReferrer : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # lplpszAcceptTypes : LPCSTR* optional
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
    Fiddle::TYPE_UINTPTR_T,  # dwContext : UINT_PTR optional
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "wininet")]
extern "system" {
    fn HttpOpenRequestA(
        hConnect: *mut (),  // void*
        lpszVerb: *const u8,  // LPCSTR optional
        lpszObjectName: *const u8,  // LPCSTR optional
        lpszVersion: *const u8,  // LPCSTR optional
        lpszReferrer: *const u8,  // LPCSTR optional
        lplpszAcceptTypes: *const *const u8,  // LPCSTR* 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.Ansi, SetLastError = true)]
public static extern IntPtr HttpOpenRequestA(IntPtr hConnect, [MarshalAs(UnmanagedType.LPStr)] string lpszVerb, [MarshalAs(UnmanagedType.LPStr)] string lpszObjectName, [MarshalAs(UnmanagedType.LPStr)] string lpszVersion, [MarshalAs(UnmanagedType.LPStr)] string lpszReferrer, IntPtr lplpszAcceptTypes, uint dwFlags, UIntPtr dwContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_HttpOpenRequestA' -Namespace Win32 -PassThru
# $api::HttpOpenRequestA(hConnect, lpszVerb, lpszObjectName, lpszVersion, lpszReferrer, lplpszAcceptTypes, dwFlags, dwContext)
#uselib "WININET.dll"
#func global HttpOpenRequestA "HttpOpenRequestA" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; HttpOpenRequestA hConnect, lpszVerb, lpszObjectName, lpszVersion, lpszReferrer, varptr(lplpszAcceptTypes), dwFlags, dwContext   ; 戻り値は stat
; hConnect : void* -> "sptr"
; lpszVerb : LPCSTR optional -> "sptr"
; lpszObjectName : LPCSTR optional -> "sptr"
; lpszVersion : LPCSTR optional -> "sptr"
; lpszReferrer : LPCSTR optional -> "sptr"
; lplpszAcceptTypes : LPCSTR* optional -> "sptr"
; dwFlags : DWORD -> "sptr"
; dwContext : UINT_PTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WININET.dll"
#cfunc global HttpOpenRequestA "HttpOpenRequestA" sptr, str, str, str, str, var, int, sptr
; res = HttpOpenRequestA(hConnect, lpszVerb, lpszObjectName, lpszVersion, lpszReferrer, lplpszAcceptTypes, dwFlags, dwContext)
; hConnect : void* -> "sptr"
; lpszVerb : LPCSTR optional -> "str"
; lpszObjectName : LPCSTR optional -> "str"
; lpszVersion : LPCSTR optional -> "str"
; lpszReferrer : LPCSTR optional -> "str"
; lplpszAcceptTypes : LPCSTR* optional -> "var"
; dwFlags : DWORD -> "int"
; dwContext : UINT_PTR optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; void* HttpOpenRequestA(void* hConnect, LPCSTR lpszVerb, LPCSTR lpszObjectName, LPCSTR lpszVersion, LPCSTR lpszReferrer, LPCSTR* lplpszAcceptTypes, DWORD dwFlags, UINT_PTR dwContext)
#uselib "WININET.dll"
#cfunc global HttpOpenRequestA "HttpOpenRequestA" intptr, str, str, str, str, var, int, intptr
; res = HttpOpenRequestA(hConnect, lpszVerb, lpszObjectName, lpszVersion, lpszReferrer, lplpszAcceptTypes, dwFlags, dwContext)
; hConnect : void* -> "intptr"
; lpszVerb : LPCSTR optional -> "str"
; lpszObjectName : LPCSTR optional -> "str"
; lpszVersion : LPCSTR optional -> "str"
; lpszReferrer : LPCSTR optional -> "str"
; lplpszAcceptTypes : LPCSTR* 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")
	procHttpOpenRequestA = wininet.NewProc("HttpOpenRequestA")
)

// hConnect (void*), lpszVerb (LPCSTR optional), lpszObjectName (LPCSTR optional), lpszVersion (LPCSTR optional), lpszReferrer (LPCSTR optional), lplpszAcceptTypes (LPCSTR* optional), dwFlags (DWORD), dwContext (UINT_PTR optional)
r1, _, err := procHttpOpenRequestA.Call(
	uintptr(hConnect),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszVerb))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszObjectName))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszVersion))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszReferrer))),
	uintptr(lplpszAcceptTypes),
	uintptr(dwFlags),
	uintptr(dwContext),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // void*
function HttpOpenRequestA(
  hConnect: Pointer;   // void*
  lpszVerb: PAnsiChar;   // LPCSTR optional
  lpszObjectName: PAnsiChar;   // LPCSTR optional
  lpszVersion: PAnsiChar;   // LPCSTR optional
  lpszReferrer: PAnsiChar;   // LPCSTR optional
  lplpszAcceptTypes: PPAnsiChar;   // LPCSTR* optional
  dwFlags: DWORD;   // DWORD
  dwContext: NativeUInt   // UINT_PTR optional
): Pointer; stdcall;
  external 'WININET.dll' name 'HttpOpenRequestA';
result := DllCall("WININET\HttpOpenRequestA"
    , "Ptr", hConnect   ; void*
    , "AStr", lpszVerb   ; LPCSTR optional
    , "AStr", lpszObjectName   ; LPCSTR optional
    , "AStr", lpszVersion   ; LPCSTR optional
    , "AStr", lpszReferrer   ; LPCSTR optional
    , "Ptr", lplpszAcceptTypes   ; LPCSTR* optional
    , "UInt", dwFlags   ; DWORD
    , "UPtr", dwContext   ; UINT_PTR optional
    , "Ptr")   ; return: void*
●HttpOpenRequestA(hConnect, lpszVerb, lpszObjectName, lpszVersion, lpszReferrer, lplpszAcceptTypes, dwFlags, dwContext) = DLL("WININET.dll", "void* HttpOpenRequestA(void*, char*, char*, char*, char*, void*, dword, int)")
# 呼び出し: HttpOpenRequestA(hConnect, lpszVerb, lpszObjectName, lpszVersion, lpszReferrer, lplpszAcceptTypes, dwFlags, dwContext)
# hConnect : void* -> "void*"
# lpszVerb : LPCSTR optional -> "char*"
# lpszObjectName : LPCSTR optional -> "char*"
# lpszVersion : LPCSTR optional -> "char*"
# lpszReferrer : LPCSTR optional -> "char*"
# lplpszAcceptTypes : LPCSTR* optional -> "void*"
# dwFlags : DWORD -> "dword"
# dwContext : UINT_PTR optional -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。