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

_lread

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

シグネチャ

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

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

パラメーター

名前方向説明
hFileINTin読み取り元のファイルハンドル(_lopen等で取得)。
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)。
const std = @import("std");

extern "kernel32" fn _lread(
    hFile: i32, // INT
    lpBuffer: ?*anyopaque, // void* out
    uBytes: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
proc _lread(
    hFile: int32,  # INT
    lpBuffer: pointer,  # void* out
    uBytes: uint32  # DWORD
): uint32 {.importc: "_lread", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
uint _lread(
    int hFile,   // INT
    void* lpBuffer,   // void* out
    uint uBytes   // DWORD
);
ccall((:_lread, "KERNEL32.dll"), stdcall, UInt32,
      (Int32, Ptr{Cvoid}, UInt32),
      hFile, lpBuffer, uBytes)
# hFile : INT -> Int32
# lpBuffer : void* out -> Ptr{Cvoid}
# uBytes : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t _lread(
    int32_t hFile,
    void* lpBuffer,
    uint32_t uBytes);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32._lread(hFile, lpBuffer, uBytes)
-- hFile : INT
-- lpBuffer : void* out
-- uBytes : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const _lread = lib.func('__stdcall', '_lread', 'uint32_t', ['int32_t', 'void *', 'uint32_t']);
// _lread(hFile, lpBuffer, uBytes)
// hFile : INT -> 'int32_t'
// lpBuffer : void* out -> 'void *'
// uBytes : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  _lread: { parameters: ["i32", "pointer", "u32"], result: "u32" },
});
// lib.symbols._lread(hFile, lpBuffer, uBytes)
// hFile : INT -> "i32"
// lpBuffer : void* out -> "pointer"
// uBytes : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t _lread(
    int32_t hFile,
    void* lpBuffer,
    uint32_t uBytes);
C, "KERNEL32.dll");
// $ffi->_lread(hFile, lpBuffer, uBytes);
// hFile : INT
// lpBuffer : void* out
// uBytes : DWORD
// 構造体/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 Kernel32 extends StdCallLibrary {
    Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
    int _lread(
        int hFile,   // INT
        Pointer lpBuffer,   // void* out
        int uBytes   // DWORD
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun _lread = _lread(
    hFile : Int32,   # INT
    lpBuffer : Void*,   # void* out
    uBytes : UInt32   # DWORD
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef _lreadNative = Uint32 Function(Int32, Pointer<Void>, Uint32);
typedef _lreadDart = int Function(int, Pointer<Void>, int);
final _lread = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<_lreadNative, _lreadDart>('_lread');
// hFile : INT -> Int32
// lpBuffer : void* out -> Pointer<Void>
// uBytes : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function _lread(
  hFile: Integer;   // INT
  lpBuffer: Pointer;   // void* out
  uBytes: DWORD   // DWORD
): DWORD; stdcall;
  external 'KERNEL32.dll' name '_lread';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "_lread"
  c__lread :: Int32 -> Ptr () -> Word32 -> IO Word32
-- hFile : INT -> Int32
-- lpBuffer : void* out -> Ptr ()
-- uBytes : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let _lread =
  foreign "_lread"
    (int32_t @-> (ptr void) @-> uint32_t @-> returning uint32_t)
(* hFile : INT -> int32_t *)
(* lpBuffer : void* out -> (ptr void) *)
(* uBytes : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("_lread" -lread :convention :stdcall) :uint32
  (h-file :int32)   ; INT
  (lp-buffer :pointer)   ; void* out
  (u-bytes :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $_lread = Win32::API::More->new('KERNEL32',
    'DWORD _lread(int hFile, LPVOID lpBuffer, DWORD uBytes)');
# my $ret = $_lread->Call($hFile, $lpBuffer, $uBytes);
# hFile : INT -> int
# lpBuffer : void* out -> LPVOID
# uBytes : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。