刚学VB练习做了个程序,添加BSE.ocx按钮控件。但是在没有BSE.ocx按钮控件的机器上就会提示错误:
component 'BSE.ocx' or one of its dependencies not correctly registered: a file is missing or invalid
google之后发现VB资源管理器能解决这个问题。BSE.cox文件写在程序根目录下没问题。换成别的目录就出错
代码如下:Dim app1() As Byte
If Dir(App.Path & "\BSE.ocx") = "" Then
app1 = LoadResData(101, "CUSTOM")
Open App.Path & "\BSE.ocx" For Binary As #1
Put #1, , app1
Close #1
End If我想换成Dim app1() As Byte
If Dir(App.Path & "\WINDOWS\system32\BSE.ocx") = "" Then
app1 = LoadResData(101, "CUSTOM")
Open App.Path & "\WINDOWS\system32\BSE.ocx" For Binary As #1
Put #1, , app1
Close #1
End If请问这个要怎么写呢?
component 'BSE.ocx' or one of its dependencies not correctly registered: a file is missing or invalid
google之后发现VB资源管理器能解决这个问题。BSE.cox文件写在程序根目录下没问题。换成别的目录就出错
代码如下:Dim app1() As Byte
If Dir(App.Path & "\BSE.ocx") = "" Then
app1 = LoadResData(101, "CUSTOM")
Open App.Path & "\BSE.ocx" For Binary As #1
Put #1, , app1
Close #1
End If我想换成Dim app1() As Byte
If Dir(App.Path & "\WINDOWS\system32\BSE.ocx") = "" Then
app1 = LoadResData(101, "CUSTOM")
Open App.Path & "\WINDOWS\system32\BSE.ocx" For Binary As #1
Put #1, , app1
Close #1
End If请问这个要怎么写呢?
解决方案 »
- 送分100分:关于KEYPREES传递的键值流程问题。
- word的宏代码如何转化成VB代码
- 为什么我的VB里面没有Excel类啊,是不是要引用什么?
- 怎样才能读写DAT文件
- 100分酬谢!寻找免费的GIF播放控件(第三方绿色控件,占用资源小,不使用WebBrowser,能够进行透明处理),有知下落者请回复!谢谢
- 无法从连接服务器"(null)"的OLEDB
- 求一个算法
- 想做个这样的网站程序难不难?
- 请高手指较
- 使用webbrowser,如何捕获网页上超链接的点击事件,执行自己的代码?
- vb 对象refresh的方法 iadodc失败 FROM 子句语法错误 新手,快交论文了,大家帮帮我!!
- 为Array赋值→能否写成多行?
Private Const OCXSIZE = 13436 '欲生成的控件大小是14336Byte,名字为BSE.ocxSub Main()
Dim Ocx() As Byte 'OCX是个Btye类型的数组
Dim Counter As Long
Ocx = LoadResData(101, "CUSTOM") '将自定义资源中101号资源读入数组OCX If Right(App.Path, 1) = "($%$43%^#ASD#2@$#f$%^)" Then '读取程序所在路径,判断是否为根目录并分别处理
'程序在根目录下
If Dir(App.Path & "BSE.ocx") = "" Then '程序路径下有无控件,无则生成控件
'以二进制方式写(生成)控件(BSE.ocx)到主程序所在的目录
Open App.Path & "BSE.ocx" For Binary As #1
For Counter = 0 To OCXSIZE - 1 '注意因为从0 Byte开始因此以文件大小 - 1Byte 为终值
Put #1, , Ocx(Counter)
Next Counter
Close #1
End if
Else
'程序不在根目录下
If Dir(App.Path & "\BSE.ocx") = "" Then '程序路径下有无控件,无则生成控件
'以二进制方式写(生成)控件(BSE.ocx)到主程序所在的目录
Open App.Path & "\BSE.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 if
Form1.Visible = True '主程序所用控件已经生成,显示主窗体,进入主程序。
End Sub 这个代码也只能释放到根目录下,就没有释放到指定目录的方法吗?
Option Explicit
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
'下面一句中的 RegTypeset 可以定义为其他你喜欢的名字
Private Declare Function RegTypeset Lib "BSE.ocx" Alias "DllRegisterServer" () As Long
Private Function GetSysDir() As String
'取系统文件夹路径
Dim Length As Long
Dim s As String * 250
Length = GetSystemDirectory(s, 250)
GetSysDir = Left$(s, Length)
End Function
Private Sub RegSelf()
Dim Ocx() As Byte
Dim Counter As Long, FreeNo As Integer
Ocx = LoadResData(101, "CUSTOM") '自定义资源的 ID
On Error Resume Next
FreeNo = FreeFile
Open GetSysDir & "\BSE.ocx" For Binary As FreeNo
Put #FreeNo, , Ocx()
Close FreeNo
Erase Ocx
Call RegTypeset '自注册,不依赖于外部的 Regsvr32.exe 文件
End Sub‘用法,可惜我看不懂
直接调用 RegSelf 就行了最好在模块的 Main 函数调用,并 Sub Main 设为启动对象Sub Main()
Call RegSelf
要显示的窗体.Show
End Sub再问下这个代码怎么用?貌似这个不错。还得多学啊```