代码如下:
Private Const FILESIZEOFAPP2 = 20480 ´我生成的APP-2.Exe大小是20480Byte
Private Sub cmdOK_Click() ´单击按钮cmdOK运行代码
Dim APP2() As Byte ´APP2是个Btye类型和数组
Dim Counter As Long
APP2 = LoadResData(101, "CUSTOM") ´将自定义资源中101号资源读入数组
注意,微软的帮助中对加载定义资源的说明有误,硬是资源标识为"CUSTOM"而非数字
If Dir(App.Path & "\APP-2.Exe") <> "" Then ´第一次按cmdOK有效
MsgBox App.Path & "\APP-2.Exe 已经存在!"
Exit Sub
End If
Open App.Path & "\APP-2.exe" For Binary As #1 ´以二进制方式写(生成)APP-2.Exe到APP-1.Exe所在的目录
For Counter = 0 To FILESIZEOFAPP2 - 1 ´注意因为从0 Byte开始因此以文件大小 - 1Byte 为终
Put #1, , APP2(Counter)
Next Counter
Close #1
Shell App.Path & "\APP-2.Exe", vbNormalFocus ´运行刚生成的APP-2.Exe
Unload Me
End Sub