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

  1. // cpduck.h: Declaration of CProxyIDuckInt
  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. #ifndef _INC_CPDUCK_H
  14. #define _INC_CPDUCK_H
  15.  
  16. #include "iduckint.h"
  17. extern const IID IID_IDuckInt;
  18. //////////////////////////////////////////////////////////////////////////////
  19. // CProxyIDuckInt
  20. template <class T>
  21. class CProxyIDuckInt : public IConnectionPointImpl<T, &IID_IDuckInt, CComDynamicUnkArray>
  22. {
  23. public:
  24.  
  25. //IDuckInt : IUnknown
  26. public:
  27.     HRESULT Fire_Quack(
  28.         BSTR szWhosCalling)
  29.     {
  30.         int n = 1;
  31.         WCHAR* pch = szWhosCalling;
  32.         while (*pch != L'X')
  33.             pch++;
  34.  
  35.         T* pT = (T*)this;
  36.         pT->Lock();
  37.         HRESULT ret;
  38.         IUnknown** pp = m_vec.begin();
  39.         while (pp < m_vec.end())
  40.         {
  41.             if (*pp != NULL)
  42.             {
  43.                 *pch = (n / 10) + L'0';
  44.                 *(pch + 1)= (n % 10) + L'0';
  45.                 n++;
  46.  
  47.                 IDuckInt* pIDuckInt = reinterpret_cast<IDuckInt*>(*pp);
  48.                 ret = pIDuckInt->Quack(szWhosCalling);
  49.             }
  50.             pp++;
  51.         }
  52.         pT->Unlock();
  53.         return ret;
  54.     }
  55.     HRESULT Fire_Flap(
  56.         BSTR szWhosCalling)
  57.     {
  58.         int n = 1;
  59.         WCHAR* pch = szWhosCalling;
  60.         while (*pch != L'X')
  61.             pch++;
  62.  
  63.         T* pT = (T*)this;
  64.         pT->Lock();
  65.         HRESULT ret;
  66.         IUnknown** pp = m_vec.begin();
  67.         while (pp < m_vec.end())
  68.         {
  69.             if (*pp != NULL)
  70.             {
  71.                 *pch = (n / 10) + L'0';
  72.                 *(pch + 1)= (n % 10) + L'0';
  73.                 n++;
  74.  
  75.                 IDuckInt* pIDuckInt = reinterpret_cast<IDuckInt*>(*pp);
  76.                 ret = pIDuckInt->Flap(szWhosCalling);
  77.             }
  78.             pp++;
  79.         }
  80.         pT->Unlock();
  81.         return ret;
  82.     }
  83.     HRESULT Fire_Paddle(
  84.         BSTR szWhosCalling)
  85.     {
  86.         int n = 1;
  87.         WCHAR* pch = szWhosCalling;
  88.         while (*pch != L'X')
  89.             pch++;
  90.  
  91.         T* pT = (T*)this;
  92.         pT->Lock();
  93.         HRESULT ret;
  94.         IUnknown** pp = m_vec.begin();
  95.         while (pp < m_vec.end())
  96.         {
  97.             if (*pp != NULL)
  98.             {
  99.                 *pch = (n / 10) + L'0';
  100.                 *(pch + 1)= (n % 10) + L'0';
  101.                 n++;
  102.  
  103.                 IDuckInt* pIDuckInt = reinterpret_cast<IDuckInt*>(*pp);
  104.                 ret = pIDuckInt->Paddle(szWhosCalling);
  105.             }
  106.             pp++;
  107.         }
  108.         pT->Unlock();
  109.         return ret;
  110.     }
  111.     HRESULT Fire_Walk(
  112.         BSTR szWhosCalling)
  113.     {
  114.         int n = 1;
  115.         WCHAR* pch = szWhosCalling;
  116.         while (*pch != L'X')
  117.             pch++;
  118.  
  119.         T* pT = (T*)this;
  120.         pT->Lock();
  121.         HRESULT ret;
  122.         IUnknown** pp = m_vec.begin();
  123.         while (pp < m_vec.end())
  124.         {
  125.             if (*pp != NULL)
  126.             {
  127.                 *pch = (n / 10) + L'0';
  128.                 *(pch + 1)= (n % 10) + L'0';
  129.                 n++;
  130.  
  131.                 IDuckInt* pIDuckInt = reinterpret_cast<IDuckInt*>(*pp);
  132.                 ret = pIDuckInt->Walk(szWhosCalling);
  133.             }
  134.             pp++;
  135.         }
  136.         pT->Unlock();
  137.         return ret;
  138.     }
  139. };
  140.  
  141. #endif
  142.