InternetGetLastResponseInfoA
関数シグネチャ
// WININET.dll (ANSI / -A)
#include <windows.h>
BOOL InternetGetLastResponseInfoA(
DWORD* lpdwError,
LPSTR lpszBuffer, // optional
DWORD* lpdwBufferLength
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpdwError | DWORD* | out | 失敗した操作に関するエラーメッセージを受け取る変数へのポインターです。 |
| lpszBuffer | LPSTR | outoptional | エラーテキストを受け取るバッファーへのポインターです。 |
| lpdwBufferLength | DWORD* | inout | lpszBuffer バッファーのサイズを TCHAR 単位で格納する変数へのポインターです。関数が戻ると、このパラメーターにはバッファーへ書き込まれた文字列のサイズ(終端のゼロを含まない)が格納されます。 |
戻り値の型: BOOL
公式ドキュメント
この関数を呼び出したスレッドにおける、直近のエラーの説明またはサーバー応答を取得します。(ANSI)
戻り値
エラーテキストがバッファーへ正常に書き込まれた場合は TRUE を、それ以外の場合は FALSE を返します。拡張エラー情報を取得するには、 GetLastError を呼び出してください。バッファーがすべてのエラーテキストを保持するには小さすぎる場合、 GetLastError は ERROR_INSUFFICIENT_BUFFER を返し、 lpdwBufferLength パラメーターにはすべてのエラーテキストを返すために必要な最小バッファーサイズが格納されます。
解説(Remarks)
FTP プロトコルは、ほとんどのエラーに加えて追加のテキスト情報を返すことがあります。この拡張エラー情報は、 GetLastError が(関数呼び出しの失敗後に) ERROR_INTERNET_EXTENDED_ERROR を返したときに、 InternetGetLastResponseInfo 関数を使用して取得できます。
lpszBuffer が指すバッファーは、エラー文字列と文字列末尾のゼロ終端の両方を保持できる十分な大きさが必要です。ただし、 lpdwBufferLength に返される値には終端のゼロが含まれない点に注意してください。
InternetGetLastResponseInfo は、このスレッドで別の関数が呼び出されるまで複数回呼び出すことができます。別の関数が呼び出されると、直近の応答情報を格納している内部バッファーはクリアされます。
WinINet API の他のすべての側面と同様に、この関数は DllMain や、グローバルオブジェクトのコンストラクター/デストラクター内から安全に呼び出すことはできません。
wininet.h ヘッダーは、InternetGetLastResponseInfo を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義しています。エンコーディング中立なエイリアスの使用と、エンコーディング中立でないコードを混在させると、不一致が生じ、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、関数プロトタイプの規約を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// WININET.dll (ANSI / -A)
#include <windows.h>
BOOL InternetGetLastResponseInfoA(
DWORD* lpdwError,
LPSTR lpszBuffer, // optional
DWORD* lpdwBufferLength
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool InternetGetLastResponseInfoA(
out uint lpdwError, // DWORD* out
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpszBuffer, // LPSTR optional, out
ref uint lpdwBufferLength // DWORD* in/out
);<DllImport("WININET.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function InternetGetLastResponseInfoA(
<Out> ByRef lpdwError As UInteger, ' DWORD* out
<MarshalAs(UnmanagedType.LPStr)> lpszBuffer As System.Text.StringBuilder, ' LPSTR optional, out
ByRef lpdwBufferLength As UInteger ' DWORD* in/out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' lpdwError : DWORD* out
' lpszBuffer : LPSTR optional, out
' lpdwBufferLength : DWORD* in/out
Declare PtrSafe Function InternetGetLastResponseInfoA Lib "wininet" ( _
ByRef lpdwError As Long, _
ByVal lpszBuffer As String, _
ByRef lpdwBufferLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
InternetGetLastResponseInfoA = ctypes.windll.wininet.InternetGetLastResponseInfoA
InternetGetLastResponseInfoA.restype = wintypes.BOOL
InternetGetLastResponseInfoA.argtypes = [
ctypes.POINTER(wintypes.DWORD), # lpdwError : DWORD* out
wintypes.LPSTR, # lpszBuffer : LPSTR optional, out
ctypes.POINTER(wintypes.DWORD), # lpdwBufferLength : DWORD* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WININET.dll')
InternetGetLastResponseInfoA = Fiddle::Function.new(
lib['InternetGetLastResponseInfoA'],
[
Fiddle::TYPE_VOIDP, # lpdwError : DWORD* out
Fiddle::TYPE_VOIDP, # lpszBuffer : LPSTR optional, out
Fiddle::TYPE_VOIDP, # lpdwBufferLength : DWORD* in/out
],
Fiddle::TYPE_INT)#[link(name = "wininet")]
extern "system" {
fn InternetGetLastResponseInfoA(
lpdwError: *mut u32, // DWORD* out
lpszBuffer: *mut u8, // LPSTR optional, out
lpdwBufferLength: *mut u32 // DWORD* in/out
) -> 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 InternetGetLastResponseInfoA(out uint lpdwError, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpszBuffer, ref uint lpdwBufferLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_InternetGetLastResponseInfoA' -Namespace Win32 -PassThru
# $api::InternetGetLastResponseInfoA(lpdwError, lpszBuffer, lpdwBufferLength)#uselib "WININET.dll"
#func global InternetGetLastResponseInfoA "InternetGetLastResponseInfoA" sptr, sptr, sptr
; InternetGetLastResponseInfoA varptr(lpdwError), varptr(lpszBuffer), varptr(lpdwBufferLength) ; 戻り値は stat
; lpdwError : DWORD* out -> "sptr"
; lpszBuffer : LPSTR optional, out -> "sptr"
; lpdwBufferLength : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WININET.dll" #cfunc global InternetGetLastResponseInfoA "InternetGetLastResponseInfoA" var, var, var ; res = InternetGetLastResponseInfoA(lpdwError, lpszBuffer, lpdwBufferLength) ; lpdwError : DWORD* out -> "var" ; lpszBuffer : LPSTR optional, out -> "var" ; lpdwBufferLength : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WININET.dll" #cfunc global InternetGetLastResponseInfoA "InternetGetLastResponseInfoA" sptr, sptr, sptr ; res = InternetGetLastResponseInfoA(varptr(lpdwError), varptr(lpszBuffer), varptr(lpdwBufferLength)) ; lpdwError : DWORD* out -> "sptr" ; lpszBuffer : LPSTR optional, out -> "sptr" ; lpdwBufferLength : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; BOOL InternetGetLastResponseInfoA(DWORD* lpdwError, LPSTR lpszBuffer, DWORD* lpdwBufferLength) #uselib "WININET.dll" #cfunc global InternetGetLastResponseInfoA "InternetGetLastResponseInfoA" var, var, var ; res = InternetGetLastResponseInfoA(lpdwError, lpszBuffer, lpdwBufferLength) ; lpdwError : DWORD* out -> "var" ; lpszBuffer : LPSTR optional, out -> "var" ; lpdwBufferLength : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL InternetGetLastResponseInfoA(DWORD* lpdwError, LPSTR lpszBuffer, DWORD* lpdwBufferLength) #uselib "WININET.dll" #cfunc global InternetGetLastResponseInfoA "InternetGetLastResponseInfoA" intptr, intptr, intptr ; res = InternetGetLastResponseInfoA(varptr(lpdwError), varptr(lpszBuffer), varptr(lpdwBufferLength)) ; lpdwError : DWORD* out -> "intptr" ; lpszBuffer : LPSTR optional, out -> "intptr" ; lpdwBufferLength : DWORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wininet = windows.NewLazySystemDLL("WININET.dll")
procInternetGetLastResponseInfoA = wininet.NewProc("InternetGetLastResponseInfoA")
)
// lpdwError (DWORD* out), lpszBuffer (LPSTR optional, out), lpdwBufferLength (DWORD* in/out)
r1, _, err := procInternetGetLastResponseInfoA.Call(
uintptr(lpdwError),
uintptr(lpszBuffer),
uintptr(lpdwBufferLength),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction InternetGetLastResponseInfoA(
lpdwError: Pointer; // DWORD* out
lpszBuffer: PAnsiChar; // LPSTR optional, out
lpdwBufferLength: Pointer // DWORD* in/out
): BOOL; stdcall;
external 'WININET.dll' name 'InternetGetLastResponseInfoA';result := DllCall("WININET\InternetGetLastResponseInfoA"
, "Ptr", lpdwError ; DWORD* out
, "Ptr", lpszBuffer ; LPSTR optional, out
, "Ptr", lpdwBufferLength ; DWORD* in/out
, "Int") ; return: BOOL●InternetGetLastResponseInfoA(lpdwError, lpszBuffer, lpdwBufferLength) = DLL("WININET.dll", "bool InternetGetLastResponseInfoA(void*, char*, void*)")
# 呼び出し: InternetGetLastResponseInfoA(lpdwError, lpszBuffer, lpdwBufferLength)
# lpdwError : DWORD* out -> "void*"
# lpszBuffer : LPSTR optional, out -> "char*"
# lpdwBufferLength : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "wininet" fn InternetGetLastResponseInfoA(
lpdwError: [*c]u32, // DWORD* out
lpszBuffer: [*c]u8, // LPSTR optional, out
lpdwBufferLength: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) i32;proc InternetGetLastResponseInfoA(
lpdwError: ptr uint32, # DWORD* out
lpszBuffer: ptr char, # LPSTR optional, out
lpdwBufferLength: ptr uint32 # DWORD* in/out
): int32 {.importc: "InternetGetLastResponseInfoA", stdcall, dynlib: "WININET.dll".}pragma(lib, "wininet");
extern(Windows)
int InternetGetLastResponseInfoA(
uint* lpdwError, // DWORD* out
char* lpszBuffer, // LPSTR optional, out
uint* lpdwBufferLength // DWORD* in/out
);ccall((:InternetGetLastResponseInfoA, "WININET.dll"), stdcall, Int32,
(Ptr{UInt32}, Ptr{UInt8}, Ptr{UInt32}),
lpdwError, lpszBuffer, lpdwBufferLength)
# lpdwError : DWORD* out -> Ptr{UInt32}
# lpszBuffer : LPSTR optional, out -> Ptr{UInt8}
# lpdwBufferLength : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t InternetGetLastResponseInfoA(
uint32_t* lpdwError,
char* lpszBuffer,
uint32_t* lpdwBufferLength);
]]
local wininet = ffi.load("wininet")
-- wininet.InternetGetLastResponseInfoA(lpdwError, lpszBuffer, lpdwBufferLength)
-- lpdwError : DWORD* out
-- lpszBuffer : LPSTR optional, out
-- lpdwBufferLength : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WININET.dll');
const InternetGetLastResponseInfoA = lib.func('__stdcall', 'InternetGetLastResponseInfoA', 'int32_t', ['uint32_t *', 'char *', 'uint32_t *']);
// InternetGetLastResponseInfoA(lpdwError, lpszBuffer, lpdwBufferLength)
// lpdwError : DWORD* out -> 'uint32_t *'
// lpszBuffer : LPSTR optional, out -> 'char *'
// lpdwBufferLength : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WININET.dll", {
InternetGetLastResponseInfoA: { parameters: ["pointer", "buffer", "pointer"], result: "i32" },
});
// lib.symbols.InternetGetLastResponseInfoA(lpdwError, lpszBuffer, lpdwBufferLength)
// lpdwError : DWORD* out -> "pointer"
// lpszBuffer : LPSTR optional, out -> "buffer"
// lpdwBufferLength : DWORD* in/out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t InternetGetLastResponseInfoA(
uint32_t* lpdwError,
char* lpszBuffer,
uint32_t* lpdwBufferLength);
C, "WININET.dll");
// $ffi->InternetGetLastResponseInfoA(lpdwError, lpszBuffer, lpdwBufferLength);
// lpdwError : DWORD* out
// lpszBuffer : LPSTR optional, out
// lpdwBufferLength : DWORD* in/out
// 構造体/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 InternetGetLastResponseInfoA(
IntByReference lpdwError, // DWORD* out
byte[] lpszBuffer, // LPSTR optional, out
IntByReference lpdwBufferLength // DWORD* in/out
);
}@[Link("wininet")]
lib LibWININET
fun InternetGetLastResponseInfoA = InternetGetLastResponseInfoA(
lpdwError : UInt32*, # DWORD* out
lpszBuffer : UInt8*, # LPSTR optional, out
lpdwBufferLength : UInt32* # DWORD* in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef InternetGetLastResponseInfoANative = Int32 Function(Pointer<Uint32>, Pointer<Utf8>, Pointer<Uint32>);
typedef InternetGetLastResponseInfoADart = int Function(Pointer<Uint32>, Pointer<Utf8>, Pointer<Uint32>);
final InternetGetLastResponseInfoA = DynamicLibrary.open('WININET.dll')
.lookupFunction<InternetGetLastResponseInfoANative, InternetGetLastResponseInfoADart>('InternetGetLastResponseInfoA');
// lpdwError : DWORD* out -> Pointer<Uint32>
// lpszBuffer : LPSTR optional, out -> Pointer<Utf8>
// lpdwBufferLength : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function InternetGetLastResponseInfoA(
lpdwError: Pointer; // DWORD* out
lpszBuffer: PAnsiChar; // LPSTR optional, out
lpdwBufferLength: Pointer // DWORD* in/out
): BOOL; stdcall;
external 'WININET.dll' name 'InternetGetLastResponseInfoA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "InternetGetLastResponseInfoA"
c_InternetGetLastResponseInfoA :: Ptr Word32 -> CString -> Ptr Word32 -> IO CInt
-- lpdwError : DWORD* out -> Ptr Word32
-- lpszBuffer : LPSTR optional, out -> CString
-- lpdwBufferLength : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let internetgetlastresponseinfoa =
foreign "InternetGetLastResponseInfoA"
((ptr uint32_t) @-> string @-> (ptr uint32_t) @-> returning int32_t)
(* lpdwError : DWORD* out -> (ptr uint32_t) *)
(* lpszBuffer : LPSTR optional, out -> string *)
(* lpdwBufferLength : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library wininet (t "WININET.dll"))
(cffi:use-foreign-library wininet)
(cffi:defcfun ("InternetGetLastResponseInfoA" internet-get-last-response-info-a :convention :stdcall) :int32
(lpdw-error :pointer) ; DWORD* out
(lpsz-buffer :pointer) ; LPSTR optional, out
(lpdw-buffer-length :pointer)) ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $InternetGetLastResponseInfoA = Win32::API::More->new('WININET',
'BOOL InternetGetLastResponseInfoA(LPVOID lpdwError, LPSTR lpszBuffer, LPVOID lpdwBufferLength)');
# my $ret = $InternetGetLastResponseInfoA->Call($lpdwError, $lpszBuffer, $lpdwBufferLength);
# lpdwError : DWORD* out -> LPVOID
# lpszBuffer : LPSTR optional, out -> LPSTR
# lpdwBufferLength : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f InternetGetLastResponseInfoW (Unicode版) — 直近のWinINet操作のエラー応答テキストを取得する(Unicode版)。