打造自己的CreateObject函数(VB)

前端之家收集整理的这篇文章主要介绍了打造自己的CreateObject函数(VB)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_403_0@vb Code

@H_403_0@在CreateObject调用之前,先调用CreateObjectEx函数

@H_403_0@下面实现,这样可以知道我们的Class参数是否能创建成功!!!

@H_403_0@Type CLSID

@H_403_0@ Data1 as long

@H_403_0@ Data2as Integer

@H_403_0@ Data3 as Integer

@H_403_0@ Data(7) as byte

@H_403_0@end Type

@H_403_0@public declare Function CLSIDFromProgID lib "Ole32.dll" (Byval lpszProgID as long,pClsid as CLSID) as long

@H_403_0@public Function CreateObjectEx(Class as string) as object

@H_403_0@'--注意最好写上

@H_403_0@on error goto ErrHandler

@H_403_0@ dim myclsid as CLSID

@H_403_0@ dim lngRet as long

@H_403_0@ dim Obj

@H_403_0@ lngRet = CLSIDFromProgID(strptr(Class),myclid)

@H_403_0@ debug.printHex(myclid.Data1)

@H_403_0@debug.printHex(myclid.Data2)

@H_403_0@debug.printHex(myclid.Data3)

@H_403_0@debug.printHex(myclid.Data(0)) & Hex(myclid.Data(1)) & Hex(myclid.Data(2)) & Hex(myclid.Data(3)) & vbcrlf

@H_403_0@debug.printHex(myclid.Data(4)) & Hex(myclid.Data(5)) & Hex(myclid.Data(6)) & Hex(myclid.Data(7)) & vbcrlf

@H_403_0@ '--如果打印出来的全是0,说明我们CreateObject的组件在系统中不存在或者被破坏了

@H_403_0@ if xxx=0 and xx=00....then

@H_403_0@ '----Error!!!

@H_403_0@ else

@H_403_0@ debug.print "--ok" & vbcrlf

@H_403_0@ Set Obj = CreateObject(Class)

@H_403_0@ set CreateObjectEx = obj

@H_403_0@ end if

@H_403_0@set obj = nothing

@H_403_0@Exit Function

@H_403_0@ErrHandler:

@H_403_0@ msgBox err.number & vbcrlf & err.description

@H_403_0@ debug.print "---Error!" & vbcrlf

@H_403_0@end function

猜你在找的VB相关文章