ホーム › Storage.FileSystem › LZRead
LZRead
関数LZ圧縮ファイルから展開したデータを読み取る。
シグネチャ
// KERNEL32.dll
#include <windows.h>
INT LZRead(
INT hFile,
LPSTR lpBuffer,
INT cbRead
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hFile | INT | in | ファイルへのハンドル。 |
| lpBuffer | LPSTR | out | ファイルから読み取ったバイトを受け取るバッファーへのポインター。このバッファーが cbRead より大きいことを確認してください。 |
| cbRead | INT | in | 読み取るバイト数。 |
戻り値の型: INT
公式ドキュメント
ファイルから指定されたバイト数(最大)を読み取り、バッファーにコピーします。
戻り値
関数が成功した場合、戻り値は読み取られたバイト数を示します。
関数が失敗した場合、戻り値は LZERROR_* コードです。これらのコードは 0 より小さい値を持ちます。なお、 LZRead は SetLastError も SetLastErrorEx も呼び出しません。したがって、その失敗はスレッドの最終エラーコードに影響しません。
以下は、 LZRead が失敗時に返すことのできるエラーコードの一覧です。
| 戻り値コード | 説明 |
|---|---|
| ソースファイルを識別するハンドルが無効です。ファイルを読み取れません。 | |
| 出力先ファイルを識別するハンドルが無効です。ファイルに書き込めません。 | |
| 入力パラメーターのいずれかが無効です。 | |
| 開いている圧縮ファイルの最大数を超えたか、ローカルメモリを割り当てられません。 | |
| LZ ファイルハンドルをロックできません。 | |
| ソースファイルの形式が無効です。 | |
| 出力ファイル用の空き領域が不足しています。 |
この関数には拡張エラー情報はありません。GetLastError を呼び出さないでください。
解説(Remarks)
ファイルを識別するハンドルは、 LZInit 関数または LZOpenFile 関数のいずれかを呼び出して取得する必要があります。
ファイルが圧縮されている場合、 LZRead はファイルの展開イメージに対して動作し、データのバイトを指定されたバッファーにコピーします。
Windows 8 および Windows Server 2012 では、この関数は次のテクノロジによってサポートされています。
| テクノロジ | サポート |
|---|---|
| Server Message Block (SMB) 3.0 プロトコル | はい |
| SMB 3.0 透過的フェールオーバー (TFO) | はい |
| SMB 3.0 スケールアウトファイル共有 (SO) | はい |
| クラスター共有ボリュームファイルシステム (CsvFS) | はい |
| 復元性ファイルシステム (ReFS) | はい |
CsvFs は圧縮ファイルに対してリダイレクト IO を実行します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
INT LZRead(
INT hFile,
LPSTR lpBuffer,
INT cbRead
);[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern int LZRead(
int hFile, // INT
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpBuffer, // LPSTR out
int cbRead // INT
);<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function LZRead(
hFile As Integer, ' INT
<MarshalAs(UnmanagedType.LPStr)> lpBuffer As System.Text.StringBuilder, ' LPSTR out
cbRead As Integer ' INT
) As Integer
End Function' hFile : INT
' lpBuffer : LPSTR out
' cbRead : INT
Declare PtrSafe Function LZRead Lib "kernel32" ( _
ByVal hFile As Long, _
ByVal lpBuffer As String, _
ByVal cbRead As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
LZRead = ctypes.windll.kernel32.LZRead
LZRead.restype = ctypes.c_int
LZRead.argtypes = [
ctypes.c_int, # hFile : INT
wintypes.LPSTR, # lpBuffer : LPSTR out
ctypes.c_int, # cbRead : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
LZRead = Fiddle::Function.new(
lib['LZRead'],
[
Fiddle::TYPE_INT, # hFile : INT
Fiddle::TYPE_VOIDP, # lpBuffer : LPSTR out
Fiddle::TYPE_INT, # cbRead : INT
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn LZRead(
hFile: i32, // INT
lpBuffer: *mut u8, // LPSTR out
cbRead: i32 // INT
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll")]
public static extern int LZRead(int hFile, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpBuffer, int cbRead);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_LZRead' -Namespace Win32 -PassThru
# $api::LZRead(hFile, lpBuffer, cbRead)#uselib "KERNEL32.dll"
#func global LZRead "LZRead" sptr, sptr, sptr
; LZRead hFile, varptr(lpBuffer), cbRead ; 戻り値は stat
; hFile : INT -> "sptr"
; lpBuffer : LPSTR out -> "sptr"
; cbRead : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global LZRead "LZRead" int, var, int ; res = LZRead(hFile, lpBuffer, cbRead) ; hFile : INT -> "int" ; lpBuffer : LPSTR out -> "var" ; cbRead : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global LZRead "LZRead" int, sptr, int ; res = LZRead(hFile, varptr(lpBuffer), cbRead) ; hFile : INT -> "int" ; lpBuffer : LPSTR out -> "sptr" ; cbRead : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT LZRead(INT hFile, LPSTR lpBuffer, INT cbRead) #uselib "KERNEL32.dll" #cfunc global LZRead "LZRead" int, var, int ; res = LZRead(hFile, lpBuffer, cbRead) ; hFile : INT -> "int" ; lpBuffer : LPSTR out -> "var" ; cbRead : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT LZRead(INT hFile, LPSTR lpBuffer, INT cbRead) #uselib "KERNEL32.dll" #cfunc global LZRead "LZRead" int, intptr, int ; res = LZRead(hFile, varptr(lpBuffer), cbRead) ; hFile : INT -> "int" ; lpBuffer : LPSTR out -> "intptr" ; cbRead : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procLZRead = kernel32.NewProc("LZRead")
)
// hFile (INT), lpBuffer (LPSTR out), cbRead (INT)
r1, _, err := procLZRead.Call(
uintptr(hFile),
uintptr(lpBuffer),
uintptr(cbRead),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction LZRead(
hFile: Integer; // INT
lpBuffer: PAnsiChar; // LPSTR out
cbRead: Integer // INT
): Integer; stdcall;
external 'KERNEL32.dll' name 'LZRead';result := DllCall("KERNEL32\LZRead"
, "Int", hFile ; INT
, "Ptr", lpBuffer ; LPSTR out
, "Int", cbRead ; INT
, "Int") ; return: INT●LZRead(hFile, lpBuffer, cbRead) = DLL("KERNEL32.dll", "int LZRead(int, char*, int)")
# 呼び出し: LZRead(hFile, lpBuffer, cbRead)
# hFile : INT -> "int"
# lpBuffer : LPSTR out -> "char*"
# cbRead : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "kernel32" fn LZRead(
hFile: i32, // INT
lpBuffer: [*c]u8, // LPSTR out
cbRead: i32 // INT
) callconv(std.os.windows.WINAPI) i32;proc LZRead(
hFile: int32, # INT
lpBuffer: ptr char, # LPSTR out
cbRead: int32 # INT
): int32 {.importc: "LZRead", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
int LZRead(
int hFile, // INT
char* lpBuffer, // LPSTR out
int cbRead // INT
);ccall((:LZRead, "KERNEL32.dll"), stdcall, Int32,
(Int32, Ptr{UInt8}, Int32),
hFile, lpBuffer, cbRead)
# hFile : INT -> Int32
# lpBuffer : LPSTR out -> Ptr{UInt8}
# cbRead : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t LZRead(
int32_t hFile,
char* lpBuffer,
int32_t cbRead);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.LZRead(hFile, lpBuffer, cbRead)
-- hFile : INT
-- lpBuffer : LPSTR out
-- cbRead : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const LZRead = lib.func('__stdcall', 'LZRead', 'int32_t', ['int32_t', 'char *', 'int32_t']);
// LZRead(hFile, lpBuffer, cbRead)
// hFile : INT -> 'int32_t'
// lpBuffer : LPSTR out -> 'char *'
// cbRead : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
LZRead: { parameters: ["i32", "buffer", "i32"], result: "i32" },
});
// lib.symbols.LZRead(hFile, lpBuffer, cbRead)
// hFile : INT -> "i32"
// lpBuffer : LPSTR out -> "buffer"
// cbRead : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t LZRead(
int32_t hFile,
char* lpBuffer,
int32_t cbRead);
C, "KERNEL32.dll");
// $ffi->LZRead(hFile, lpBuffer, cbRead);
// hFile : INT
// lpBuffer : LPSTR out
// cbRead : INT
// 構造体/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 LZRead(
int hFile, // INT
byte[] lpBuffer, // LPSTR out
int cbRead // INT
);
}@[Link("kernel32")]
lib LibKERNEL32
fun LZRead = LZRead(
hFile : Int32, # INT
lpBuffer : UInt8*, # LPSTR out
cbRead : Int32 # INT
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef LZReadNative = Int32 Function(Int32, Pointer<Utf8>, Int32);
typedef LZReadDart = int Function(int, Pointer<Utf8>, int);
final LZRead = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<LZReadNative, LZReadDart>('LZRead');
// hFile : INT -> Int32
// lpBuffer : LPSTR out -> Pointer<Utf8>
// cbRead : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function LZRead(
hFile: Integer; // INT
lpBuffer: PAnsiChar; // LPSTR out
cbRead: Integer // INT
): Integer; stdcall;
external 'KERNEL32.dll' name 'LZRead';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "LZRead"
c_LZRead :: Int32 -> CString -> Int32 -> IO Int32
-- hFile : INT -> Int32
-- lpBuffer : LPSTR out -> CString
-- cbRead : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let lzread =
foreign "LZRead"
(int32_t @-> string @-> int32_t @-> returning int32_t)
(* hFile : INT -> int32_t *)
(* lpBuffer : LPSTR out -> string *)
(* cbRead : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("LZRead" lzread :convention :stdcall) :int32
(h-file :int32) ; INT
(lp-buffer :pointer) ; LPSTR out
(cb-read :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $LZRead = Win32::API::More->new('KERNEL32',
'int LZRead(int hFile, LPSTR lpBuffer, int cbRead)');
# my $ret = $LZRead->Call($hFile, $lpBuffer, $cbRead);
# hFile : INT -> int
# lpBuffer : LPSTR out -> LPSTR
# cbRead : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f LZInit — LZ展開用にソースファイルを初期化する。
- f LZOpenFileW — LZ展開用にファイルを開く(Unicode版)。
- f LZSeek — LZ展開ファイル内のファイルポインタを移動する。