I have attached a Observer on a document as below:
{ InterfacePtr<IActiveContext> iActiveContext(GetExecutionContextSession()->GetActiveContext(), UseDefaultIID()); if(iActiveContext == nil) break; else { IDocument *idocument= iActiveContext->GetContextDocument(); if(idocument == nil) break; UIDRef docRef(::GetUIDRef(reinterpret_cast<IPMUnknown*>(idocument))); InterfacePtr<IObserver> docObserver(docRef, IID_ICSDTSELECTIONOBSERVER); if (docObserver != nil) { docObserver->AutoAttach(); } } }} } //else} }