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

WinHttpProtocolSend

関数
昇格したプロトコル接続でデータを送信する。
DLLWINHTTP.dll呼出規約winapi

シグネチャ

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

DWORD WinHttpProtocolSend(
    void* ProtocolHandle,
    ULONGLONG Flags,
    void* pvBuffer,   // optional
    DWORD dwBufferLength
);

パラメーター

名前方向説明
ProtocolHandlevoid*inCompleteUpgradeで取得した汎用プロトコルハンドル。送信対象。
FlagsULONGLONGin送信動作を制御する64ビットフラグ。
pvBuffervoid*inoptional送信するデータを格納したバッファへのポインタ。
dwBufferLengthDWORDinpvBufferが指す送信データのバイト数。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD WinHttpProtocolSend(
    void* ProtocolHandle,
    ULONGLONG Flags,
    void* pvBuffer,   // optional
    DWORD dwBufferLength
);
[DllImport("WINHTTP.dll", ExactSpelling = true)]
static extern uint WinHttpProtocolSend(
    IntPtr ProtocolHandle,   // void*
    ulong Flags,   // ULONGLONG
    IntPtr pvBuffer,   // void* optional
    uint dwBufferLength   // DWORD
);
<DllImport("WINHTTP.dll", ExactSpelling:=True)>
Public Shared Function WinHttpProtocolSend(
    ProtocolHandle As IntPtr,   ' void*
    Flags As ULong,   ' ULONGLONG
    pvBuffer As IntPtr,   ' void* optional
    dwBufferLength As UInteger   ' DWORD
) As UInteger
End Function
' ProtocolHandle : void*
' Flags : ULONGLONG
' pvBuffer : void* optional
' dwBufferLength : DWORD
Declare PtrSafe Function WinHttpProtocolSend Lib "winhttp" ( _
    ByVal ProtocolHandle As LongPtr, _
    ByVal Flags As LongLong, _
    ByVal pvBuffer As LongPtr, _
    ByVal dwBufferLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WinHttpProtocolSend = ctypes.windll.winhttp.WinHttpProtocolSend
WinHttpProtocolSend.restype = wintypes.DWORD
WinHttpProtocolSend.argtypes = [
    ctypes.POINTER(None),  # ProtocolHandle : void*
    ctypes.c_ulonglong,  # Flags : ULONGLONG
    ctypes.POINTER(None),  # pvBuffer : void* optional
    wintypes.DWORD,  # dwBufferLength : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WINHTTP.dll')
WinHttpProtocolSend = Fiddle::Function.new(
  lib['WinHttpProtocolSend'],
  [
    Fiddle::TYPE_VOIDP,  # ProtocolHandle : void*
    -Fiddle::TYPE_LONG_LONG,  # Flags : ULONGLONG
    Fiddle::TYPE_VOIDP,  # pvBuffer : void* optional
    -Fiddle::TYPE_INT,  # dwBufferLength : DWORD
  ],
  -Fiddle::TYPE_INT)
#[link(name = "winhttp")]
extern "system" {
    fn WinHttpProtocolSend(
        ProtocolHandle: *mut (),  // void*
        Flags: u64,  // ULONGLONG
        pvBuffer: *mut (),  // void* optional
        dwBufferLength: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WINHTTP.dll")]
public static extern uint WinHttpProtocolSend(IntPtr ProtocolHandle, ulong Flags, IntPtr pvBuffer, uint dwBufferLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WINHTTP_WinHttpProtocolSend' -Namespace Win32 -PassThru
# $api::WinHttpProtocolSend(ProtocolHandle, Flags, pvBuffer, dwBufferLength)
#uselib "WINHTTP.dll"
#func global WinHttpProtocolSend "WinHttpProtocolSend" sptr, sptr, sptr, sptr
; WinHttpProtocolSend ProtocolHandle, Flags, pvBuffer, dwBufferLength   ; 戻り値は stat
; ProtocolHandle : void* -> "sptr"
; Flags : ULONGLONG -> "sptr"
; pvBuffer : void* optional -> "sptr"
; dwBufferLength : DWORD -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WINHTTP.dll"
#cfunc global WinHttpProtocolSend "WinHttpProtocolSend" sptr, int64, sptr, int
; res = WinHttpProtocolSend(ProtocolHandle, Flags, pvBuffer, dwBufferLength)
; ProtocolHandle : void* -> "sptr"
; Flags : ULONGLONG -> "int64"
; pvBuffer : void* optional -> "sptr"
; dwBufferLength : DWORD -> "int"
; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
; DWORD WinHttpProtocolSend(void* ProtocolHandle, ULONGLONG Flags, void* pvBuffer, DWORD dwBufferLength)
#uselib "WINHTTP.dll"
#cfunc global WinHttpProtocolSend "WinHttpProtocolSend" intptr, int64, intptr, int
; res = WinHttpProtocolSend(ProtocolHandle, Flags, pvBuffer, dwBufferLength)
; ProtocolHandle : void* -> "intptr"
; Flags : ULONGLONG -> "int64"
; pvBuffer : void* optional -> "intptr"
; dwBufferLength : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winhttp = windows.NewLazySystemDLL("WINHTTP.dll")
	procWinHttpProtocolSend = winhttp.NewProc("WinHttpProtocolSend")
)

// ProtocolHandle (void*), Flags (ULONGLONG), pvBuffer (void* optional), dwBufferLength (DWORD)
r1, _, err := procWinHttpProtocolSend.Call(
	uintptr(ProtocolHandle),
	uintptr(Flags),
	uintptr(pvBuffer),
	uintptr(dwBufferLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function WinHttpProtocolSend(
  ProtocolHandle: Pointer;   // void*
  Flags: UInt64;   // ULONGLONG
  pvBuffer: Pointer;   // void* optional
  dwBufferLength: DWORD   // DWORD
): DWORD; stdcall;
  external 'WINHTTP.dll' name 'WinHttpProtocolSend';
result := DllCall("WINHTTP\WinHttpProtocolSend"
    , "Ptr", ProtocolHandle   ; void*
    , "Int64", Flags   ; ULONGLONG
    , "Ptr", pvBuffer   ; void* optional
    , "UInt", dwBufferLength   ; DWORD
    , "UInt")   ; return: DWORD
●WinHttpProtocolSend(ProtocolHandle, Flags, pvBuffer, dwBufferLength) = DLL("WINHTTP.dll", "dword WinHttpProtocolSend(void*, qword, void*, dword)")
# 呼び出し: WinHttpProtocolSend(ProtocolHandle, Flags, pvBuffer, dwBufferLength)
# ProtocolHandle : void* -> "void*"
# Flags : ULONGLONG -> "qword"
# pvBuffer : void* optional -> "void*"
# dwBufferLength : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "winhttp" fn WinHttpProtocolSend(
    ProtocolHandle: ?*anyopaque, // void*
    Flags: u64, // ULONGLONG
    pvBuffer: ?*anyopaque, // void* optional
    dwBufferLength: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
proc WinHttpProtocolSend(
    ProtocolHandle: pointer,  # void*
    Flags: uint64,  # ULONGLONG
    pvBuffer: pointer,  # void* optional
    dwBufferLength: uint32  # DWORD
): uint32 {.importc: "WinHttpProtocolSend", stdcall, dynlib: "WINHTTP.dll".}
pragma(lib, "winhttp");
extern(Windows)
uint WinHttpProtocolSend(
    void* ProtocolHandle,   // void*
    ulong Flags,   // ULONGLONG
    void* pvBuffer,   // void* optional
    uint dwBufferLength   // DWORD
);
ccall((:WinHttpProtocolSend, "WINHTTP.dll"), stdcall, UInt32,
      (Ptr{Cvoid}, UInt64, Ptr{Cvoid}, UInt32),
      ProtocolHandle, Flags, pvBuffer, dwBufferLength)
# ProtocolHandle : void* -> Ptr{Cvoid}
# Flags : ULONGLONG -> UInt64
# pvBuffer : void* optional -> Ptr{Cvoid}
# dwBufferLength : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t WinHttpProtocolSend(
    void* ProtocolHandle,
    uint64_t Flags,
    void* pvBuffer,
    uint32_t dwBufferLength);
]]
local winhttp = ffi.load("winhttp")
-- winhttp.WinHttpProtocolSend(ProtocolHandle, Flags, pvBuffer, dwBufferLength)
-- ProtocolHandle : void*
-- Flags : ULONGLONG
-- pvBuffer : void* optional
-- dwBufferLength : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('WINHTTP.dll');
const WinHttpProtocolSend = lib.func('__stdcall', 'WinHttpProtocolSend', 'uint32_t', ['void *', 'uint64_t', 'void *', 'uint32_t']);
// WinHttpProtocolSend(ProtocolHandle, Flags, pvBuffer, dwBufferLength)
// ProtocolHandle : void* -> 'void *'
// Flags : ULONGLONG -> 'uint64_t'
// pvBuffer : void* optional -> 'void *'
// dwBufferLength : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WINHTTP.dll", {
  WinHttpProtocolSend: { parameters: ["pointer", "u64", "pointer", "u32"], result: "u32" },
});
// lib.symbols.WinHttpProtocolSend(ProtocolHandle, Flags, pvBuffer, dwBufferLength)
// ProtocolHandle : void* -> "pointer"
// Flags : ULONGLONG -> "u64"
// pvBuffer : void* optional -> "pointer"
// dwBufferLength : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t WinHttpProtocolSend(
    void* ProtocolHandle,
    uint64_t Flags,
    void* pvBuffer,
    uint32_t dwBufferLength);
C, "WINHTTP.dll");
// $ffi->WinHttpProtocolSend(ProtocolHandle, Flags, pvBuffer, dwBufferLength);
// ProtocolHandle : void*
// Flags : ULONGLONG
// pvBuffer : void* optional
// dwBufferLength : DWORD
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Winhttp extends StdCallLibrary {
    Winhttp INSTANCE = Native.load("winhttp", Winhttp.class);
    int WinHttpProtocolSend(
        Pointer ProtocolHandle,   // void*
        long Flags,   // ULONGLONG
        Pointer pvBuffer,   // void* optional
        int dwBufferLength   // DWORD
    );
}
@[Link("winhttp")]
lib LibWINHTTP
  fun WinHttpProtocolSend = WinHttpProtocolSend(
    ProtocolHandle : Void*,   # void*
    Flags : UInt64,   # ULONGLONG
    pvBuffer : Void*,   # void* optional
    dwBufferLength : UInt32   # DWORD
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef WinHttpProtocolSendNative = Uint32 Function(Pointer<Void>, Uint64, Pointer<Void>, Uint32);
typedef WinHttpProtocolSendDart = int Function(Pointer<Void>, int, Pointer<Void>, int);
final WinHttpProtocolSend = DynamicLibrary.open('WINHTTP.dll')
    .lookupFunction<WinHttpProtocolSendNative, WinHttpProtocolSendDart>('WinHttpProtocolSend');
// ProtocolHandle : void* -> Pointer<Void>
// Flags : ULONGLONG -> Uint64
// pvBuffer : void* optional -> Pointer<Void>
// dwBufferLength : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function WinHttpProtocolSend(
  ProtocolHandle: Pointer;   // void*
  Flags: UInt64;   // ULONGLONG
  pvBuffer: Pointer;   // void* optional
  dwBufferLength: DWORD   // DWORD
): DWORD; stdcall;
  external 'WINHTTP.dll' name 'WinHttpProtocolSend';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "WinHttpProtocolSend"
  c_WinHttpProtocolSend :: Ptr () -> Word64 -> Ptr () -> Word32 -> IO Word32
-- ProtocolHandle : void* -> Ptr ()
-- Flags : ULONGLONG -> Word64
-- pvBuffer : void* optional -> Ptr ()
-- dwBufferLength : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let winhttpprotocolsend =
  foreign "WinHttpProtocolSend"
    ((ptr void) @-> uint64_t @-> (ptr void) @-> uint32_t @-> returning uint32_t)
(* ProtocolHandle : void* -> (ptr void) *)
(* Flags : ULONGLONG -> uint64_t *)
(* pvBuffer : void* optional -> (ptr void) *)
(* dwBufferLength : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library winhttp (t "WINHTTP.dll"))
(cffi:use-foreign-library winhttp)

(cffi:defcfun ("WinHttpProtocolSend" win-http-protocol-send :convention :stdcall) :uint32
  (protocol-handle :pointer)   ; void*
  (flags :uint64)   ; ULONGLONG
  (pv-buffer :pointer)   ; void* optional
  (dw-buffer-length :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WinHttpProtocolSend = Win32::API::More->new('WINHTTP',
    'DWORD WinHttpProtocolSend(LPVOID ProtocolHandle, UINT64 Flags, LPVOID pvBuffer, DWORD dwBufferLength)');
# my $ret = $WinHttpProtocolSend->Call($ProtocolHandle, $Flags, $pvBuffer, $dwBufferLength);
# ProtocolHandle : void* -> LPVOID
# Flags : ULONGLONG -> UINT64
# pvBuffer : void* optional -> LPVOID
# dwBufferLength : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。