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

WinHttpWriteData

関数
HTTP要求の本体にデータを書き込む。
DLLWINHTTP.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL WinHttpWriteData(
    void* hRequest,
    const void* lpBuffer,   // optional
    DWORD dwNumberOfBytesToWrite,
    DWORD* lpdwNumberOfBytesWritten
);

パラメーター

名前方向
hRequestvoid*inout
lpBuffervoid*inoptional
dwNumberOfBytesToWriteDWORDin
lpdwNumberOfBytesWrittenDWORD*inout

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL WinHttpWriteData(
    void* hRequest,
    const void* lpBuffer,   // optional
    DWORD dwNumberOfBytesToWrite,
    DWORD* lpdwNumberOfBytesWritten
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WINHTTP.dll", SetLastError = true, ExactSpelling = true)]
static extern bool WinHttpWriteData(
    IntPtr hRequest,   // void* in/out
    IntPtr lpBuffer,   // void* optional
    uint dwNumberOfBytesToWrite,   // DWORD
    ref uint lpdwNumberOfBytesWritten   // DWORD* in/out
);
<DllImport("WINHTTP.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WinHttpWriteData(
    hRequest As IntPtr,   ' void* in/out
    lpBuffer As IntPtr,   ' void* optional
    dwNumberOfBytesToWrite As UInteger,   ' DWORD
    ByRef lpdwNumberOfBytesWritten As UInteger   ' DWORD* in/out
) As Boolean
End Function
' hRequest : void* in/out
' lpBuffer : void* optional
' dwNumberOfBytesToWrite : DWORD
' lpdwNumberOfBytesWritten : DWORD* in/out
Declare PtrSafe Function WinHttpWriteData Lib "winhttp" ( _
    ByVal hRequest As LongPtr, _
    ByVal lpBuffer As LongPtr, _
    ByVal dwNumberOfBytesToWrite As Long, _
    ByRef lpdwNumberOfBytesWritten As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WinHttpWriteData = ctypes.windll.winhttp.WinHttpWriteData
WinHttpWriteData.restype = wintypes.BOOL
WinHttpWriteData.argtypes = [
    ctypes.POINTER(None),  # hRequest : void* in/out
    ctypes.POINTER(None),  # lpBuffer : void* optional
    wintypes.DWORD,  # dwNumberOfBytesToWrite : DWORD
    ctypes.POINTER(wintypes.DWORD),  # lpdwNumberOfBytesWritten : DWORD* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WINHTTP.dll')
WinHttpWriteData = Fiddle::Function.new(
  lib['WinHttpWriteData'],
  [
    Fiddle::TYPE_VOIDP,  # hRequest : void* in/out
    Fiddle::TYPE_VOIDP,  # lpBuffer : void* optional
    -Fiddle::TYPE_INT,  # dwNumberOfBytesToWrite : DWORD
    Fiddle::TYPE_VOIDP,  # lpdwNumberOfBytesWritten : DWORD* in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "winhttp")]
extern "system" {
    fn WinHttpWriteData(
        hRequest: *mut (),  // void* in/out
        lpBuffer: *const (),  // void* optional
        dwNumberOfBytesToWrite: u32,  // DWORD
        lpdwNumberOfBytesWritten: *mut u32  // DWORD* 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 WinHttpWriteData(IntPtr hRequest, IntPtr lpBuffer, uint dwNumberOfBytesToWrite, ref uint lpdwNumberOfBytesWritten);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WINHTTP_WinHttpWriteData' -Namespace Win32 -PassThru
# $api::WinHttpWriteData(hRequest, lpBuffer, dwNumberOfBytesToWrite, lpdwNumberOfBytesWritten)
#uselib "WINHTTP.dll"
#func global WinHttpWriteData "WinHttpWriteData" sptr, sptr, sptr, sptr
; WinHttpWriteData hRequest, lpBuffer, dwNumberOfBytesToWrite, varptr(lpdwNumberOfBytesWritten)   ; 戻り値は stat
; hRequest : void* in/out -> "sptr"
; lpBuffer : void* optional -> "sptr"
; dwNumberOfBytesToWrite : DWORD -> "sptr"
; lpdwNumberOfBytesWritten : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WINHTTP.dll"
#cfunc global WinHttpWriteData "WinHttpWriteData" sptr, sptr, int, var
; res = WinHttpWriteData(hRequest, lpBuffer, dwNumberOfBytesToWrite, lpdwNumberOfBytesWritten)
; hRequest : void* in/out -> "sptr"
; lpBuffer : void* optional -> "sptr"
; dwNumberOfBytesToWrite : DWORD -> "int"
; lpdwNumberOfBytesWritten : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL WinHttpWriteData(void* hRequest, void* lpBuffer, DWORD dwNumberOfBytesToWrite, DWORD* lpdwNumberOfBytesWritten)
#uselib "WINHTTP.dll"
#cfunc global WinHttpWriteData "WinHttpWriteData" intptr, intptr, int, var
; res = WinHttpWriteData(hRequest, lpBuffer, dwNumberOfBytesToWrite, lpdwNumberOfBytesWritten)
; hRequest : void* in/out -> "intptr"
; lpBuffer : void* optional -> "intptr"
; dwNumberOfBytesToWrite : DWORD -> "int"
; lpdwNumberOfBytesWritten : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winhttp = windows.NewLazySystemDLL("WINHTTP.dll")
	procWinHttpWriteData = winhttp.NewProc("WinHttpWriteData")
)

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