''如何将 exe程序和vb编译的exe文件 封装为一个exe文件
''把它当成资源文件,包到主程序里
''以下代码是我封装控件和数据库的代码,你看看数据库是怎样封的,没时间简化
Option Explicit
Sub Main()
Const DBSIZE = 479232 '欲生成的数据库大小是479232Byte,名字为Provider.mdb
Const Comcat = 3856 '欲生成的控件大小是3856Byte,Comcat.dll
Const Msado15 = 491792 '欲生成的控件大小是3856Byte,msado15.dll
Const MSCOMCT2 = 662288 '欲生成的控件大小是662,288Byte,MSCOMCT2.OCX
Const mscomctl = 1081616 '欲生成的控件大小是3856Byte,mscomctl.ocx
Const stdole2 = 16896 '欲生成的控件大小是16,896Byte,stdole2.tlb
''**
Dim Ocx() As Byte 'OCX是个Btye类型的数组
Dim Counter As Long
Ocx = LoadResData(107,"CUSTOM") '将自定义资源中101号资源读入数组OCX
'注意,微软的帮助中对加载自定义资源的说明有错误,自定义资源标识为"CUSTOM"而不是帮助所说
的数字10
'程序不在根目录下一一一一一一一一一一一
If Dir(App.Path & "/Provider.mdb") = "" Then '程序路径下有无控件,无则
生成控件
'以二进制方式写(生成)控件(agtintl.dll)到主程序所在的目录
Open App.Path & "/Provider.mdb" For Binary As #1
For Counter = 0 To DBSIZE - 1 '注意因为从0 Byte开始因此以文件
大小 - 1Byte 为终值
Put #1,Ocx(Counter)
Next Counter
Close #1
End If
''二二二二二二二二二二二二二二二二二二二二二二
Erase Ocx
Ocx = LoadResData(102,"CUSTOM")
If Dir(App.Path & "/comcat.dll") = "" Then
Open App.Path & "/comcat.dll" For Binary As #1
For Counter = 0 To Comcat - 1 '注意因为从0 Byte开始因此以
文件大小 - 1Byte 为终值
Put #1,Ocx(Counter)
Next Counter
Close #1
End If
Shell "Regsvr32 /s" & App.Path & "/comcat.dll"
'三三三三三三三三三三三三三三三三三三三三三三三三三
Erase Ocx
Ocx = LoadResData(103,"CUSTOM")
If Dir(App.Path & "/msado15.dll") = "" Then
Open App.Path & "/msado15.dll" For Binary As #1
For Counter = 0 To Msado15 - 1 '注意因为从0 Byte开始因此以
文件大小 - 1Byte 为终值
Put #1,Ocx(Counter)
Next Counter
Close #1
End If
Shell "Regsvr32 /s" & App.Path & "/msado15.dll"
'四四四四四四四四四四四四四四四四四四四四四四四四四四四四四四四四四四
Erase Ocx
Ocx = LoadResData(104,"CUSTOM")
If Dir(App.Path & "/MSCOMCT2.OCX") = "" Then
Open App.Path & "/MSCOMCT2.OCX" For Binary As #1
For Counter = 0 To MSCOMCT2 - 1 '注意因为从0 Byte开始因此
以文件大小 - 1Byte 为终值
Put #1,Ocx(Counter)
Next Counter
Close #1
End If
Shell "Regsvr32 /s" & App.Path & "/MSCOMCT2.OCX"
'五五五五五五五五五五五五五五五五五五五五五五五五五五五五五五五五五五五五五
Erase Ocx
Ocx = LoadResData(105,"CUSTOM")
If Dir(App.Path & "/mscomctl.ocx") = "" Then
Open App.Path & "/mscomctl.ocx" For Binary As #1
For Counter = 0 To mscomctl - 1 '注意因为从0 Byte开始因此
以文件大小 - 1Byte 为终值
Put #1,Ocx(Counter)
Next Counter
Close #1
End If
Shell "Regsvr32 /s" & App.Path & "/mscomctl.ocx"
'六六六六六六六六六六六六六六六六六六六六六六六六六
Erase Ocx
Ocx = LoadResData(106,"CUSTOM")
If Dir(App.Path & "/stdole2.tlb") = "" Then
Open App.Path & "/stdole2.tlb" For Binary As #1
For Counter = 0 To stdole2 - 1 '注意因为从0 Byte开始因此以
文件大小 - 1Byte 为终值
Put #1,Ocx(Counter)
Next Counter
Close #1
End If
Shell "Regsvr32 /s" & App.Path & "/stdole2.tlb"
FrmMain.Show
End Sub
'注册控件
'Private Declare Function RegOcx Lib "A.OCX" Alias "DllRegisterServer" ()
As Long
'
'Private Sub Form_Load()
' Call RegOcx
'End Sub
'
'OCX文件中都有一个接口DllRegisterServer,这个接口就是用来注册自身的,同样,也可以
用"UnDllregisterServer"在代碼中來取消注冊控件自身
'如果是注册其它路径的文件,要在声明时写完整路径,如
'Private Declare Function RegOcx Lib "C:/Test/A.OCX" Alias "DllRegisterServer"
() As Long
'
'Private Sub Form_Load()
' Call RegOcx
'End Sub
'还有一种
'Private Sub Form_Load()
' Me.Visible = False
' Shell "regsvr32 /s " & App.Path & "/DtRead.ocx" '用参数/s,不提示
注册成功信息 ' Shell "regsvr32 /s " & App.Path & "/ConnStr.dll" ' Shell "regsvr32 /s " & App.Path & "/HisCurve.ocx" ' Shell "regsvr32 /s " & App.Path & "/Rep.dll" ' MsgBox "注册成功!" ' Unload Me 'End Sub