为了获取标准COM接口IDispach,可在CCntrItem类中添加返回数据类型为LPDISPATCH 的GetIDispatch()函数,该函数通过QueryInterface()方法对IID_Idispatch接口的查询而返回得到指向IDispach接口的指针:
ASSERT_VALID(this); ASSERT(m_lpObject != NULL); LPUNKNOWN lpUnk = m_lpObject; Run(); LPOLELINK lpOleLink = NULL; if(m_lpObject->QueryInterface(IID_IOleLink,(LPVOID FAR*)&lpOleLink)== NOERROR) { ASSERT(lpOleLink != NULL); lpUnk = NULL; if(lpOleLink->GetBoundSource(&lpUnk) != NOERROR) { TRACE0("Warning: Link is not connected!n"); lpOleLink->Release(); } ASSERT(lpUnk != NULL); } LPDISPATCH lpDispatch = NULL; if(lpUnk->QueryInterface(IID_IDispatch,(LPVOID FAR*)&lpDispatch) != NOERROR) { TRACE0("Waring: does not support IDispatch!n"); return NULL; } ASSERT(lpDispatch != NULL); return lpDispatch; |
为了使用类型库中的方法,需要在使用类型库的地方添加对“MSWord8.h”的引用(如使用Word 2000,则包含对“MSWord9.h”的引用)。
|