home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / atl / connect / random.h < prev    next >
C/C++ Source or Header  |  1998-03-26  |  2KB  |  77 lines

  1. // Random.h : Declaration of the CRandom
  2. //
  3. // This is a part of the Active Template Library.
  4. // Copyright (C) 1996-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Active Template Library Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Active Template Library product.
  12.  
  13. #include "connres.h"       // main symbols
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CRandom
  17.  
  18. const int nMaxSessions = 10;
  19.  
  20. class CRandom :
  21.     public IDispatchImpl<IRandom, &IID_IRandom, &LIBID_CONNECTLib>,
  22.     public IConnectionPointContainerImpl<CRandom>,
  23.     public IConnectionPointImpl<CRandom, &IID_IRandomEvent, CComDynamicUnkArray>,
  24.     public ISupportErrorInfo,
  25.     public CComObjectRoot,
  26.     public CComCoClass<CRandom,&CLSID_CoRandom>
  27. {
  28. public:
  29.     CRandom()
  30.     {
  31.         memset(m_rsArray, 0, nMaxSessions*sizeof(RandomSessionData));
  32.     }
  33.     ~CRandom();
  34.  
  35. BEGIN_COM_MAP(CRandom)
  36.     COM_INTERFACE_ENTRY2(IDispatch, IRandom)
  37.     COM_INTERFACE_ENTRY(IRandom)
  38.     COM_INTERFACE_ENTRY(ISupportErrorInfo)
  39.     COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
  40. END_COM_MAP()
  41. //  DECLARE_NOT_AGGREGATABLE(CRandom)
  42. // Remove the comment from the line above if you don't want your object to
  43. // support aggregation.  The default is to support it
  44.  
  45.     DECLARE_REGISTRY_RESOURCEID(IDR_Random)
  46.  
  47. // Connection Point
  48.     BEGIN_CONNECTION_POINT_MAP(CRandom)
  49.         CONNECTION_POINT_ENTRY(IID_IRandomEvent)
  50.     END_CONNECTION_POINT_MAP()
  51.  
  52. // ISupportsErrorInfo
  53.     STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
  54.  
  55. // IRandom
  56.     STDMETHOD(Start)(long* pnID);
  57.     STDMETHOD(Stop)(long nID);
  58.     STDMETHOD(StopAll)();
  59.  
  60.     // method to broadcast a call on the current connections
  61.     HRESULT Fire(long  nID);
  62.     // info associated to each session
  63.     struct RandomSessionData
  64.     {
  65.         CRandom* pRandom;
  66.         HANDLE m_hEvent;
  67.         HANDLE m_hThread;
  68.         int m_nID;
  69.     };
  70. protected:
  71.  
  72.     RandomSessionData m_rsArray[nMaxSessions];
  73.     void CreateRandomSession(RandomSessionData& rs);
  74.  
  75.     _ThreadModel::AutoCriticalSection m_cs;
  76. };
  77.