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

_lread

関数
ファイルから指定バイト数を読み込む旧式関数。
DLLKERNEL32.dll呼出規約winapi

シグネチャ

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

DWORD _lread(
    INT hFile,
    void* lpBuffer,
    DWORD uBytes
);

パラメーター

名前方向
hFileINTin
lpBuffervoid*out
uBytesDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD _lread(
    INT hFile,
    void* lpBuffer,
    DWORD uBytes
);
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern uint _lread(
    int hFile,   // INT
    IntPtr lpBuffer,   // void* out
    uint uBytes   // DWORD
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function _lread(
    hFile As Integer,   ' INT
    lpBuffer As IntPtr,   ' void* out
    uBytes As UInteger   ' DWORD
) As UInteger
End Function
' hFile : INT
' lpBuffer : void* out
' uBytes : DWORD
Declare PtrSafe Function _lread Lib "kernel32" ( _
    ByVal hFile As Long, _
    ByVal lpBuffer As LongPtr, _
    ByVal uBytes As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

_lread = ctypes.windll.kernel32._lread
_lread.restype = wintypes.DWORD
_lread.argtypes = [
    ctypes.c_int,  # hFile : INT
    ctypes.POINTER(None),  # lpBuffer : void* out
    wintypes.DWORD,  # uBytes : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	proc_lread = kernel32.NewProc("_lread")
)

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