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 / chap14 / beeper3 / beeper.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  4.3 KB  |  170 lines

  1. /*
  2.  * BEEPER.H
  3.  * Beeper Automation Object #3 Chapter 14
  4.  *
  5.  * Classes that implement the Beeper object.
  6.  *
  7.  * Copyright (c)1993-1995 Microsoft Corporation, All Right Reserved
  8.  *
  9.  * Kraig Brockschmidt, Microsoft
  10.  * Internet  :  kraigb@microsoft.com
  11.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  12.  */
  13.  
  14.  
  15. #ifndef _BEEPER_H_
  16. #define _BEEPER_H_
  17.  
  18. /*
  19.  * This #define tells <bookguid.h> to not define GUIDs that will
  20.  * be defined in MKTYPLIB-generated header files, like ibeeper.h.
  21.  */
  22. #define GUIDS_FROM_TYPELIB
  23. #define INC_AUTOMATION
  24. #define CHAPTER14
  25. #include <inole.h>
  26. #include <malloc.h>
  27.  
  28. //This file is generated from MKTYPLIB
  29. #include "ibeeper.h"
  30.  
  31. //Help context ID for exceptions
  32. #define HID_SOUND_PROPERTY_LIMITATIONS  0x1E100
  33.  
  34. //English exception strings
  35. #define IDS_0_MIN                   16
  36. #define IDS_0_EXCEPTIONSOURCE       (IDS_0_MIN)
  37. #define IDS_0_EXCEPTIONINVALIDSOUND (IDS_0_MIN+1)
  38.  
  39. //German exception strings
  40. #define IDS_7_MIN                   32
  41. #define IDS_7_EXCEPTIONSOURCE       (IDS_7_MIN)
  42. #define IDS_7_EXCEPTIONINVALIDSOUND (IDS_7_MIN+1)
  43.  
  44.  
  45. //Forward class declarations for friend statements
  46. class CImpIDispatch;
  47. typedef CImpIDispatch *PCImpIDispatch;
  48. class CImpISupportErrorInfo;
  49. typedef CImpISupportErrorInfo *PCImpISupportErrorInfo;
  50.  
  51.  
  52. class CBeeper : public IBeeper
  53.     {
  54.     friend CImpIDispatch;
  55.  
  56.     protected:
  57.         ULONG           m_cRef;             //Object reference count
  58.         LPUNKNOWN       m_pUnkOuter;        //Controlling unknown
  59.         PFNDESTROYED    m_pfnDestroy;       //To call on closure
  60.  
  61.         long            m_lSound;
  62.  
  63.         //Our interfaces
  64.         PCImpIDispatch         m_pImpIDispatch;
  65.         PCImpISupportErrorInfo m_pImpISuppErr;
  66.  
  67.     public:
  68.         CBeeper(LPUNKNOWN, PFNDESTROYED);
  69.         ~CBeeper(void);
  70.  
  71.         BOOL         Init(void);
  72.  
  73.         //Non-delegating object IUnknown
  74.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  75.         STDMETHODIMP_(ULONG) AddRef(void);
  76.         STDMETHODIMP_(ULONG) Release(void);
  77.  
  78.         //IBeeper functions
  79.         STDMETHODIMP_(long)  get_Sound(void);
  80.         STDMETHODIMP_(void)  put_Sound(long);
  81.         STDMETHODIMP_(long)  Beep(void);
  82.     };
  83.  
  84. typedef CBeeper *PCBeeper;
  85.  
  86.  
  87. //DISPIDs for our dispinterface
  88. enum
  89.     {
  90.     PROPERTY_SOUND=0,
  91.     METHOD_BEEP
  92.     };
  93.  
  94. /*
  95.  * IDispatch interface implementations for the Beeper.
  96.  */
  97.  
  98. class CImpIDispatch : public IDispatch
  99.     {
  100.     public:
  101.         ULONG           m_cRef;     //For debugging
  102.  
  103.     private:
  104.         PCBeeper        m_pObj;
  105.         LPUNKNOWN       m_pUnkOuter;
  106.  
  107.         ITypeInfo      *m_pITINeutral;      //Type information
  108.         ITypeInfo      *m_pITIGerman;
  109.  
  110.     public:
  111.         CImpIDispatch(PCBeeper, LPUNKNOWN);
  112.         ~CImpIDispatch(void);
  113.  
  114.         //For raising exceptions
  115.         void                 Exception(WORD);
  116.  
  117.  
  118.         //IUnknown members that delegate to m_pUnkOuter.
  119.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  120.         STDMETHODIMP_(ULONG) AddRef(void);
  121.         STDMETHODIMP_(ULONG) Release(void);
  122.  
  123.         //IDispatch members
  124.         STDMETHODIMP GetTypeInfoCount(UINT *);
  125.         STDMETHODIMP GetTypeInfo(UINT, LCID, ITypeInfo **);
  126.         STDMETHODIMP GetIDsOfNames(REFIID, OLECHAR **, UINT, LCID
  127.             , DISPID *);
  128.         STDMETHODIMP Invoke(DISPID, REFIID, LCID, WORD
  129.             , DISPPARAMS *, VARIANT *, EXCEPINFO *, UINT *);
  130.     };
  131.  
  132.  
  133. //Exceptions we can throw from IDispatch::Invoke
  134. enum
  135.     {
  136.     EXCEPTION_NONE=0,
  137.     EXCEPTION_INVALIDSOUND=1000
  138.     };
  139.  
  140.  
  141. /*
  142.  * ISupportErrorInfo interface implementations for the Beeper.
  143.  */
  144.  
  145. class CImpISupportErrorInfo : public ISupportErrorInfo
  146.     {
  147.     public:
  148.         ULONG           m_cRef;     //For debugging
  149.  
  150.     private:
  151.         PCBeeper        m_pObj;
  152.         LPUNKNOWN       m_pUnkOuter;
  153.  
  154.     public:
  155.         CImpISupportErrorInfo(PCBeeper, LPUNKNOWN);
  156.         ~CImpISupportErrorInfo(void);
  157.  
  158.         //IUnknown members that delegate to m_pUnkOuter.
  159.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  160.         STDMETHODIMP_(ULONG) AddRef(void);
  161.         STDMETHODIMP_(ULONG) Release(void);
  162.  
  163.         //ISupportErrorInfo members
  164.         STDMETHODIMP InterfaceSupportsErrorInfo(REFIID);
  165.     };
  166.  
  167.  
  168.  
  169. #endif //_BEEPER_H_
  170.