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 / chap16 / beeper6 / beeper.h < prev    next >
C/C++ Source or Header  |  1995-05-03  |  7KB  |  253 lines

  1. /*
  2.  * BEEPER.H
  3.  * Beeper Object #6 with Property Pages Chapter 16
  4.  *
  5.  * Classes that implement the Beeper object for supporting
  6.  * property pages.
  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 _BEEPER_H_
  17. #define _BEEPER_H_
  18.  
  19. /*
  20.  * This #define tells <bookguid.h> to not define GUIDs that will
  21.  * be defined in MKTYPLIB-generated header files, like ibeeper.h.
  22.  */
  23. #define GUIDS_FROM_TYPELIB
  24. #define INC_AUTOMATION
  25. //CHAPTER16MOD
  26. #define INC_CONTROLS
  27. #define CHAPTER16
  28. //End CHAPTER16MOD
  29. #include <inole.h>
  30. #include <malloc.h>
  31.  
  32. //This file is generated from MKTYPLIB
  33. #include "ibeeper.h"
  34.  
  35. //Help context ID for exceptions
  36. #define HID_SOUND_PROPERTY_LIMITATIONS  0x1E100
  37.  
  38. //English exception strings
  39. #define IDS_0_MIN                   16
  40. #define IDS_0_EXCEPTIONSOURCE       (IDS_0_MIN)
  41. #define IDS_0_EXCEPTIONINVALIDSOUND (IDS_0_MIN+1)
  42.  
  43. //German exception strings
  44. #define IDS_7_MIN                   32
  45. #define IDS_7_EXCEPTIONSOURCE       (IDS_7_MIN)
  46. #define IDS_7_EXCEPTIONINVALIDSOUND (IDS_7_MIN+1)
  47.  
  48.  
  49. //Forward class declarations for friend statements
  50. class CImpIDispatch;
  51. typedef CImpIDispatch *PCImpIDispatch;
  52.  
  53. //CHAPTER16MOD
  54. class CImpISpecifyPP;
  55. typedef CImpISpecifyPP *PCImpISpecifyPP;
  56.  
  57. class CImpIConnPtCont;
  58. typedef CImpIConnPtCont *PCImpIConnPtCont;
  59.  
  60. class CConnectionPoint;
  61. typedef CConnectionPoint *PCConnectionPoint;
  62.  
  63. //Number of property pages we support
  64. #define CPROPPAGES      1
  65. //End CHAPTER16MOD
  66.  
  67. class CBeeper : public IBeeper
  68.     {
  69.     friend CImpIDispatch;
  70.     //CHAPTER16MOD
  71.     friend CImpISpecifyPP;
  72.     friend CImpIConnPtCont;
  73.     friend CConnectionPoint;
  74.     //End CHAPTER16MOD
  75.  
  76.     protected:
  77.         ULONG           m_cRef;             //Object reference count
  78.         LPUNKNOWN       m_pUnkOuter;        //Controlling unknown
  79.         PFNDESTROYED    m_pfnDestroy;       //To call on closure
  80.  
  81.         long            m_lSound;
  82.         PCImpIDispatch  m_pImpIDispatch;    //Our IDispatch
  83.  
  84.         //CHAPTER16MOD
  85.         PCImpISpecifyPP  m_pImpISpecifyPP;   //Our ISpecifyPropertyPages
  86.         PCImpIConnPtCont m_pImpIConnPtCont;  //Our IConnectionPointContainer
  87.  
  88.         IPropertyNotifySink *m_pIPropNotifySink;    //Client's
  89.         PCConnectionPoint    m_pConnPt;             //Ours
  90.         //End CHAPTER16MOD
  91.  
  92.     public:
  93.         CBeeper(LPUNKNOWN, PFNDESTROYED);
  94.         ~CBeeper(void);
  95.  
  96.         BOOL         Init(void);
  97.  
  98.         //Non-delegating object IUnknown
  99.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  100.         STDMETHODIMP_(ULONG) AddRef(void);
  101.         STDMETHODIMP_(ULONG) Release(void);
  102.  
  103.         //IBeeper functions
  104.         STDMETHODIMP_(long)  get_Sound(void);
  105.         STDMETHODIMP_(void)  put_Sound(long);
  106.         STDMETHODIMP_(long)  Beep(void);
  107.     };
  108.  
  109. typedef CBeeper *PCBeeper;
  110.  
  111.  
  112. //DISPIDs for our dispinterface
  113. enum
  114.     {
  115.     PROPERTY_SOUND=0,
  116.     METHOD_BEEP
  117.     };
  118.  
  119. /*
  120.  * IDispatch interface implementations for the Beeper.
  121.  */
  122.  
  123. class CImpIDispatch : public IDispatch
  124.     {
  125.     public:
  126.         ULONG           m_cRef;     //For debugging
  127.  
  128.     private:
  129.         PCBeeper        m_pObj;
  130.         LPUNKNOWN       m_pUnkOuter;
  131.         WORD            m_wException;
  132.  
  133.         ITypeInfo      *m_pITINeutral;      //Type information
  134.         ITypeInfo      *m_pITIGerman;
  135.  
  136.     public:
  137.         CImpIDispatch(PCBeeper, LPUNKNOWN);
  138.         ~CImpIDispatch(void);
  139.  
  140.         /*
  141.          * This function is called from CBeeper functions that
  142.          * are called from within DispInvoke to set an exception.
  143.          * This is because the CBeeper functions have no way to
  144.          * tell DispInvoke of such exceptions, so we have to
  145.          * tell our IDispatch::Invoke implementation directly.
  146.          */
  147.         void Exception(WORD);
  148.  
  149.         //IUnknown members that delegate to m_pUnkOuter.
  150.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  151.         STDMETHODIMP_(ULONG) AddRef(void);
  152.         STDMETHODIMP_(ULONG) Release(void);
  153.  
  154.         //IDispatch members
  155.         STDMETHODIMP GetTypeInfoCount(UINT *);
  156.         STDMETHODIMP GetTypeInfo(UINT, LCID, ITypeInfo **);
  157.         STDMETHODIMP GetIDsOfNames(REFIID, OLECHAR **, UINT, LCID
  158.             , DISPID *);
  159.         STDMETHODIMP Invoke(DISPID, REFIID, LCID, WORD
  160.             , DISPPARAMS *, VARIANT *, EXCEPINFO *, UINT *);
  161.     };
  162.  
  163.  
  164. //Exceptions we can throw from IDispatch::Invoke
  165. enum
  166.     {
  167.     EXCEPTION_NONE=0,
  168.     EXCEPTION_INVALIDSOUND=1000
  169.     };
  170.  
  171.  
  172. //Exception filling function for the EXCEPINFO structure.
  173. HRESULT STDAPICALLTYPE FillException(EXCEPINFO *);
  174.  
  175. //CHAPTER16MOD
  176.  
  177. class CImpISpecifyPP : public ISpecifyPropertyPages
  178.     {
  179.     protected:
  180.         ULONG           m_cRef;      //Interface reference count
  181.         PCBeeper        m_pObj;      //Backpointer to the object
  182.         LPUNKNOWN       m_pUnkOuter; //For delegation
  183.  
  184.     public:
  185.         CImpISpecifyPP(PCBeeper, LPUNKNOWN);
  186.         ~CImpISpecifyPP(void);
  187.  
  188.         STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  189.         STDMETHODIMP_(ULONG) AddRef(void);
  190.         STDMETHODIMP_(ULONG) Release(void);
  191.  
  192.         STDMETHODIMP GetPages(CAUUID *);
  193.     };
  194.  
  195.  
  196.  
  197. //CONNPT.CPP
  198.  
  199. class CImpIConnPtCont : public IConnectionPointContainer
  200.     {
  201.     private:
  202.         ULONG               m_cRef;      //Interface ref count
  203.         PCBeeper            m_pObj;      //Backpointer to object
  204.         LPUNKNOWN           m_pUnkOuter; //Controlling unknown
  205.  
  206.     public:
  207.         CImpIConnPtCont(PCBeeper, LPUNKNOWN);
  208.         ~CImpIConnPtCont(void);
  209.  
  210.         //IUnknown members
  211.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  212.         STDMETHODIMP_(DWORD) AddRef(void);
  213.         STDMETHODIMP_(DWORD) Release(void);
  214.  
  215.         //IConnectionPointContainer members
  216.         STDMETHODIMP EnumConnectionPoints(IEnumConnectionPoints **);
  217.         STDMETHODIMP FindConnectionPoint(REFIID, IConnectionPoint **);
  218.     };
  219.  
  220.  
  221. //This object only supports one connection per point
  222. #define CCONNMAX    1
  223. #define ADVISEKEY   72388       //Arbitrary
  224.  
  225. class CConnectionPoint : public IConnectionPoint
  226.     {
  227.     private:
  228.         ULONG           m_cRef;     //Object reference count
  229.         PCBeeper        m_pObj;     //Containing object.
  230.  
  231.     public:
  232.         CConnectionPoint(PCBeeper);
  233.         ~CConnectionPoint(void);
  234.  
  235.         //IUnknown members
  236.         STDMETHODIMP         QueryInterface(REFIID, LPVOID *);
  237.         STDMETHODIMP_(ULONG) AddRef(void);
  238.         STDMETHODIMP_(ULONG) Release(void);
  239.  
  240.         //IConnectionPoint members
  241.         STDMETHODIMP GetConnectionInterface(IID *);
  242.         STDMETHODIMP GetConnectionPointContainer
  243.             (IConnectionPointContainer **);
  244.         STDMETHODIMP Advise(LPUNKNOWN, DWORD *);
  245.         STDMETHODIMP Unadvise(DWORD);
  246.         STDMETHODIMP EnumConnections(IEnumConnections **);
  247.     };
  248.  
  249.  
  250. //End CHAPTER16MOD
  251.  
  252. #endif //_BEEPER_H_
  253.