/*============================================================================ * * File Name: OleItemContainer.cpp * * Class Tribble * * Description: Implements IOleItemContainer for the Tribble object * * Author: Roger Hughes * * Date: 16/10/98 * *==============================================================================*/ #include "stdafx.h" #include "Tribble.h" #include "TribbleClass.h" /// externs extern CString ResolveIIDName(REFIID riid); //IOleItemContainer HRESULT Tribble::GetObject( /* [in] */ LPOLESTR pszItem, /* [in] */ DWORD dwSpeedNeeded, /* [unique][in] */ IBindCtx __RPC_FAR *pbc, /* [in] */ REFIID riid, /* [iid_is][out] */ void **ppvObject) { OutputDebugString("Tribble IOleItemContainer::GetObject\n"); HRESULT hr = S_OK; // Here the world is you Oyster... // You need to return a pointer to a // Tribble that has something to do // with the string "pszItem". // "pszItem" could be a Stream, of an // object in a list etc. // You just return that object. // Step one - check that it's a Tribble // that the caller is asking for. if(riid != IID_ITribble) { CString strWrongInterface = ResolveIIDName(riid); CString strOut; strOut.Format("Incorrect Interface: %s\n", strWrongInterface); OutputDebugString(strOut); hr = E_NOINTERFACE; // What - gotos!!!! JUst for demonstration goto TheExit; } // Step two - Theoretically we check the ROT // although in this implementation we're the object // we're already running so we return this one // so there's no need to bother // Step 3 - In real life, item monikers usually // refer to part of a file - but in this case // we just override the colour attribute m_Colour = pszItem; *ppvObject = (void *)this; // Step 4 - Add ourselves a File!Item composite // to show that an object is running that supports // this particular File item combination if(m_pmkFile && !m_pmkCmp) { IMoniker * pmk; // Use this Wrapper to create an Item Moniker hr = CreateItemMoniker(OLESTR("!"),pszItem,&pmk); if(SUCCEEDED(hr)) { // Combine the two into a composite hr = m_pmkFile->ComposeWith(pmk, FALSE,&m_pmkCmp); if(SUCCEEDED(hr)) { IRunningObjectTable *pROT; hr = GetRunningObjectTable(0, &pROT); if (SUCCEEDED(hr)) { //Register as weak so clients can free us pROT->Register(0,(IUnknown *)(ITribble*)this,m_pmkCmp,&m_dwROTCmp); pROT->Release(); } // At this point, use IROTView.exe to see this // object in the Running Object Table } // don't need this now pmk->Release(); } } TheExit: // This value gets returned to BindToObject() return hr; } HRESULT Tribble::GetObjectStorage( /* [in] */ LPOLESTR pszItem, /* [unique][in] */ IBindCtx __RPC_FAR *pbc, /* [in] */ REFIID riid, /* [iid_is][out] */ void * *ppvStorage) { OutputDebugString("Tribble:IOleItemContainer:GeTObjectStorgage\n"); return E_NOTIMPL; } HRESULT Tribble::IsRunning(/* [in] */ LPOLESTR pszItem) { OutputDebugString("Tribble:IOleItemContainer::IsRunning\n"); return E_NOTIMPL; } //IOleContainer methods HRESULT Tribble::EnumObjects( /* [in] */ DWORD grfFlags, /* [out] */ IEnumUnknown * *ppenum) { OutputDebugString("Tribble::IOleItemContainer::EnumObjects\n"); return E_NOTIMPL; } HRESULT Tribble::LockContainer(/* [in] */ BOOL fLock) { OutputDebugString("Tribble::IOleItemContainer::LockContainer\n"); if(fLock) LockModule(); else UnlockModule(); return S_OK; } /*============================================================================ * End of File: OleItemContainer.cpp ==============================================================================*/