ホーム › Networking.WinInet › HttpEndRequestA
HttpEndRequestA
関数HttpSendRequestExで開始したHTTP要求を完了させる(ANSI版)。
シグネチャ
// WININET.dll (ANSI / -A)
#include <windows.h>
BOOL HttpEndRequestA(
void* hRequest,
INTERNET_BUFFERSA* lpBuffersOut, // optional
DWORD dwFlags,
UINT_PTR dwContext // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hRequest | void* | in | HttpOpenRequest によって返され、 HttpSendRequestEx によって送信されたハンドル。 |
| lpBuffersOut | INTERNET_BUFFERSA* | outoptional | このパラメーターは予約されており、NULL でなければなりません。 |
| dwFlags | DWORD | in | このパラメーターは予約されており、0 を設定する必要があります。 |
| dwContext | UINT_PTR | inoptional | このパラメーターは予約されており、0 を設定する必要があります。 |
戻り値の型: BOOL
公式ドキュメント
HttpSendRequestEx によって開始された HTTP 要求を終了します。(ANSI)
戻り値
関数が成功した場合、TRUE を返します。
関数が失敗した場合、FALSE を返します。拡張エラー情報を取得するには、 GetLastError を呼び出してください。
解説(Remarks)
lpBuffersOut が NULL に設定されていない場合、 HttpEndRequest は ERROR_INVALID_PARAMETER を返します。
WinINet API の他のすべての側面と同様に、この関数は DllMain 内やグローバルオブジェクトのコンストラクター・デストラクター内から安全に呼び出すことはできません。
注意 WinINet はサーバー実装をサポートしていません。また、サービスから使用しないでください。サーバー実装やサービスでは、Microsoft Windows HTTP Services (WinHTTP) を使用してください。
メモ
wininet.h ヘッダーは、HttpEndRequest を UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義しています。エンコーディング中立のエイリアスを、エンコーディング中立でないコードと混在して使用すると、不一致が発生し、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// WININET.dll (ANSI / -A)
#include <windows.h>
BOOL HttpEndRequestA(
void* hRequest,
INTERNET_BUFFERSA* lpBuffersOut, // optional
DWORD dwFlags,
UINT_PTR dwContext // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool HttpEndRequestA(
IntPtr hRequest, // void*
IntPtr lpBuffersOut, // INTERNET_BUFFERSA* optional, out
uint dwFlags, // DWORD
UIntPtr dwContext // UINT_PTR optional
);<DllImport("WININET.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function HttpEndRequestA(
hRequest As IntPtr, ' void*
lpBuffersOut As IntPtr, ' INTERNET_BUFFERSA* optional, out
dwFlags As UInteger, ' DWORD
dwContext As UIntPtr ' UINT_PTR optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hRequest : void*
' lpBuffersOut : INTERNET_BUFFERSA* optional, out
' dwFlags : DWORD
' dwContext : UINT_PTR optional
Declare PtrSafe Function HttpEndRequestA Lib "wininet" ( _
ByVal hRequest As LongPtr, _
ByVal lpBuffersOut As LongPtr, _
ByVal dwFlags As Long, _
ByVal dwContext As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
HttpEndRequestA = ctypes.windll.wininet.HttpEndRequestA
HttpEndRequestA.restype = wintypes.BOOL
HttpEndRequestA.argtypes = [
ctypes.POINTER(None), # hRequest : void*
ctypes.c_void_p, # lpBuffersOut : INTERNET_BUFFERSA* optional, out
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')
HttpEndRequestA = Fiddle::Function.new(
lib['HttpEndRequestA'],
[
Fiddle::TYPE_VOIDP, # hRequest : void*
Fiddle::TYPE_VOIDP, # lpBuffersOut : INTERNET_BUFFERSA* optional, out
-Fiddle::TYPE_INT, # dwFlags : DWORD
Fiddle::TYPE_UINTPTR_T, # dwContext : UINT_PTR optional
],
Fiddle::TYPE_INT)#[link(name = "wininet")]
extern "system" {
fn HttpEndRequestA(
hRequest: *mut (), // void*
lpBuffersOut: *mut INTERNET_BUFFERSA, // INTERNET_BUFFERSA* optional, out
dwFlags: u32, // DWORD
dwContext: usize // UINT_PTR optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool HttpEndRequestA(IntPtr hRequest, IntPtr lpBuffersOut, uint dwFlags, UIntPtr dwContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_HttpEndRequestA' -Namespace Win32 -PassThru
# $api::HttpEndRequestA(hRequest, lpBuffersOut, dwFlags, dwContext)#uselib "WININET.dll"
#func global HttpEndRequestA "HttpEndRequestA" sptr, sptr, sptr, sptr
; HttpEndRequestA hRequest, varptr(lpBuffersOut), dwFlags, dwContext ; 戻り値は stat
; hRequest : void* -> "sptr"
; lpBuffersOut : INTERNET_BUFFERSA* optional, out -> "sptr"
; dwFlags : DWORD -> "sptr"
; dwContext : UINT_PTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "WININET.dll" #cfunc global HttpEndRequestA "HttpEndRequestA" sptr, var, int, sptr ; res = HttpEndRequestA(hRequest, lpBuffersOut, dwFlags, dwContext) ; hRequest : void* -> "sptr" ; lpBuffersOut : INTERNET_BUFFERSA* optional, out -> "var" ; dwFlags : DWORD -> "int" ; dwContext : UINT_PTR optional -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WININET.dll" #cfunc global HttpEndRequestA "HttpEndRequestA" sptr, sptr, int, sptr ; res = HttpEndRequestA(hRequest, varptr(lpBuffersOut), dwFlags, dwContext) ; hRequest : void* -> "sptr" ; lpBuffersOut : INTERNET_BUFFERSA* optional, out -> "sptr" ; dwFlags : DWORD -> "int" ; dwContext : UINT_PTR optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL HttpEndRequestA(void* hRequest, INTERNET_BUFFERSA* lpBuffersOut, DWORD dwFlags, UINT_PTR dwContext) #uselib "WININET.dll" #cfunc global HttpEndRequestA "HttpEndRequestA" intptr, var, int, intptr ; res = HttpEndRequestA(hRequest, lpBuffersOut, dwFlags, dwContext) ; hRequest : void* -> "intptr" ; lpBuffersOut : INTERNET_BUFFERSA* optional, out -> "var" ; dwFlags : DWORD -> "int" ; dwContext : UINT_PTR optional -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL HttpEndRequestA(void* hRequest, INTERNET_BUFFERSA* lpBuffersOut, DWORD dwFlags, UINT_PTR dwContext) #uselib "WININET.dll" #cfunc global HttpEndRequestA "HttpEndRequestA" intptr, intptr, int, intptr ; res = HttpEndRequestA(hRequest, varptr(lpBuffersOut), dwFlags, dwContext) ; hRequest : void* -> "intptr" ; lpBuffersOut : INTERNET_BUFFERSA* optional, out -> "intptr" ; dwFlags : DWORD -> "int" ; dwContext : UINT_PTR optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wininet = windows.NewLazySystemDLL("WININET.dll")
procHttpEndRequestA = wininet.NewProc("HttpEndRequestA")
)
// hRequest (void*), lpBuffersOut (INTERNET_BUFFERSA* optional, out), dwFlags (DWORD), dwContext (UINT_PTR optional)
r1, _, err := procHttpEndRequestA.Call(
uintptr(hRequest),
uintptr(lpBuffersOut),
uintptr(dwFlags),
uintptr(dwContext),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction HttpEndRequestA(
hRequest: Pointer; // void*
lpBuffersOut: Pointer; // INTERNET_BUFFERSA* optional, out
dwFlags: DWORD; // DWORD
dwContext: NativeUInt // UINT_PTR optional
): BOOL; stdcall;
external 'WININET.dll' name 'HttpEndRequestA';result := DllCall("WININET\HttpEndRequestA"
, "Ptr", hRequest ; void*
, "Ptr", lpBuffersOut ; INTERNET_BUFFERSA* optional, out
, "UInt", dwFlags ; DWORD
, "UPtr", dwContext ; UINT_PTR optional
, "Int") ; return: BOOL●HttpEndRequestA(hRequest, lpBuffersOut, dwFlags, dwContext) = DLL("WININET.dll", "bool HttpEndRequestA(void*, void*, dword, int)")
# 呼び出し: HttpEndRequestA(hRequest, lpBuffersOut, dwFlags, dwContext)
# hRequest : void* -> "void*"
# lpBuffersOut : INTERNET_BUFFERSA* optional, out -> "void*"
# dwFlags : DWORD -> "dword"
# dwContext : UINT_PTR optional -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "wininet" fn HttpEndRequestA(
hRequest: ?*anyopaque, // void*
lpBuffersOut: [*c]INTERNET_BUFFERSA, // INTERNET_BUFFERSA* optional, out
dwFlags: u32, // DWORD
dwContext: usize // UINT_PTR optional
) callconv(std.os.windows.WINAPI) i32;proc HttpEndRequestA(
hRequest: pointer, # void*
lpBuffersOut: ptr INTERNET_BUFFERSA, # INTERNET_BUFFERSA* optional, out
dwFlags: uint32, # DWORD
dwContext: uint # UINT_PTR optional
): int32 {.importc: "HttpEndRequestA", stdcall, dynlib: "WININET.dll".}pragma(lib, "wininet");
extern(Windows)
int HttpEndRequestA(
void* hRequest, // void*
INTERNET_BUFFERSA* lpBuffersOut, // INTERNET_BUFFERSA* optional, out
uint dwFlags, // DWORD
size_t dwContext // UINT_PTR optional
);ccall((:HttpEndRequestA, "WININET.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{INTERNET_BUFFERSA}, UInt32, Csize_t),
hRequest, lpBuffersOut, dwFlags, dwContext)
# hRequest : void* -> Ptr{Cvoid}
# lpBuffersOut : INTERNET_BUFFERSA* optional, out -> Ptr{INTERNET_BUFFERSA}
# dwFlags : DWORD -> UInt32
# dwContext : UINT_PTR optional -> Csize_t
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t HttpEndRequestA(
void* hRequest,
void* lpBuffersOut,
uint32_t dwFlags,
uintptr_t dwContext);
]]
local wininet = ffi.load("wininet")
-- wininet.HttpEndRequestA(hRequest, lpBuffersOut, dwFlags, dwContext)
-- hRequest : void*
-- lpBuffersOut : INTERNET_BUFFERSA* optional, out
-- dwFlags : DWORD
-- dwContext : UINT_PTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WININET.dll');
const HttpEndRequestA = lib.func('__stdcall', 'HttpEndRequestA', 'int32_t', ['void *', 'void *', 'uint32_t', 'uintptr_t']);
// HttpEndRequestA(hRequest, lpBuffersOut, dwFlags, dwContext)
// hRequest : void* -> 'void *'
// lpBuffersOut : INTERNET_BUFFERSA* optional, out -> 'void *'
// dwFlags : DWORD -> 'uint32_t'
// dwContext : UINT_PTR optional -> 'uintptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WININET.dll", {
HttpEndRequestA: { parameters: ["pointer", "pointer", "u32", "usize"], result: "i32" },
});
// lib.symbols.HttpEndRequestA(hRequest, lpBuffersOut, dwFlags, dwContext)
// hRequest : void* -> "pointer"
// lpBuffersOut : INTERNET_BUFFERSA* optional, out -> "pointer"
// dwFlags : DWORD -> "u32"
// dwContext : UINT_PTR optional -> "usize"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t HttpEndRequestA(
void* hRequest,
void* lpBuffersOut,
uint32_t dwFlags,
size_t dwContext);
C, "WININET.dll");
// $ffi->HttpEndRequestA(hRequest, lpBuffersOut, dwFlags, dwContext);
// hRequest : void*
// lpBuffersOut : INTERNET_BUFFERSA* optional, out
// dwFlags : DWORD
// dwContext : UINT_PTR optional
// 構造体/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 Wininet extends StdCallLibrary {
Wininet INSTANCE = Native.load("wininet", Wininet.class, W32APIOptions.ASCII_OPTIONS);
boolean HttpEndRequestA(
Pointer hRequest, // void*
Pointer lpBuffersOut, // INTERNET_BUFFERSA* optional, out
int dwFlags, // DWORD
long dwContext // UINT_PTR optional
);
}@[Link("wininet")]
lib LibWININET
fun HttpEndRequestA = HttpEndRequestA(
hRequest : Void*, # void*
lpBuffersOut : INTERNET_BUFFERSA*, # INTERNET_BUFFERSA* optional, out
dwFlags : UInt32, # DWORD
dwContext : LibC::SizeT # UINT_PTR optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef HttpEndRequestANative = Int32 Function(Pointer<Void>, Pointer<Void>, Uint32, UintPtr);
typedef HttpEndRequestADart = int Function(Pointer<Void>, Pointer<Void>, int, int);
final HttpEndRequestA = DynamicLibrary.open('WININET.dll')
.lookupFunction<HttpEndRequestANative, HttpEndRequestADart>('HttpEndRequestA');
// hRequest : void* -> Pointer<Void>
// lpBuffersOut : INTERNET_BUFFERSA* optional, out -> Pointer<Void>
// dwFlags : DWORD -> Uint32
// dwContext : UINT_PTR optional -> UintPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function HttpEndRequestA(
hRequest: Pointer; // void*
lpBuffersOut: Pointer; // INTERNET_BUFFERSA* optional, out
dwFlags: DWORD; // DWORD
dwContext: NativeUInt // UINT_PTR optional
): BOOL; stdcall;
external 'WININET.dll' name 'HttpEndRequestA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "HttpEndRequestA"
c_HttpEndRequestA :: Ptr () -> Ptr () -> Word32 -> CUIntPtr -> IO CInt
-- hRequest : void* -> Ptr ()
-- lpBuffersOut : INTERNET_BUFFERSA* optional, out -> Ptr ()
-- dwFlags : DWORD -> Word32
-- dwContext : UINT_PTR optional -> CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let httpendrequesta =
foreign "HttpEndRequestA"
((ptr void) @-> (ptr void) @-> uint32_t @-> size_t @-> returning int32_t)
(* hRequest : void* -> (ptr void) *)
(* lpBuffersOut : INTERNET_BUFFERSA* optional, out -> (ptr void) *)
(* dwFlags : DWORD -> uint32_t *)
(* dwContext : UINT_PTR optional -> size_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library wininet (t "WININET.dll"))
(cffi:use-foreign-library wininet)
(cffi:defcfun ("HttpEndRequestA" http-end-request-a :convention :stdcall) :int32
(h-request :pointer) ; void*
(lp-buffers-out :pointer) ; INTERNET_BUFFERSA* optional, out
(dw-flags :uint32) ; DWORD
(dw-context :uint64)) ; UINT_PTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $HttpEndRequestA = Win32::API::More->new('WININET',
'BOOL HttpEndRequestA(LPVOID hRequest, LPVOID lpBuffersOut, DWORD dwFlags, WPARAM dwContext)');
# my $ret = $HttpEndRequestA->Call($hRequest, $lpBuffersOut, $dwFlags, $dwContext);
# hRequest : void* -> LPVOID
# lpBuffersOut : INTERNET_BUFFERSA* optional, out -> LPVOID
# dwFlags : DWORD -> DWORD
# dwContext : UINT_PTR optional -> WPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f HttpEndRequestW (Unicode版) — HttpSendRequestExで開始したHTTP要求を完了させる(Unicode版)。
使用する型