home *** CD-ROM | disk | FTP | other *** search
/ Troubleshooting Netware Systems / CSTRIAL0196.BIN / attach / msj / v10n05 / autoole.exe / BEEP.EXE / BEEPER.H < prev    next >
C/C++ Source or Header  |  1995-05-01  |  5KB  |  217 lines

  1. /*
  2.  * BEEPER.H
  3.  * Beeper Automation Object
  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.  
  23. #define INC_OLE2
  24. #include <windows.h>
  25. #include <ole2.h>
  26. #include <ole2ver.h>
  27. #include <malloc.h>
  28.  
  29. #ifdef INITGUIDS
  30. #include <initguid.h>
  31. #endif //INITGUIDS
  32.  
  33.  
  34. #ifndef WIN32
  35. #include <dispatch.h>
  36. #include <olenls.h>
  37. #else
  38. #include <oleauto.h>
  39. #endif
  40.  
  41. #ifdef WIN32
  42. #include <tchar.h>
  43. #ifdef UNICODE
  44. #include <wchar.h>
  45. #endif
  46. #endif
  47.  
  48. //This file is generated from MKTYPLIB
  49. #include "ibeeper.h"
  50.  
  51. //Help context ID for exceptions
  52. #define HID_SOUND_PROPERTY_LIMITATIONS  0x1E100
  53.  
  54. //English exception strings
  55. #define IDS_0_MIN                   16
  56. #define IDS_0_EXCEPTIONSOURCE       (IDS_0_MIN)
  57. #define IDS_0_EXCEPTIONINVALIDSOUND (IDS_0_MIN+1)
  58.  
  59. //German exception strings
  60. #define IDS_7_MIN                   32
  61. #define IDS_7_EXCEPTIONSOURCE       (IDS_7_MIN)
  62. #define IDS_7_EXCEPTIONINVALIDSOUND (IDS_7_MIN+1)
  63.  
  64.  
  65. #ifndef PPVOID
  66. typedef LPVOID * PPVOID;
  67. #endif  //PPVOID
  68.  
  69. //Type for an object-destroyed callback
  70. typedef void (*PFNDESTROYED)(void);
  71.  
  72. //Macros for setting EXCEPINFO structures
  73. #define SETEXCEPINFO(ei, excode, src, desc, file, ctx, func, scd) \
  74.     {\
  75.     (ei).wCode=excode;\
  76.     (ei).wReserved=0;\
  77.     (ei).bstrSource=src;\
  78.     (ei).bstrDescription=desc;\
  79.     (ei).bstrHelpFile=file;\
  80.     (ei).dwHelpContext=ctx;\
  81.     (ei).pvReserved=NULL;\
  82.     (ei).pfnDeferredFillIn=func;\
  83.     (ei).scode=scd;\
  84.     }
  85.  
  86.  
  87. #define INITEXCEPINFO(ei) \
  88.         SETEXCEPINFO(ei,0,NULL,NULL,NULL,0L,NULL,S_OK)
  89.  
  90.  
  91.  
  92. //DeleteInterfaceImp calls 'delete' and NULLs the pointer
  93. #define DeleteInterfaceImp(p)\
  94.             {\
  95.             if (NULL!=p)\
  96.                 {\
  97.                 delete p;\
  98.                 p=NULL;\
  99.                 }\
  100.             }
  101.  
  102.  
  103. //ReleaseInterface calls 'Release' and NULLs the pointer
  104. #define ReleaseInterface(p)\
  105.             {\
  106.             if (NULL!=p)\
  107.                 {\
  108.                 p->Release();\
  109.                 p=NULL;\
  110.                 }\
  111.             }
  112.  
  113.  
  114.  
  115.  
  116. //Forward class declarations for friend statements
  117. class CImpIDispatch;
  118. typedef CImpIDispatch *PCImpIDispatch;
  119.  
  120.  
  121. class CBeeper : public IBeeper
  122.     {
  123.     friend CImpIDispatch;
  124.  
  125.     protected:
  126.         ULONG           m_cRef;             //Object reference count
  127.         LPUNKNOWN       m_pUnkOuter;        //Controlling unknown
  128.         PFNDESTROYED    m_pfnDestroy;       //To call on closure
  129.  
  130.         long            m_lSound;
  131.         PCImpIDispatch  m_pImpIDispatch;    //Our IDispatch
  132.  
  133.     public:
  134.         CBeeper(LPUNKNOWN, PFNDESTROYED);
  135.         ~CBeeper(void);
  136.  
  137.         BOOL         Init(void);
  138.  
  139.         //Non-delegating object IUnknown
  140.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  141.         STDMETHODIMP_(ULONG) AddRef(void);
  142.         STDMETHODIMP_(ULONG) Release(void);
  143.  
  144.         //IBeeper functions
  145.         STDMETHODIMP_(long)  get_Sound(void);
  146.         STDMETHODIMP_(void)  put_Sound(long);
  147.         STDMETHODIMP_(long)  Beep(void);
  148.     };
  149.  
  150. typedef CBeeper *PCBeeper;
  151.  
  152.  
  153. //DISPIDs for our dispinterface
  154. enum
  155.     {
  156.     PROPERTY_SOUND=0,
  157.     METHOD_BEEP
  158.     };
  159.  
  160. /*
  161.  * IDispatch interface implementations for the Beeper.
  162.  */
  163.  
  164. class CImpIDispatch : public IDispatch
  165.     {
  166.     public:
  167.         ULONG           m_cRef;     //For debugging
  168.  
  169.     private:
  170.         PCBeeper        m_pObj;
  171.         LPUNKNOWN       m_pUnkOuter;
  172.         WORD            m_wException;
  173.  
  174.         ITypeInfo      *m_pITINeutral;      //Type information
  175.         ITypeInfo      *m_pITIGerman;
  176.  
  177.     public:
  178.         CImpIDispatch(PCBeeper, LPUNKNOWN);
  179.         ~CImpIDispatch(void);
  180.  
  181.         /*
  182.          * This function is called from CBeeper functions that
  183.          * are called from within DispInvoke to set an exception.
  184.          * This is because the CBeeper functions have no way to
  185.          * tell DispInvoke of such exceptions, so we have to
  186.          * tell our IDispatch::Invoke implementation directly.
  187.          */
  188.         void Exception(WORD);
  189.  
  190.         //IUnknown members that delegate to m_pUnkOuter.
  191.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  192.         STDMETHODIMP_(ULONG) AddRef(void);
  193.         STDMETHODIMP_(ULONG) Release(void);
  194.  
  195.         //IDispatch members
  196.         STDMETHODIMP GetTypeInfoCount(UINT *);
  197.         STDMETHODIMP GetTypeInfo(UINT, LCID, ITypeInfo **);
  198.         STDMETHODIMP GetIDsOfNames(REFIID, TCHAR **, UINT, LCID
  199.             , DISPID *);
  200.         STDMETHODIMP Invoke(DISPID, REFIID, LCID, WORD
  201.             , DISPPARAMS *, VARIANT *, EXCEPINFO *, UINT *);
  202.     };
  203.  
  204.  
  205. //Exceptions we can throw from IDispatch::Invoke
  206. enum
  207.     {
  208.     EXCEPTION_NONE=0,
  209.     EXCEPTION_INVALIDSOUND=1000
  210.     };
  211.  
  212.  
  213. //Exception filling function for the EXCEPINFO structure.
  214. HRESULT STDAPICALLTYPE FillException(EXCEPINFO *);
  215.  
  216. #endif //_BEEPER_H_
  217.