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

InternetWriteFile

関数
開いたインターネットハンドルにデータを書き込む。
DLLWININET.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL InternetWriteFile(
    void* hFile,
    const void* lpBuffer,
    DWORD dwNumberOfBytesToWrite,
    DWORD* lpdwNumberOfBytesWritten
);

パラメーター

名前方向
hFilevoid*in
lpBuffervoid*in
dwNumberOfBytesToWriteDWORDin
lpdwNumberOfBytesWrittenDWORD*out

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL InternetWriteFile(
    void* hFile,
    const void* lpBuffer,
    DWORD dwNumberOfBytesToWrite,
    DWORD* lpdwNumberOfBytesWritten
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", SetLastError = true, ExactSpelling = true)]
static extern bool InternetWriteFile(
    IntPtr hFile,   // void*
    IntPtr lpBuffer,   // void*
    uint dwNumberOfBytesToWrite,   // DWORD
    out uint lpdwNumberOfBytesWritten   // DWORD* out
);
<DllImport("WININET.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function InternetWriteFile(
    hFile As IntPtr,   ' void*
    lpBuffer As IntPtr,   ' void*
    dwNumberOfBytesToWrite As UInteger,   ' DWORD
    <Out> ByRef lpdwNumberOfBytesWritten As UInteger   ' DWORD* out
) As Boolean
End Function
' hFile : void*
' lpBuffer : void*
' dwNumberOfBytesToWrite : DWORD
' lpdwNumberOfBytesWritten : DWORD* out
Declare PtrSafe Function InternetWriteFile Lib "wininet" ( _
    ByVal hFile 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

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

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

var (
	wininet = windows.NewLazySystemDLL("WININET.dll")
	procInternetWriteFile = wininet.NewProc("InternetWriteFile")
)

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