比较 VBA 中 COM 对象的标识
Compare identity of COM objects in VBA
在 C++ 中,如果我想知道两个 COM 接口指针 p1 和 p2 是否指向同一个组件,我会这样做:
bool IsSame( IDispatch* p1, IDispatch* p2 )
{
IUnknown* pUnk1;
p1->QueryInterface( IID_IUnknown, reinterpret_cast<void**>(&pUnk1) );
IUnknown* pUnk2;
p2->QueryInterface( IID_IUnknown, reinterpret_cast<void**>(&pUnk2) );
return p1 == p2;
}
如何在 VBA 中执行此操作?我想将它用于两个 MSForms.ListBox 对象:
Private Function IsSame( p1 as MSForms.ListBox, p2 as MSForms.ListBox )
' Comparing p1 and p2 would compare their default Property, which is their Value
End Function
有什么想法吗?
您可以使用Is
来比较两个对象:
Private Function IsSame(p1 As msforms.ListBox, p2 As msforms.ListBox)
IsSame = p1 Is p2
End Function
在 C++ 中,如果我想知道两个 COM 接口指针 p1 和 p2 是否指向同一个组件,我会这样做:
bool IsSame( IDispatch* p1, IDispatch* p2 )
{
IUnknown* pUnk1;
p1->QueryInterface( IID_IUnknown, reinterpret_cast<void**>(&pUnk1) );
IUnknown* pUnk2;
p2->QueryInterface( IID_IUnknown, reinterpret_cast<void**>(&pUnk2) );
return p1 == p2;
}
如何在 VBA 中执行此操作?我想将它用于两个 MSForms.ListBox 对象:
Private Function IsSame( p1 as MSForms.ListBox, p2 as MSForms.ListBox )
' Comparing p1 and p2 would compare their default Property, which is their Value
End Function
有什么想法吗?
您可以使用Is
来比较两个对象:
Private Function IsSame(p1 As msforms.ListBox, p2 As msforms.ListBox)
IsSame = p1 Is p2
End Function