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 / beeper1 / beeper.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  3.4 KB  |  134 lines

  1. /*
  2.  * BEEPER.H
  3.  * Beeper Automation Object #1 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. #define INC_AUTOMATION
  19. #define CHAPTER14
  20. #include <inole.h>
  21. #include <malloc.h>
  22.  
  23. //Help context ID for exceptions
  24. #define HID_SOUND_PROPERTY_LIMITATIONS  0x1E100
  25.  
  26.  
  27. //English method, property, and exception strings
  28. #define IDS_0_MIN                   16
  29. #define IDS_0_EXCEPTIONSOURCE       (IDS_0_MIN)
  30. #define IDS_0_EXCEPTIONINVALIDSOUND (IDS_0_MIN+1)
  31. #define IDS_0_SOUND                 (IDS_0_MIN+2)
  32. #define IDS_0_BEEP                  (IDS_0_MIN+3)
  33.  
  34. #define IDS_0_NAMESMIN              (IDS_0_MIN+2)
  35.  
  36. //German method, property, and exception strings
  37. #define IDS_7_MIN                   32
  38. #define IDS_7_EXCEPTIONSOURCE       (IDS_7_MIN)
  39. #define IDS_7_EXCEPTIONINVALIDSOUND (IDS_7_MIN+1)
  40. #define IDS_7_SOUND                 (IDS_7_MIN+2)
  41. #define IDS_7_BEEP                  (IDS_7_MIN+3)
  42.  
  43. #define IDS_7_NAMESMIN              (IDS_7_MIN+2)
  44.  
  45. //Number of names in GetIDsOfNames
  46. #define CNAMES                      2
  47.  
  48. //Forward class declarations for friend statements
  49. class CImpIDispatch;
  50. typedef CImpIDispatch *PCImpIDispatch;
  51.  
  52.  
  53. class CBeeper : public IUnknown
  54.     {
  55.     friend CImpIDispatch;
  56.  
  57.     protected:
  58.         ULONG           m_cRef;             //Object reference count
  59.         LPUNKNOWN       m_pUnkOuter;        //Controlling unknown
  60.         PFNDESTROYED    m_pfnDestroy;       //To call on closure
  61.  
  62.         long            m_lSound;           //Type of sound
  63.         PCImpIDispatch  m_pImpIDispatch;    //Our IDispatch
  64.         LPTSTR          m_pszScratch;       //For GetIDsOfNames
  65.  
  66.     public:
  67.         CBeeper(LPUNKNOWN, PFNDESTROYED);
  68.         ~CBeeper(void);
  69.  
  70.         BOOL Init(void);
  71.  
  72.         //Non-delegating object IUnknown
  73.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  74.         STDMETHODIMP_(ULONG) AddRef(void);
  75.         STDMETHODIMP_(ULONG) Release(void);
  76.     };
  77.  
  78. typedef CBeeper *PCBeeper;
  79.  
  80.  
  81. //DISPIDs for our dispinterface
  82. enum
  83.     {
  84.     PROPERTY_SOUND=0,
  85.     METHOD_BEEP
  86.     };
  87.  
  88.  
  89. /*
  90.  * IDispatch interface implementations for the Beeper.
  91.  */
  92.  
  93. class CImpIDispatch : public IDispatch
  94.     {
  95.     public:
  96.         ULONG           m_cRef;
  97.  
  98.     private:
  99.         PCBeeper        m_pObj;
  100.         LPUNKNOWN       m_pUnkOuter;
  101.  
  102.     public:
  103.         CImpIDispatch(PCBeeper, LPUNKNOWN);
  104.         ~CImpIDispatch(void);
  105.  
  106.         //IUnknown members that delegate to m_pUnkOuter.
  107.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  108.         STDMETHODIMP_(ULONG) AddRef(void);
  109.         STDMETHODIMP_(ULONG) Release(void);
  110.  
  111.         //IDispatch members
  112.         STDMETHODIMP GetTypeInfoCount(UINT *);
  113.         STDMETHODIMP GetTypeInfo(UINT, LCID, ITypeInfo **);
  114.         STDMETHODIMP GetIDsOfNames(REFIID, OLECHAR **, UINT, LCID
  115.             , DISPID *);
  116.         STDMETHODIMP Invoke(DISPID, REFIID, LCID, WORD
  117.             , DISPPARAMS *, VARIANT *, EXCEPINFO *, UINT *);
  118.     };
  119.  
  120.  
  121.  
  122. //Exceptions we can throw from IDispatch::Invoke
  123. enum
  124.     {
  125.     EXCEPTION_NONE=0,
  126.     EXCEPTION_INVALIDSOUND=1000
  127.     };
  128.  
  129.  
  130. //Exception filling function for the EXCEPINFO structure.
  131. HRESULT STDAPICALLTYPE FillException(EXCEPINFO *);
  132.  
  133. #endif //_BEEPER_H_
  134.