vb Code
在CreateObject调用之前,先调用CreateObjectEx函数
下面实现,这样可以知道我们的Class参数是否能创建成功!!!
Type CLSID
Data1 as long
Data2as Integer
Data3 as Integer
Data(7) as byte
end Type
public declare Function CLSIDFromProgID lib "Ole32.dll" (Byval lpszProgID as long,pClsid as CLSID) as long
public Function CreateObjectEx(Class as string) as object
'--注意最好写上
on error goto ErrHandler
dim myclsid as CLSID
dim lngRet as long
dim Obj
lngRet = CLSIDFromProgID(strptr(Class),myclid)
debug.printHex(myclid.Data1)
debug.printHex(myclid.Data2)
debug.printHex(myclid.Data3)
debug.printHex(myclid.Data(0)) & Hex(myclid.Data(1)) & Hex(myclid.Data(2)) & Hex(myclid.Data(3)) & vbcrlf
debug.printHex(myclid.Data(4)) & Hex(myclid.Data(5)) & Hex(myclid.Data(6)) & Hex(myclid.Data(7)) & vbcrlf
'--如果打印出来的全是0,说明我们CreateObject的组件在系统中不存在或者被破坏了
if xxx=0 and xx=00....then
'----Error!!!
else
debug.print "--ok" & vbcrlf
Set Obj = CreateObject(Class)
set CreateObjectEx = obj
end if
set obj = nothing
Exit Function
ErrHandler:
msgBox err.number & vbcrlf & err.description
debug.print "---Error!" & vbcrlf
end function
原文链接:https://www.f2er.com/vb/261280.html