VB6資源文件的讀寫到硬盤文件

2019-07-15 16:05:00
zstmtony
轉貼
477
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
分享