void CWnd::AssertValid() const { if (m_hWnd == NULL) return; // null (unattached) windows are valid
// check for special wnd??? values ASSERT(HWND_TOP == NULL); // same as desktop if (m_hWnd == HWND_BOTTOM) ASSERT(this == &CWnd::wndBottom); else if (m_hWnd == HWND_TOPMOST) ASSERT(this == &CWnd::wndTopMost); else if (m_hWnd == HWND_NOTOPMOST) ASSERT(this == &CWnd::wndNoTopMost); else { // should be a normal window ASSERT(::IsWindow(m_hWnd));
// should also be in the permanent or temporary handle map CHandleMap* pMap = afxMapHWND(); ASSERT(pMap != NULL); // this is the row
CObject* p=NULL; if(pMap) { ASSERT( (p = pMap->LookupPermanent(m_hWnd)) != NULL || (p = pMap->LookupTemporary(m_hWnd)) != NULL); } ASSERT((CWnd*)p == this); // must be us
// Note: if either of the above asserts fire and you are // writing a multithreaded application, it is likely that // you have passed a C++ object from one thread to another // and have used that object in a way that was not intended. // (only simple inline wrapper functions should be used) // // In general, CWnd objects should be passed by HWND from // one thread to another. The receiving thread can wrap // the HWND with a CWnd object by using CWnd::FromHandle. // // It is dangerous to pass C++ objects from one thread to // another, unless the objects are designed to be used in // such a manner. } }
void AFXAPI AfxAssertValidObject(const CObject* pOb, LPCSTR lpszFileName, int nLine) { if (pOb == NULL) { TRACE(traceAppMsg, 0, "ASSERT_VALID fails with NULL pointer.\n"); if (AfxAssertFailedLine(lpszFileName, nLine)) AfxDebugBreak(); return; // quick escape } if (!AfxIsValidAddress(pOb, sizeof(CObject))) { TRACE(traceAppMsg, 0, "ASSERT_VALID fails with illegal pointer.\n"); if (AfxAssertFailedLine(lpszFileName, nLine)) AfxDebugBreak(); return; // quick escape }
// check to make sure the VTable pointer is valid ASSERT(sizeof(CObject) == sizeof(void*)); if (!AfxIsValidAddress(*(void**)pOb, sizeof(void*), FALSE)) { TRACE(traceAppMsg, 0, "ASSERT_VALID fails with illegal vtable pointer.\n"); if (AfxAssertFailedLine(lpszFileName, nLine)) AfxDebugBreak(); return; // quick escape }
if (!AfxIsValidAddress(pOb, pOb->GetRuntimeClass()->m_nObjectSize, FALSE)) { TRACE(traceAppMsg, 0, "ASSERT_VALID fails with illegal pointer.\n"); if (AfxAssertFailedLine(lpszFileName, nLine)) AfxDebugBreak(); return; // quick escape } pOb->AssertValid(); // this is the row }
// return addref'd IDispatch part of CCmdTarget object LPDISPATCH CCmdTarget::GetIDispatch(BOOL bAddRef) { ASSERT_VALID(this); ASSERT(m_xDispatch.m_vtbl != 0); // forgot to call EnableAutomation? // this is the row
// AddRef the object if requested if (bAddRef) ExternalAddRef();
// return pointer to IDispatch implementation return (LPDISPATCH)GetInterface(&IID_IDispatch); }
HRESULT CXTPDockingPane::GetAccessibleParent(IDispatch* FAR* ppdispParent) { SAFE_MANAGE_STATE(m_pModuleState);
*ppdispParent = NULL;
if (m_pParentContainer) { *ppdispParent = ((CXTPDockingPaneTabbedContainer*)m_pParentContainer)->GetIDispatch(TRUE); // this is the row return S_OK; } return E_FAIL; }
STDMETHODIMP CXTPAccessible::XAccessible::get_accParent(IDispatch* FAR* ppdispParent) { TRACE_ACCESSIBLE(_T("get_accParent\n")); METHOD_PROLOGUE_EX_(CXTPAccessible, ExternalAccessible);
return pThis->GetAccessibleParent(ppdispParent); // this is the row }
|