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

WinHttpReadDataEx

関数
HTTP応答から拡張フラグ付きでデータを読み取る。
DLLWINHTTP.dll呼出規約winapi

シグネチャ

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

DWORD WinHttpReadDataEx(
    void* hRequest,
    void* lpBuffer,
    DWORD dwNumberOfBytesToRead,
    DWORD* lpdwNumberOfBytesRead,
    ULONGLONG ullFlags,
    DWORD cbProperty,
    void* pvProperty   // optional
);

パラメーター

名前方向
hRequestvoid*inout
lpBuffervoid*out
dwNumberOfBytesToReadDWORDin
lpdwNumberOfBytesReadDWORD*inout
ullFlagsULONGLONGin
cbPropertyDWORDin
pvPropertyvoid*inoptional

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD WinHttpReadDataEx(
    void* hRequest,
    void* lpBuffer,
    DWORD dwNumberOfBytesToRead,
    DWORD* lpdwNumberOfBytesRead,
    ULONGLONG ullFlags,
    DWORD cbProperty,
    void* pvProperty   // optional
);
[DllImport("WINHTTP.dll", ExactSpelling = true)]
static extern uint WinHttpReadDataEx(
    IntPtr hRequest,   // void* in/out
    IntPtr lpBuffer,   // void* out
    uint dwNumberOfBytesToRead,   // DWORD
    ref uint lpdwNumberOfBytesRead,   // DWORD* in/out
    ulong ullFlags,   // ULONGLONG
    uint cbProperty,   // DWORD
    IntPtr pvProperty   // void* optional
);
<DllImport("WINHTTP.dll", ExactSpelling:=True)>
Public Shared Function WinHttpReadDataEx(
    hRequest As IntPtr,   ' void* in/out
    lpBuffer As IntPtr,   ' void* out
    dwNumberOfBytesToRead As UInteger,   ' DWORD
    ByRef lpdwNumberOfBytesRead As UInteger,   ' DWORD* in/out
    ullFlags As ULong,   ' ULONGLONG
    cbProperty As UInteger,   ' DWORD
    pvProperty As IntPtr   ' void* optional
) As UInteger
End Function
' hRequest : void* in/out
' lpBuffer : void* out
' dwNumberOfBytesToRead : DWORD
' lpdwNumberOfBytesRead : DWORD* in/out
' ullFlags : ULONGLONG
' cbProperty : DWORD
' pvProperty : void* optional
Declare PtrSafe Function WinHttpReadDataEx Lib "winhttp" ( _
    ByVal hRequest As LongPtr, _
    ByVal lpBuffer As LongPtr, _
    ByVal dwNumberOfBytesToRead As Long, _
    ByRef lpdwNumberOfBytesRead As Long, _
    ByVal ullFlags As LongLong, _
    ByVal cbProperty As Long, _
    ByVal pvProperty As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WinHttpReadDataEx = ctypes.windll.winhttp.WinHttpReadDataEx
WinHttpReadDataEx.restype = wintypes.DWORD
WinHttpReadDataEx.argtypes = [
    ctypes.POINTER(None),  # hRequest : void* in/out
    ctypes.POINTER(None),  # lpBuffer : void* out
    wintypes.DWORD,  # dwNumberOfBytesToRead : DWORD
    ctypes.POINTER(wintypes.DWORD),  # lpdwNumberOfBytesRead : DWORD* in/out
    ctypes.c_ulonglong,  # ullFlags : ULONGLONG
    wintypes.DWORD,  # cbProperty : DWORD
    ctypes.POINTER(None),  # pvProperty : void* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WINHTTP.dll')
WinHttpReadDataEx = Fiddle::Function.new(
  lib['WinHttpReadDataEx'],
  [
    Fiddle::TYPE_VOIDP,  # hRequest : void* in/out
    Fiddle::TYPE_VOIDP,  # lpBuffer : void* out
    -Fiddle::TYPE_INT,  # dwNumberOfBytesToRead : DWORD
    Fiddle::TYPE_VOIDP,  # lpdwNumberOfBytesRead : DWORD* in/out
    -Fiddle::TYPE_LONG_LONG,  # ullFlags : ULONGLONG
    -Fiddle::TYPE_INT,  # cbProperty : DWORD
    Fiddle::TYPE_VOIDP,  # pvProperty : void* optional
  ],
  -Fiddle::TYPE_INT)
#[link(name = "winhttp")]
extern "system" {
    fn WinHttpReadDataEx(
        hRequest: *mut (),  // void* in/out
        lpBuffer: *mut (),  // void* out
        dwNumberOfBytesToRead: u32,  // DWORD
        lpdwNumberOfBytesRead: *mut u32,  // DWORD* in/out
        ullFlags: u64,  // ULONGLONG
        cbProperty: u32,  // DWORD
        pvProperty: *mut ()  // void* optional
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WINHTTP.dll")]
public static extern uint WinHttpReadDataEx(IntPtr hRequest, IntPtr lpBuffer, uint dwNumberOfBytesToRead, ref uint lpdwNumberOfBytesRead, ulong ullFlags, uint cbProperty, IntPtr pvProperty);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WINHTTP_WinHttpReadDataEx' -Namespace Win32 -PassThru
# $api::WinHttpReadDataEx(hRequest, lpBuffer, dwNumberOfBytesToRead, lpdwNumberOfBytesRead, ullFlags, cbProperty, pvProperty)
#uselib "WINHTTP.dll"
#func global WinHttpReadDataEx "WinHttpReadDataEx" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; WinHttpReadDataEx hRequest, lpBuffer, dwNumberOfBytesToRead, varptr(lpdwNumberOfBytesRead), ullFlags, cbProperty, pvProperty   ; 戻り値は stat
; hRequest : void* in/out -> "sptr"
; lpBuffer : void* out -> "sptr"
; dwNumberOfBytesToRead : DWORD -> "sptr"
; lpdwNumberOfBytesRead : DWORD* in/out -> "sptr"
; ullFlags : ULONGLONG -> "sptr"
; cbProperty : DWORD -> "sptr"
; pvProperty : void* optional -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WINHTTP.dll"
#cfunc global WinHttpReadDataEx "WinHttpReadDataEx" sptr, sptr, int, var, int64, int, sptr
; res = WinHttpReadDataEx(hRequest, lpBuffer, dwNumberOfBytesToRead, lpdwNumberOfBytesRead, ullFlags, cbProperty, pvProperty)
; hRequest : void* in/out -> "sptr"
; lpBuffer : void* out -> "sptr"
; dwNumberOfBytesToRead : DWORD -> "int"
; lpdwNumberOfBytesRead : DWORD* in/out -> "var"
; ullFlags : ULONGLONG -> "int64"
; cbProperty : DWORD -> "int"
; pvProperty : void* optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
出力引数:
; DWORD WinHttpReadDataEx(void* hRequest, void* lpBuffer, DWORD dwNumberOfBytesToRead, DWORD* lpdwNumberOfBytesRead, ULONGLONG ullFlags, DWORD cbProperty, void* pvProperty)
#uselib "WINHTTP.dll"
#cfunc global WinHttpReadDataEx "WinHttpReadDataEx" intptr, intptr, int, var, int64, int, intptr
; res = WinHttpReadDataEx(hRequest, lpBuffer, dwNumberOfBytesToRead, lpdwNumberOfBytesRead, ullFlags, cbProperty, pvProperty)
; hRequest : void* in/out -> "intptr"
; lpBuffer : void* out -> "intptr"
; dwNumberOfBytesToRead : DWORD -> "int"
; lpdwNumberOfBytesRead : DWORD* in/out -> "var"
; ullFlags : ULONGLONG -> "int64"
; cbProperty : DWORD -> "int"
; pvProperty : void* optional -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winhttp = windows.NewLazySystemDLL("WINHTTP.dll")
	procWinHttpReadDataEx = winhttp.NewProc("WinHttpReadDataEx")
)

// hRequest (void* in/out), lpBuffer (void* out), dwNumberOfBytesToRead (DWORD), lpdwNumberOfBytesRead (DWORD* in/out), ullFlags (ULONGLONG), cbProperty (DWORD), pvProperty (void* optional)
r1, _, err := procWinHttpReadDataEx.Call(
	uintptr(hRequest),
	uintptr(lpBuffer),
	uintptr(dwNumberOfBytesToRead),
	uintptr(lpdwNumberOfBytesRead),
	uintptr(ullFlags),
	uintptr(cbProperty),
	uintptr(pvProperty),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function WinHttpReadDataEx(
  hRequest: Pointer;   // void* in/out
  lpBuffer: Pointer;   // void* out
  dwNumberOfBytesToRead: DWORD;   // DWORD
  lpdwNumberOfBytesRead: Pointer;   // DWORD* in/out
  ullFlags: UInt64;   // ULONGLONG
  cbProperty: DWORD;   // DWORD
  pvProperty: Pointer   // void* optional
): DWORD; stdcall;
  external 'WINHTTP.dll' name 'WinHttpReadDataEx';
result := DllCall("WINHTTP\WinHttpReadDataEx"
    , "Ptr", hRequest   ; void* in/out
    , "Ptr", lpBuffer   ; void* out
    , "UInt", dwNumberOfBytesToRead   ; DWORD
    , "Ptr", lpdwNumberOfBytesRead   ; DWORD* in/out
    , "Int64", ullFlags   ; ULONGLONG
    , "UInt", cbProperty   ; DWORD
    , "Ptr", pvProperty   ; void* optional
    , "UInt")   ; return: DWORD
●WinHttpReadDataEx(hRequest, lpBuffer, dwNumberOfBytesToRead, lpdwNumberOfBytesRead, ullFlags, cbProperty, pvProperty) = DLL("WINHTTP.dll", "dword WinHttpReadDataEx(void*, void*, dword, void*, qword, dword, void*)")
# 呼び出し: WinHttpReadDataEx(hRequest, lpBuffer, dwNumberOfBytesToRead, lpdwNumberOfBytesRead, ullFlags, cbProperty, pvProperty)
# hRequest : void* in/out -> "void*"
# lpBuffer : void* out -> "void*"
# dwNumberOfBytesToRead : DWORD -> "dword"
# lpdwNumberOfBytesRead : DWORD* in/out -> "void*"
# ullFlags : ULONGLONG -> "qword"
# cbProperty : DWORD -> "dword"
# pvProperty : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。