home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / common / msdev98 / template / atl / compreg.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-16  |  2.4 KB  |  105 lines

  1. // [!HeaderName] : Declaration of the [!ClassName]
  2. [!crlf]
  3.  
  4. [!if=(FileExists, "FALSE")]
  5. #ifndef __[!UpperShortName]_H_
  6. #define __[!UpperShortName]_H_
  7. [!crlf]
  8. #include "resource.h"       // main symbols
  9. [!else]
  10. [!AddIncludeFile(TargetFile, "resource.h")]
  11. [!endif]
  12.  
  13. [!crlf]
  14. /////////////////////////////////////////////////////////////////////////////
  15. // [!ClassName]
  16.  
  17. class ATL_NO_VTABLE [!ClassName] : 
  18.     public CComObjectRootEx<CComSingleThreadModel>,
  19.     public CComCoClass<[!ClassName], &CLSID_[!CoClassName]>,
  20.     public IDispatchImpl<IComponentRegistrar, &IID_IComponentRegistrar, &LIBID_[!LibName]>
  21. {
  22. public:
  23.     [!ClassName]()
  24.     {
  25.     }
  26.  
  27. [!crlf]
  28. DECLARE_NO_REGISTRY()
  29.  
  30. [!crlf]
  31. BEGIN_COM_MAP([!ClassName])
  32.     COM_INTERFACE_ENTRY(IComponentRegistrar)
  33.     COM_INTERFACE_ENTRY(IDispatch)
  34. END_COM_MAP()
  35.  
  36. [!crlf]
  37. // IComponentRegistrar
  38. public:
  39.     STDMETHOD(Attach)(BSTR bstrPath)
  40.     {
  41.         return E_NOTIMPL;
  42.     }
  43.     STDMETHOD(RegisterAll)()
  44.     {
  45.         return _Module.RegisterServer(TRUE);
  46.     }
  47.     STDMETHOD(UnregisterAll)()    
  48.     {
  49.         _Module.UnregisterServer(TRUE);
  50.         return S_OK;
  51.     }
  52.     STDMETHOD(GetComponents)(SAFEARRAY **ppCLSIDs, SAFEARRAY **ppDescriptions)
  53.     {
  54.         _ATL_OBJMAP_ENTRY* pEntry = _Module.m_pObjMap;
  55.         int nComponents = 0;
  56.         while (pEntry->pclsid != NULL)
  57.         {
  58.             LPCTSTR pszDescription = pEntry->pfnGetObjectDescription();
  59.             if (pszDescription)
  60.                 nComponents++;
  61.             pEntry++;
  62.         }
  63.         SAFEARRAYBOUND rgBound[1];
  64.         rgBound[0].lLbound = 0;
  65.         rgBound[0].cElements = nComponents;
  66.         *ppCLSIDs = SafeArrayCreate(VT_BSTR, 1, rgBound);
  67.         *ppDescriptions = SafeArrayCreate(VT_BSTR, 1, rgBound);
  68.         pEntry = _Module.m_pObjMap;
  69.         for (long i=0; pEntry->pclsid != NULL; pEntry++)
  70.         {
  71.             LPCTSTR pszDescription = pEntry->pfnGetObjectDescription();
  72.             if (pszDescription)
  73.             {
  74.                 LPOLESTR pszCLSID;
  75.                 StringFromCLSID(*pEntry->pclsid, &pszCLSID);
  76.                 SafeArrayPutElement(*ppCLSIDs, &i, OLE2BSTR(pszCLSID));
  77.                 CoTaskMemFree(pszCLSID);
  78.                 SafeArrayPutElement(*ppDescriptions, &i, T2BSTR(pszDescription));
  79.                 i++;
  80.             }
  81.         }
  82.  
  83.         return S_OK;
  84.     }
  85.     STDMETHOD(RegisterComponent)(BSTR bstrCLSID)
  86.     {
  87.         CLSID clsid;
  88.         CLSIDFromString(bstrCLSID, &clsid);
  89.         _Module.RegisterServer(TRUE, &clsid);
  90.         return S_OK;
  91.     }
  92.     STDMETHOD(UnregisterComponent)(BSTR bstrCLSID)
  93.     {
  94.         CLSID clsid;
  95.         CLSIDFromString(bstrCLSID, &clsid);
  96.         _Module.UnregisterServer(&clsid);
  97.         return S_OK;
  98.     }
  99. };
  100.  
  101. [!crlf]
  102. [!if=(FileExists, "FALSE")]
  103. #endif //__[!UpperShortName]_H_
  104. [!endif]
  105.