我将二进制文件(扩展名为.xdt)加入资源文件中,用LoadResData函数调用,
Open LoadResData(114, "CUSTOM") For Binary As #1
。。。。。。。。。。。。。。。。。。。。。。。
运行时报“文件未找到”,
Open LoadResData(114, 10) For Binary As #1
。。。。。。。。。。。。。。。。。
运行时报“标志为114的资源文件未找到”
请问如何使用资源文件中的二进制文件?
...全文
717打赏收藏
关于如何使用资源文件
我将二进制文件(扩展名为.xdt)加入资源文件中,用LoadResData函数调用, Open LoadResData(114, "CUSTOM") For Binary As #1 。。。。。。。。。。。。。。。。。。。。。。。 运行时报“文件未找到”, Open LoadResData(114, 10) For Binary As #1 。。。。。。。。。。。。。。。。。 运行时报“标志为114的资源文件未找到” 请问如何使用资源文件中的二进制文件?
Private Sub Command1_Click()
Dim bytData() As Byte
bytData = LoadResData(101, "custom")
Open App.Path + "\aaa.exe" For Binary As #1
Put #1, , bytData
Close #1
这里的C:\about.gif只是一个例子,在实际编程可以用Windows API的GetTempFileName来生成临时文件名(但GetTempFileName生成的临时文件扩展名为.tmp,需改为.gif)。这里的SaveFileFromRes函数来完成写临时文件的工作,具体代码如下:
Public Function SaveFileFromRes(vntResourceID As Variant,
sType As String, sFileName As String) As Boolean
Dim bytImage() As Byte ' Always store binary data in byte arrays!
Dim iFileNum As Integer 'Free File Handle
On Error GoTo SaveFileFromRes_Err
SaveFileFromRes = True
'Load Binary Data from Resource file
bytImage = LoadResData(vntResourceID, sType)
'Get Free File Handle
iFileNum = FreeFile
'Open the file and save the data
Open sFileName For Binary As iFileNum
Put #iFileNum, , bytImage
Close iFileNum
Exit Function
SaveFileFromRes_Err:
SaveFileFromRes = False: Exit Function
End Function
Option Explicit
'在外接程序中调入VB资源文件编辑器
'单击加入自定义文件图标,选择要加入的程序,注意程序不要大于64k(否则你拆开你程序,分别加入,然后在合成)
Private Sub Command1_Click()
Dim bytData() As Byte
bytData = LoadResData(101, "custom")
Open App.Path + "\aaa.exe" For Binary As #1
Put #1, , bytData
Close #1