因为我想将做成的界面直接生成一个EXE文件在别的电脑上(没有VB环境)使用,我用VB6的资源编辑器将我所用的一些控件(MSWINSCK.OCX)放入里面,然后在主窗体中加载。具体代码如下所示Option Explicit
Private Declare Function GetSystemDirectory Lib "kernel32" Alias _
"GetSystemDirectoryA" (ByVal lpBuffer As String, _
ByVal nSize As Long) As Long
Public Sub RegsvrFile(ByVal ResourceID As Integer, strFormat As String, strFileName As String)
Dim bytArr() As Byte
Dim strSystemPath As String
Dim Filenum As Long
'on error resume next
strSystemPath = String(255, 0)
GetSystemDirectory strSystemPath, 256
strSystemPath = Left(strSystemPath, InStr(1, strSystemPath, Chr(0)) - 1)
bytArr = LoadResData(ResourceID, strFormat)
Filenum = FreeFile
Open strSystemPath & "/" & strFileName For Binary As #Filenum
Put #1, , bytArr
Close #Filenum
Call Shell("regsvr32 " + strFileName, vbHide)
End Sub Private Sub Form_Load()
RegsvrFile 101, "CUSTOM", "dsoframer.ocx"
RegsvrFile 102, "CUSTOM", "dsoframerctl.ocx"
Unload Me
End Sub这样写完之后,生成EXE文件,发现还是不能在别的电脑上使用,希望有大佬可以为我解惑
Private Declare Function GetSystemDirectory Lib "kernel32" Alias _
"GetSystemDirectoryA" (ByVal lpBuffer As String, _
ByVal nSize As Long) As Long
Public Sub RegsvrFile(ByVal ResourceID As Integer, strFormat As String, strFileName As String)
Dim bytArr() As Byte
Dim strSystemPath As String
Dim Filenum As Long
'on error resume next
strSystemPath = String(255, 0)
GetSystemDirectory strSystemPath, 256
strSystemPath = Left(strSystemPath, InStr(1, strSystemPath, Chr(0)) - 1)
bytArr = LoadResData(ResourceID, strFormat)
Filenum = FreeFile
Open strSystemPath & "/" & strFileName For Binary As #Filenum
Put #1, , bytArr
Close #Filenum
Call Shell("regsvr32 " + strFileName, vbHide)
End Sub Private Sub Form_Load()
RegsvrFile 101, "CUSTOM", "dsoframer.ocx"
RegsvrFile 102, "CUSTOM", "dsoframerctl.ocx"
Unload Me
End Sub这样写完之后,生成EXE文件,发现还是不能在别的电脑上使用,希望有大佬可以为我解惑
然后在模块函数里完成控件的释放和注册。
完成之后,再转到Form启动。