VB6资源文件的读写到硬盘文件

2019-07-15 16:05:00
zstmtony
转贴
481
LoadResData是从VB的资源文件读取一个文件的函数
LoadResData DataID , DataType
例如你添加了一个资源文件得到的资源号是101号,在"Test"文件夹中.
就可以用LoadResData(101,"Test") 获到该 文件。

Dim xFileByteArray() As Byte
xFileByteArray = LoadResData(101,"Test")
'将资源写入文件
open App.path & "\A.Txt" for binary as #1
put #1,,xFileByteArray

Close #1



Public Function SaveResItemToDisk( _
                ByVal iResourceNum As Integer, _
                ByVal sResourceType As String, _
                ByVal sDestFileName As String _
                ) As Long
        '=============================================
        'Saves a resource item to disk

    'Returns 0 on success, error number on failure
    '=============================================

    'Example Call:
    ' iRetVal = SaveResItemToDisk(101, "CUSTOM", "C:\myImage.gif")

    Dim bytResourceData()   As Byte
    Dim iFileNumOut         As Integer

    On Error GoTo SaveResItemToDisk_err

    'Retrieve the resource contents (data) into a byte array
    bytResourceData = LoadResData(iResourceNum, sResourceType)

    'Get Free File Handle
    iFileNumOut = FreeFile

    'Open the output file
    Open sDestFileName For Binary Access Write As #iFileNumOut

        'Write the resource to the file
        Put #iFileNumOut, , bytResourceData

    'Close the file
    Close #iFileNumOut

    'Return 0 for success
    SaveResItemToDisk = 0

    Exit Function
SaveResItemToDisk_err:
    'Return error number
    SaveResItemToDisk = Err.Number
End Function
分享