//+------------------------------------------------------------------------ // // Microsoft Windows // Copyright (C) Microsoft Corporation, 1993. // // File: bm_qi.cxx // // Contents: Ole QueryInterface test // // Classes: CQueryInterfaceTest // // History: 1-July-93 t-martig Created // //-------------------------------------------------------------------------- #include #pragma hdrstop #include // this is just an array of random interface iids. The qi server object // answers YES to any QI, although the only valid methods on each interface // are the methods of IUnknown. // // the code will answer NO to the following IIDs in order to prevent // custom marshalling problems... // // IID_IMarshal, IID_IStdMarshalInfo, IID_IStdIdentity, // IID_IPersist, IID_IProxyManager const IID *iid[] = {&IID_IAdviseSink, &IID_IDataObject, &IID_IOleObject, &IID_IOleClientSite, &IID_IParseDisplayName, &IID_IPersistStorage, &IID_IPersistFile, &IID_IStorage, &IID_IOleContainer, &IID_IOleItemContainer, &IID_IOleInPlaceSite, &IID_IOleInPlaceActiveObject, &IID_IOleInPlaceObject, &IID_IOleInPlaceUIWindow, &IID_IOleInPlaceFrame, &IID_IOleWindow}; TCHAR *CQueryInterfaceTest::Name () { return TEXT("QueryInterface"); } SCODE CQueryInterfaceTest::Setup (CTestInput *pInput) { SCODE sc; CTestBase::Setup(pInput); // get iteration count m_ulIterations = pInput->GetIterations(Name()); // initialize state for (ULONG iCtx=0; iCtxGetGUID(&m_ClsID[iCtx], Name(), apszClsIDName[iCtx]); if (FAILED(sc)) { Log (TEXT("Setup - GetClassID failed."), sc); return sc; } INIT_RESULTS(m_ulQueryInterfaceSameTime[iCtx]); INIT_RESULTS(m_ulPunkReleaseSameTime[iCtx]); INIT_RESULTS(m_ulQueryInterfaceNewTime[iCtx]); INIT_RESULTS(m_ulPunkReleaseNewTime[iCtx]); _pUnk[iCtx] = NULL; } sc = InitCOM(); if (FAILED(sc)) { Log (TEXT("Setup - CoInitialize failed."), sc); return sc; } // create an instance of each qi server object for (iCtx=0; iCtxRelease(); } } UninitCOM(); return S_OK; } SCODE CQueryInterfaceTest::Run () { CStopWatch sw; IUnknown *pUnk = NULL; for (ULONG iCtx=0; iCtxQueryInterface(IID_IStorage, (void **)&pUnk); m_ulQueryInterfaceSameTime[iCtx][iIter] = sw.Read (); Log (TEXT("QueryInterface"), sc); if (SUCCEEDED(sc)) { sw.Reset(); pUnk->Release (); m_ulPunkReleaseSameTime[iCtx][iIter] = sw.Read(); } else { m_ulPunkReleaseSameTime[iCtx][iIter] = NOTAVAIL; } } // different interface each time, releasing after each query for (iIter=0; iIterQueryInterface(*(iid[iIter]), (void **)&pUnk); m_ulQueryInterfaceNewTime[iCtx][iIter] = sw.Read (); Log (TEXT("QueryInterface"), sc); if (SUCCEEDED(sc)) { sw.Reset(); pUnk->Release (); m_ulPunkReleaseNewTime[iCtx][iIter] = sw.Read(); } else { m_ulPunkReleaseNewTime[iCtx][iIter] = NOTAVAIL; } } } return S_OK; } SCODE CQueryInterfaceTest::Report (CTestOutput &output) { output.WriteSectionHeader (Name(), TEXT("QueryInterface"), *m_pInput); for (ULONG iCtx=0; iCtx