LZOpenFile
VB聲明
Declare Function LZOpenFile Lib "lz32.dll" Alias "LZOpenFileA" (ByVal lpszFile As String, lpOf As OFSTRUCT, ByVal style As Long) As Long
說明
該函式能執行大量不同的檔案處理,而且兼容於壓縮檔案
返回值
Long,如函式執行成功,且樣式(style)參數不為OF_READ,就返回常規的檔案句柄,具體請參考OpenFile函式的說明。如樣式參數為OF_READ,而且檔案是壓縮的,就會返回一個特殊的檔案句柄,以便由LZCopy, LZRead 和 LZSeek函式使用。如出錯,返回如下表所示的一個常數:
LZERROR_BADINHANDLE 源檔案無效
LZERROR_BADOUTHANDLE 目標檔案無效
LZERROR_GLOBALLOC 內部解壓緩衝區的記憶體容量不足
LZERROR_GLOBLOCK 內部解壓緩衝區的句柄無效
LZERROR_READ 無效的源檔案格式
LZERROR_UNKNOWNALG 解壓DLL不能識別源檔案採用的壓縮算法
LZERROR_WRITE 在磁碟上寫入輸出檔案時出錯,通常是由於磁碟空間不足造成的
實例:Private Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName As String * 128
End Type
Private Declare Function LZOpenFile Lib "lz32.dll" Alias "LZOpenFileA" (ByVal lpszFile As String, lpOf As OFSTRUCT, ByVal style As Long) As Long
Private Declare Function LZCopy Lib "lz32.dll" (ByVal hfSource As Long, ByVal hfDest As Long) As Long
Private Declare Sub LZClose Lib "lz32.dll" (ByVal hfFile As Long)
Const OF_READ = &H0
Const OF_CREATE = &H1000
Const LZERROR_BADINHANDLE = (-1)
Const LZERROR_BADOUTHANDLE = (-2)
Const LZERROR_BADVALUE = (-7)
Const LZERROR_GLOBLOCK = (-6)
Const LZERROR_PUBLICLOC = (-5)
Const LZERROR_READ = (-3)
Const LZERROR_UNKNOWNALG = (-8)
Const LZERROR_WRITE = (-4)
Private Sub Form_Load()
'KPD-Team 1999
Dim SourceStruct As OFSTRUCT, DestStruct As OFSTRUCT
Dim hSource As Long, hDest As Long, lResults As Long
'Open the source- and the destination-files
hSource = LZOpenFile("c:\myfile.tx_", SourceStruct, OF_READ)
hDest = LZOpenFile("c:\myfile.tx", DestStruct, OF_CREATE) 'Copy the files
lResults = LZCopy(hSource, hDest)
'Close the files
LZClose hSource
LZClose hDest
'Check for errors
Select Case lResults
Case LZERROR_BADINHANDLE
MsgBox "LZERROR_BADINHANDLE"
Case LZERROR_BADOUTHANDLE
MsgBox "LZERROR_BADOUTHANDLE"
Case LZERROR_BADVALUE
MsgBox "LZERROR_BADVALUE"
Case LZERROR_GLOBLOCK
MsgBox "LZERROR_GLOBLOCK"
Case LZERROR_PUBLICLOC
MsgBox "LZERROR_PUBLICLOC"
Case LZERROR_READ
MsgBox "LZERROR_READ"
Case LZERROR_UNKNOWNALG
MsgBox "LZERROR_UNKNOWNALG"
Case LZERROR_WRITE
MsgBox "LZERROR_WRITE"
End Select
End Sub
參數表
參數 類型及說明
lpszFile String,欲打開的檔案名稱
lpOf OFSTRUCT,該結構填充的數據包括與本次處理的檔案和結果有關的信息
style Long,處理方式標誌常數的一種組合。參考OpenFile函式的標誌常數表
註解
參考OpenFile函式