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

InternetReadFile

関数
開いたインターネットハンドルからデータを読み取る。
DLLWININET.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL InternetReadFile(
    void* hFile,
    void* lpBuffer,
    DWORD dwNumberOfBytesToRead,
    DWORD* lpdwNumberOfBytesRead
);

パラメーター

名前方向
hFilevoid*in
lpBuffervoid*out
dwNumberOfBytesToReadDWORDin
lpdwNumberOfBytesReadDWORD*out

戻り値の型: BOOL

各言語での呼び出し定義

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

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

InternetReadFile = ctypes.windll.wininet.InternetReadFile
InternetReadFile.restype = wintypes.BOOL
InternetReadFile.argtypes = [
    ctypes.POINTER(None),  # hFile : void*
    ctypes.POINTER(None),  # lpBuffer : void* out
    wintypes.DWORD,  # dwNumberOfBytesToRead : DWORD
    ctypes.POINTER(wintypes.DWORD),  # lpdwNumberOfBytesRead : DWORD* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WININET.dll')
InternetReadFile = Fiddle::Function.new(
  lib['InternetReadFile'],
  [
    Fiddle::TYPE_VOIDP,  # hFile : void*
    Fiddle::TYPE_VOIDP,  # lpBuffer : void* out
    -Fiddle::TYPE_INT,  # dwNumberOfBytesToRead : DWORD
    Fiddle::TYPE_VOIDP,  # lpdwNumberOfBytesRead : DWORD* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "wininet")]
extern "system" {
    fn InternetReadFile(
        hFile: *mut (),  // void*
        lpBuffer: *mut (),  // void* out
        dwNumberOfBytesToRead: u32,  // DWORD
        lpdwNumberOfBytesRead: *mut u32  // DWORD* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", SetLastError = true)]
public static extern bool InternetReadFile(IntPtr hFile, IntPtr lpBuffer, uint dwNumberOfBytesToRead, out uint lpdwNumberOfBytesRead);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_InternetReadFile' -Namespace Win32 -PassThru
# $api::InternetReadFile(hFile, lpBuffer, dwNumberOfBytesToRead, lpdwNumberOfBytesRead)
#uselib "WININET.dll"
#func global InternetReadFile "InternetReadFile" sptr, sptr, sptr, sptr
; InternetReadFile hFile, lpBuffer, dwNumberOfBytesToRead, varptr(lpdwNumberOfBytesRead)   ; 戻り値は stat
; hFile : void* -> "sptr"
; lpBuffer : void* out -> "sptr"
; dwNumberOfBytesToRead : DWORD -> "sptr"
; lpdwNumberOfBytesRead : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WININET.dll"
#cfunc global InternetReadFile "InternetReadFile" sptr, sptr, int, var
; res = InternetReadFile(hFile, lpBuffer, dwNumberOfBytesToRead, lpdwNumberOfBytesRead)
; hFile : void* -> "sptr"
; lpBuffer : void* out -> "sptr"
; dwNumberOfBytesToRead : DWORD -> "int"
; lpdwNumberOfBytesRead : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL InternetReadFile(void* hFile, void* lpBuffer, DWORD dwNumberOfBytesToRead, DWORD* lpdwNumberOfBytesRead)
#uselib "WININET.dll"
#cfunc global InternetReadFile "InternetReadFile" intptr, intptr, int, var
; res = InternetReadFile(hFile, lpBuffer, dwNumberOfBytesToRead, lpdwNumberOfBytesRead)
; hFile : void* -> "intptr"
; lpBuffer : void* out -> "intptr"
; dwNumberOfBytesToRead : DWORD -> "int"
; lpdwNumberOfBytesRead : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wininet = windows.NewLazySystemDLL("WININET.dll")
	procInternetReadFile = wininet.NewProc("InternetReadFile")
)

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