在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
有什么想法吗?
答案 0 :(得分:1)
您可以使用Is
来比较两个对象:
Private Function IsSame(p1 As msforms.ListBox, p2 As msforms.ListBox)
IsSame = p1 Is p2
End Function