怎么判断类是否存在?

vcbug 2003-07-28 10:54:23
在主程序里引用一个自定义的activedll类之前,怎么判断该类是否存在,或是否注册了?


例如 dim ss as new mydll

如果mydll没有,会报错的.

怎么写 if 该类存在 then
dim ss as new mydll
............
end if
...全文
105 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
vcbug 2003-07-29
  • 打赏
  • 举报
回复
都是用出错判断的方法,不是很好
xingsoft 2003-07-28
  • 打赏
  • 举报
回复
>在主程序里引用一个自定义的activedll类之前,怎么判断该类是否存在,或是否注册了?
思路:试着去建立一个对象,如果建立不成功,则这个类没有被注册。
使用方法:
if CretaeObjectEx("MyDll.MyClass") is nothing then
msgbox "ActiveX Dll 不能建立对象"

end if

'***********************************************************
Public Function CreateObjectEx(Class As String, Optional ServerName As String)
'目的 : 建立对象
'相关模块:
'返回:建立成功,返回对对象的引用,否则返回Nothing.
On Error GoTo PROC_ERR
Dim lngErr As Long
If IsMissing(ServerName) Then
Set CreateObjectEx = CreateObject(Class)
Else
Set CreateObjectEx = CreateObject(Class, ServerName)
End If

PROC_EXIT:
Exit Function
PROC_ERR:
lngErr = Err.Number
Set CreateObjectEx = Nothing
Debug.Print "CreateObjectEx.Err(" & Err.Number & "):" & Err.Description
GoTo PROC_EXIT
End Function
'***********************************************************
'*希望能够对你有所帮助!
'***********************************************************
'*欢迎访问的网站,给我的作品提宝贵意见!
http://www.softboyzhou.com
'*下载EasyDialog:
http://www.softboyzhou.com/download/EasyDialog.asp
flxa 2003-07-28
  • 打赏
  • 举报
回复
On error GOTO ERRHAND
dim ss as new mydll
......



ERRHAND:
msgbox("类没有注册")
 if file("C:\windows\system32\mydll.dll") Then
regsvr32 C:\windwos\system32\mydll.dll /s
endif




vcbug 2003-07-28
  • 打赏
  • 举报
回复
除了查找,dll文件外有其他更好的办法吗?

7,785

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧