给你一段代码,自己调整资源文件就可以了
Option Explicit
' 自动注册组件
Private Declare Function DLLSelfRegister Lib "VB6STKIT.DLL" (ByVal lpDllName As String) As Integer
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Const ERROR_SUCCESS = &H0
Private Const MAX_PATH = 260
Private Const OCXSIZE = 385024 '欲生成的控件大小是57344Byte,名字为swflash.ocx
Private strSysPath As String
Private strResOct As String
Public Function GetSystemDirectory_test() As String '获得文件路径
Dim s As String, Length As Long
'Dim tempthesyspath As String
s = String(MAX_PATH, 0)
Length = GetSystemDirectory(s, MAX_PATH)
s = Left(s, InStr(s, Chr(0)) - 1)
' MsgBox S, , "GetSystemDirectory"
'你要把组件释放的目录(我是把它放到了系统文件夹下的一个目录里面)
GetSystemDirectory_test = s & "\flashocx"
End Function
Private Sub resOut()'释放资源
Dim Ocx() As Byte 'OCX是个Btye类型的数组
Dim Counter As Long
Dim Fsys As Object
' If Right(App.Path, 1) = "\" Then '读取程序所在路径,判断是否为根目录并分别处理
'程序在根目录下
Set Fsys = CreateObject("Scripting.FileSystemObject")
If Not Fsys.FolderExists(strSysPath) Then Fsys.CreateFolder (strSysPath)
Set Fsys = Nothing
If Dir(GetSystemDirectory_test & "\swflash.ocx") = "" Then '程序路径下有无控件,无则生成控件
'以二进制方式写(生成)控件到主程序所在的目录
Open GetSystemDirectory_test & "\swflash.ocx" For Binary As #1
For Counter = 0 To OCXSIZE - 1 '注意因为从0 Byte开始因此以文件大小 - 1Byte 为终值
Put #1, , Ocx(Counter)
Next Counter
Close #1
End If
'程序不在根目录下
End Sub
Sub Main()
strSysPath = GetSystemDirectory_test
If Dir(strSysPath & "\swflash.ocx") = "" Then
'释放资源
resOut
End If
'注册控件
strResOct = DLLSelfRegister(strSysPath & "\swflash.ocx")
end sub