vb6工具集系列源码分享

vb6工具集系列-二进制文件存取

使用adodb 实现的文件二进制存取工具, 后期会更新更多函数, 目前就2个

Option Explicit

' 作者:邓伟
' 网站:www.vb6.pro

'    Library ADODB
'C:  \Program Files (x86)\Common Files\System\ado\msado28.tlb
'    Microsoft ActiveX Data Objects 2.8 Library

Public Inst As New ADODB.Stream
Public LastError As String

Public Function LoadFileAsBinary(ByVal Path As String, OutData() As Byte) As Boolean
    On Error GoTo EH
    LastError = ""
    With Inst
        If .State <> adStateClosed Then .Close
        .Type = adTypeBinary
        .Open
        .LoadFromFile Path
        OutData = .Read()
        .Close
    End With
    LoadFileAsBinary = True
    Exit Function
EH:
    LastError = Err.Description & "#" & Err.Description
End Function

Public Function SaveFileAsBinary(ByVal Path As String, OutData() As Byte) As Boolean
    On Error GoTo EH
    LastError = ""
    With Inst
        If .State <> adStateClosed Then .Close
        .Type = adTypeBinary
        .Open
        .Write OutData
        .SaveToFile Path, adSaveCreateNotExist
        .Close
    End With
    SaveFileAsBinary = True
    Exit Function
EH:
    LastError = Err.Description & "#" & Err.Description
End Function

Views: 61

Hi, I’m 邓伟

本来无一物,何处惹尘埃

发表回复