home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / chap09 / linksrc / objects.h < prev    next >
C/C++ Source or Header  |  1996-05-21  |  7KB  |  252 lines

  1. /*
  2.  * OBJECTS.H
  3.  * File and Item Objects for Link Source, Chapter 9
  4.  *
  5.  * Classes to define the file and item objects supplied by
  6.  * this server as well as their interfaces.
  7.  *
  8.  * Copyright (c)1993-1995 Microsoft Corporation, All Right Reserved
  9.  *
  10.  * Kraig Brockschmidt, Microsoft
  11.  * Internet  :  kraigb@microsoft.com
  12.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  13.  */
  14.  
  15.  
  16. #ifndef _OBJECTS_H_
  17. #define _OBJECTS_H_
  18.  
  19. #define CHAPTER9
  20. #include <inole.h>
  21. #include <idescrip.h>
  22.  
  23. //Shared implementations
  24. class CImpIOleItemContainer;
  25. typedef CImpIOleItemContainer *PCImpIOleItemContainer;
  26.  
  27. class CImpIDescription;
  28. typedef CImpIDescription *PCImpIDescription;
  29.  
  30.  
  31. //FILEOBJ.CPP
  32.  
  33. class CImpIPersistFile;
  34. typedef CImpIPersistFile *PCImpIPersistFile;
  35.  
  36.  
  37. class CFileObject : public IUnknown
  38.     {
  39.     friend class CImpIPersistFile;
  40.     friend class CImpIOleItemContainer;
  41.     friend class CImpIDescription;
  42.  
  43.     protected:
  44.         ULONG           m_cRef;         //Object reference count
  45.         LPUNKNOWN       m_pUnkOuter;    //Controlling unknown
  46.         PFNDESTROYED    m_pfnDestroy;   //To call on closure
  47.  
  48.         CLSID           m_clsID;        //Object identity
  49.         OLECHAR         m_szFile[512];  //Current filename
  50.         IStorage       *m_pIStorage;    //Opened file
  51.         IMoniker       *m_pmk;          //Our name
  52.         DWORD           m_dwRegROT;     //ROT registration
  53.  
  54.         //Interfaces
  55.         PCImpIPersistFile         m_pImpIPersistFile;
  56.         PCImpIOleItemContainer    m_pImpIOleItemContainer;
  57.         PCImpIDescription         m_pImpIDescription;
  58.  
  59.     public:
  60.         CFileObject(LPUNKNOWN, PFNDESTROYED);
  61.         ~CFileObject(void);
  62.  
  63.         BOOL Init(void);
  64.  
  65.         //Non-delegating object IUnknown
  66.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  67.         STDMETHODIMP_(ULONG) AddRef(void);
  68.         STDMETHODIMP_(ULONG) Release(void);
  69.     };
  70.  
  71. typedef CFileObject *PCFileObject;
  72.  
  73.  
  74. class CImpIPersistFile : public IPersistFile
  75.     {
  76.     protected:
  77.         ULONG           m_cRef;      //Interface reference count
  78.         PCFileObject    m_pObj;      //Backpointer to the object
  79.         LPUNKNOWN       m_pUnkOuter; //For delegation
  80.  
  81.     public:
  82.         CImpIPersistFile(PCFileObject, LPUNKNOWN);
  83.         ~CImpIPersistFile(void);
  84.  
  85.         STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  86.         STDMETHODIMP_(ULONG) AddRef(void);
  87.         STDMETHODIMP_(ULONG) Release(void);
  88.  
  89.         STDMETHODIMP GetClassID(LPCLSID);
  90.         STDMETHODIMP IsDirty(void);
  91.         STDMETHODIMP Load(LPCOLESTR, DWORD);
  92.         STDMETHODIMP Save(LPCOLESTR, BOOL);
  93.         STDMETHODIMP SaveCompleted(LPCOLESTR);
  94.         STDMETHODIMP GetCurFile(LPOLESTR *);
  95.     };
  96.  
  97.  
  98.  
  99. //CONTITEM.CPP
  100.  
  101. /*
  102.  * Implementation of an item object that itself contains other
  103.  * items, thus it implements IOleItemContainer.  IDescription is
  104.  * added only for reason of this sample.
  105.  */
  106.  
  107.  
  108. class CContainerItem : public IUnknown
  109.     {
  110.     friend class CImpIOleItemContainer;
  111.     friend class CImpIDescription;
  112.  
  113.     protected:
  114.         ULONG           m_cRef;         //Object reference count
  115.         LPUNKNOWN       m_pUnkParent;   //CFileObject's pointer
  116.         PFNDESTROYED    m_pfnDestroy;   //To call on closure
  117.         IStorage       *m_pIStorage;    //Our storage
  118.         IMoniker       *m_pmk;          //Our name
  119.         DWORD           m_dwRegROT;     //ROT Registration
  120.  
  121.         //Interfaces
  122.         PCImpIOleItemContainer    m_pImpIOleItemContainer;
  123.         PCImpIDescription         m_pImpIDescription;
  124.  
  125.     public:
  126.         CContainerItem(LPUNKNOWN, PFNDESTROYED);
  127.         ~CContainerItem(void);
  128.  
  129.         BOOL Init(IMoniker *, IBindCtx *, LPOLESTR, IStorage *);
  130.  
  131.         //Non-delegating object IUnknown
  132.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  133.         STDMETHODIMP_(ULONG) AddRef(void);
  134.         STDMETHODIMP_(ULONG) Release(void);
  135.     };
  136.  
  137. typedef CContainerItem *PCContainerItem;
  138.  
  139.  
  140.  
  141. //SIMPITEM.CPP
  142.  
  143. /*
  144.  * Implementation of a simple item object with only IDescription.
  145.  */
  146.  
  147. class CSimpleItem : public IUnknown
  148.     {
  149.     friend class CImpIDescription;
  150.  
  151.     protected:
  152.         ULONG           m_cRef;         //Object reference count
  153.         LPUNKNOWN       m_pUnkParent;   //CContainerItems's pointer
  154.         PFNDESTROYED    m_pfnDestroy;   //To call on closure
  155.         IStorage       *m_pIStorage;    //Our storage
  156.         IMoniker       *m_pmk;          //Our name
  157.         DWORD           m_dwRegROT;     //ROT Registration
  158.  
  159.         //Interfaces
  160.         PCImpIDescription         m_pImpIDescription;
  161.  
  162.     public:
  163.         CSimpleItem(LPUNKNOWN, PFNDESTROYED);
  164.         ~CSimpleItem(void);
  165.  
  166.         BOOL Init(IMoniker *, IBindCtx *, LPOLESTR, IStorage *);
  167.  
  168.         //Non-delegating object IUnknown
  169.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  170.         STDMETHODIMP_(ULONG) AddRef(void);
  171.         STDMETHODIMP_(ULONG) Release(void);
  172.     };
  173.  
  174. typedef CSimpleItem *PCSimpleItem;
  175.  
  176.  
  177.  
  178.  
  179. //IOLECONT.CPP
  180. /*
  181.  * IOleItemContainer implementation that is shared between
  182.  * CFileObject and CContainerItem.  The flag to the constructor
  183.  * indicates which object exposes any given instantiation.
  184.  */
  185.  
  186. class CImpIOleItemContainer : public IOleItemContainer
  187.     {
  188.     protected:
  189.         ULONG               m_cRef;
  190.         LPUNKNOWN           m_pUnkOuter;
  191.  
  192.         BOOL                m_fFileObj;
  193.         PCFileObject        m_pObjFile;
  194.         PCContainerItem     m_pObjCont;
  195.  
  196.     public:
  197.         CImpIOleItemContainer(LPVOID, LPUNKNOWN, BOOL);
  198.         ~CImpIOleItemContainer(void);
  199.  
  200.         HRESULT GetRunning(LPOLESTR, IBindCtx *, REFIID, void **
  201.             , BOOL);
  202.  
  203.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  204.         STDMETHODIMP_(ULONG) AddRef(void);
  205.         STDMETHODIMP_(ULONG) Release(void);
  206.  
  207.         STDMETHODIMP ParseDisplayName(LPBC, LPOLESTR, ULONG *
  208.                          , LPMONIKER *);
  209.         STDMETHODIMP EnumObjects(DWORD, LPENUMUNKNOWN *);
  210.         STDMETHODIMP LockContainer(BOOL);
  211.         STDMETHODIMP GetObject(LPOLESTR, DWORD, LPBINDCTX, REFIID
  212.                          , PPVOID);
  213.         STDMETHODIMP GetObjectStorage(LPOLESTR, LPBINDCTX, REFIID
  214.                          , PPVOID);
  215.         STDMETHODIMP IsRunning(LPOLESTR);
  216.     };
  217.  
  218.  
  219. #define SZOPENSTORAGE  OLETEXT("OpenStorage")
  220.  
  221.  
  222. //IDESCRIP.CPP
  223. /*
  224.  * IDescription implementation that is shared between
  225.  * CFileObject, CContainerItem, and CSimpleItem.  The
  226.  * IStorage argument to the constructor is all that this
  227.  * implementation needs, so there's no backpointer.
  228.  */
  229.  
  230. class CImpIDescription : public IDescription
  231.     {
  232.     protected:
  233.         ULONG               m_cRef;
  234.         LPUNKNOWN           m_pUnkOuter;
  235.         IStorage           *m_pIStorage;
  236.  
  237.     public:
  238.         CImpIDescription(LPUNKNOWN);
  239.         ~CImpIDescription(void);
  240.  
  241.         void SetStorage(IStorage *);
  242.  
  243.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  244.         STDMETHODIMP_(ULONG) AddRef(void);
  245.         STDMETHODIMP_(ULONG) Release(void);
  246.  
  247.         STDMETHODIMP GetText(LPOLESTR, ULONG);
  248.     };
  249.  
  250.  
  251. #endif //_OBJECTS_H_
  252.