请问vb 修改资源文件(即修改字符串表的内容)
发布网友
发布时间:2022-04-22 10:13
我来回答
共4个回答
热心网友
时间:2023-10-10 07:51
'窗体上的控件如你所述,复制下面代码,根据实际情况修改注释部分,然后运行即可。
Option Explicit
'API声明
Private Declare Function BeginUpdateResource Lib "kernel32" Alias "BeginUpdateResourceA" (ByVal pFileName As String, ByVal bDeleteExistingResources As Long) As Long
Private Declare Function UpdateResource Lib "kernel32" Alias "UpdateResourceA" (ByVal hUpdate As Long, ByVal lpType As String, ByVal lpName As Long, ByVal wLanguage As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function EndUpdateResource Lib "kernel32" Alias "EndUpdateResourceA" (ByVal hUpdate As Long, ByVal fDiscard As Long) As Long
Private Sub Cmd_Write_Click()
Dim hRes As Long, i As Integer
Dim myStr() As Byte, b() As Byte, FileName As String
FileName = "c:\1.exe" '这个就是你要生成的程序名
If Dir(FileName) <> "" Then Kill FileName
b = LoadResData(101, "CUSTOM") '本程序中Exe文件的资源ID号
i = FreeFile
Open FileName For Binary As #i
Put #i, , b
Close #i
myStr = StrConv(Text1.Text, vbFromUnicode)
hRes = BeginUpdateResource(FileName, False)
UpdateResource hRes, "CUSTOM", 101, 2052, myStr(0), Len(Text1.Text) 'Exe文件中要替换的资源ID号
EndUpdateResource hRes, False
MsgBox "文件替换并生成完毕!"
End Sub
热心网友
时间:2023-10-10 07:52
读写文件 另存为而已,不难。
不过小心替换错了, 就不行了,所以一定要找对地方才行吧。
open app.path & "/" &app.name for binary as #1
类似这样,吧,哈哈,谁帮你写个完整的
热心网友
时间:2023-10-10 07:52
Option Explicit
'API声明
Private Declare Function BeginUpdateResource Lib "kernel32" Alias "BeginUpdateResourceA" (ByVal pFileName As String, ByVal bDeleteExistingResources As Long) As Long
Private Declare Function UpdateResource Lib "kernel32" Alias "UpdateResourceA" (ByVal hUpdate As Long, ByVal lpType As String, ByVal lpName As Long, ByVal wLanguage As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function EndUpdateResource Lib "kernel32" Alias "EndUpdateResourceA" (ByVal hUpdate As Long, ByVal fDiscard As Long) As Long
Private Sub Cmd_Write_Click()
Dim hRes As Long, i As Integer
Dim myStr() As Byte, b() As Byte, FileName As String
FileName = "c:\1.exe" '这个就是你要生成的程序名
If Dir(FileName) <> "" Then Kill FileName
b = LoadResData(101, "CUSTOM") '本程序中Exe文件的资源ID号
i = FreeFile
Open FileName For Binary As #i
Put #i, , b
Close #i
myStr = StrConv(Text1.Text, vbFromUnicode)
hRes = BeginUpdateResource(FileName, False)
UpdateResource hRes, "CUSTOM", 101, 2052, myStr(0), Len(Text1.Text) 'Exe文件中要替换的资源ID号
EndUpdateResource hRes, False
MsgBox "文件替换并生成完毕!"
End Sub
热心网友
时间:2023-10-10 07:53
1。 先把资源文件读取写到文件中
Dim strData() As Byte 'APP2是个Btye类型和数组
'读取资源
strData = LoadResData(strFileName, strExeType) '将自定义资源读入数组,注意,微软的帮助中对加载定义资源的说明有误,硬是资源标识为"CUSTOM"而非数字
'写入文件
iFile = FreeFile()
Open strTmpFile For Binary As #iFile
Put #iFile, , strData
Close #iFile
2. 用二进制打开上面建立的文件strTmpFile,找到123,替换成321。使用时,应注意文件的定位。
不知这是不是你想要的!GoodLuck。