void EventTest::CreateEvent() { assert(_pHeader && _pDictionary); HRESULT hr = S_OK; IAAFEvent *pEvent = NULL; IAAFEventMobSlot *pEventMobSlot = NULL; IAAFSegment *pSegment = NULL; IAAFMobSlot *pMobSlot = NULL; IAAFDataDef *pDataDef = NULL; IAAFComponent *pComp = NULL; IAAFMob *pMob = NULL; CAAFBuiltinDefs defs (_pDictionary); try { // not already in dictionary checkResult(defs.cdDataDef()-> CreateInstance (IID_IAAFDataDef, (IUnknown **)&pDataDef)); hr = pDataDef->Initialize (kAAFDataDef_Test, L"Test", L"Test data"); hr = _pDictionary->RegisterDataDef (pDataDef); // Create a concrete subclass of event checkResult(defs.cdCommentMarker()-> CreateInstance(IID_IAAFEvent, (IUnknown **)&pEvent)); checkResult(pEvent->SetPosition(_position)); checkResult(pEvent->SetComment(const_cast<wchar_t*>(_eventComment))); checkResult(pEvent->QueryInterface(IID_IAAFComponent, (void **)&pComp)); checkResult(pComp->SetDataDef(pDataDef)); pComp->Release(); pComp = NULL; // Get the segment inteface to the event to install into the mob slot. checkResult(pEvent->QueryInterface(IID_IAAFSegment, (void **)&pSegment)); // Create and initialize an EventMobSlot checkResult(defs.cdEventMobSlot()-> CreateInstance(IID_IAAFEventMobSlot, (IUnknown **)&pEventMobSlot)); checkResult(pEventMobSlot->SetEditRate(const_cast<aafRational_t *>(&_editRate))); // Get the mob slot interface so that we can add the event segment. checkResult(pEventMobSlot->QueryInterface(IID_IAAFMobSlot, (void **)&pMobSlot)); // Add the event segment to the event mob slot. checkResult(pMobSlot->SetSegment(pSegment)); // Create the mob to hold the new event mob slot. checkResult(defs.cdCompositionMob()-> CreateInstance(IID_IAAFMob, (IUnknown **)&pMob)); checkResult(pMob->SetName(L"CompositionMob::Name:Test mob to hold an event mob slot")); // Append event slot to the composition mob. checkResult(pMob->AppendSlot(pMobSlot)); // Save the id of the composition mob that contains our test // event mob slot. checkResult(pMob->SetMobID(gMobID)); // Attach the mob to the header... checkResult(_pHeader->AddMob(pMob)); } catch (HRESULT& rHR) { hr = rHR; // fall through and handle cleanup } // Cleanup local references if (pMob) { pMob->Release(); pMob = NULL; } if (pDataDef) { pDataDef->Release(); pDataDef = NULL; } if (pComp) { pComp->Release(); pComp = NULL; } if (pMobSlot) { pMobSlot->Release(); pMobSlot = NULL; } if (pEventMobSlot) { pEventMobSlot->Release(); pEventMobSlot = NULL; } if (pSegment) { pSegment->Release(); pSegment = NULL; } if (pEvent) { pEvent->Release(); pEvent = NULL; } // Propogate the error if necessary. checkResult(hr); }