Win32 API 日本語リファレンス
ホームSystem.WindowsProgramming › _hwrite

_hwrite

関数
ファイルへ大きなバイト数を書き込む旧式関数。
DLLKERNEL32.dll呼出規約winapi

シグネチャ

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

INT _hwrite(
    INT hFile,
    LPCSTR lpBuffer,
    INT lBytes
);

パラメーター

名前方向
hFileINTin
lpBufferLPCSTRin
lBytesINTin

戻り値の型: INT

各言語での呼び出し定義

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

INT _hwrite(
    INT hFile,
    LPCSTR lpBuffer,
    INT lBytes
);
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern int _hwrite(
    int hFile,   // INT
    [MarshalAs(UnmanagedType.LPStr)] string lpBuffer,   // LPCSTR
    int lBytes   // INT
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function _hwrite(
    hFile As Integer,   ' INT
    <MarshalAs(UnmanagedType.LPStr)> lpBuffer As String,   ' LPCSTR
    lBytes As Integer   ' INT
) As Integer
End Function
' hFile : INT
' lpBuffer : LPCSTR
' lBytes : INT
Declare PtrSafe Function _hwrite Lib "kernel32" ( _
    ByVal hFile As Long, _
    ByVal lpBuffer As String, _
    ByVal lBytes As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

_hwrite = ctypes.windll.kernel32._hwrite
_hwrite.restype = ctypes.c_int
_hwrite.argtypes = [
    ctypes.c_int,  # hFile : INT
    wintypes.LPCSTR,  # lpBuffer : LPCSTR
    ctypes.c_int,  # lBytes : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
_hwrite = Fiddle::Function.new(
  lib['_hwrite'],
  [
    Fiddle::TYPE_INT,  # hFile : INT
    Fiddle::TYPE_VOIDP,  # lpBuffer : LPCSTR
    Fiddle::TYPE_INT,  # lBytes : INT
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn _hwrite(
        hFile: i32,  // INT
        lpBuffer: *const u8,  // LPCSTR
        lBytes: i32  // INT
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll")]
public static extern int _hwrite(int hFile, [MarshalAs(UnmanagedType.LPStr)] string lpBuffer, int lBytes);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32__hwrite' -Namespace Win32 -PassThru
# $api::_hwrite(hFile, lpBuffer, lBytes)
#uselib "KERNEL32.dll"
#func global _hwrite "_hwrite" sptr, sptr, sptr
; _hwrite hFile, lpBuffer, lBytes   ; 戻り値は stat
; hFile : INT -> "sptr"
; lpBuffer : LPCSTR -> "sptr"
; lBytes : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global _hwrite "_hwrite" int, str, int
; res = _hwrite(hFile, lpBuffer, lBytes)
; hFile : INT -> "int"
; lpBuffer : LPCSTR -> "str"
; lBytes : INT -> "int"
; INT _hwrite(INT hFile, LPCSTR lpBuffer, INT lBytes)
#uselib "KERNEL32.dll"
#cfunc global _hwrite "_hwrite" int, str, int
; res = _hwrite(hFile, lpBuffer, lBytes)
; hFile : INT -> "int"
; lpBuffer : LPCSTR -> "str"
; lBytes : INT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	proc_hwrite = kernel32.NewProc("_hwrite")
)

// hFile (INT), lpBuffer (LPCSTR), lBytes (INT)
r1, _, err := proc_hwrite.Call(
	uintptr(hFile),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpBuffer))),
	uintptr(lBytes),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function _hwrite(
  hFile: Integer;   // INT
  lpBuffer: PAnsiChar;   // LPCSTR
  lBytes: Integer   // INT
): Integer; stdcall;
  external 'KERNEL32.dll' name '_hwrite';
result := DllCall("KERNEL32\_hwrite"
    , "Int", hFile   ; INT
    , "AStr", lpBuffer   ; LPCSTR
    , "Int", lBytes   ; INT
    , "Int")   ; return: INT
●_hwrite(hFile, lpBuffer, lBytes) = DLL("KERNEL32.dll", "int _hwrite(int, char*, int)")
# 呼び出し: _hwrite(hFile, lpBuffer, lBytes)
# hFile : INT -> "int"
# lpBuffer : LPCSTR -> "char*"
# lBytes : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。