Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.6 KiB

  1. // PageFact.h: interface for the CPageFactory class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #ifndef __PAGEFACT_H_
  5. #define __PAGEFACT_H_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. typedef struct
  10. {
  11. const CLSID *pclsid;
  12. _ATL_CREATORFUNC* pfnCreateInstance;
  13. } _PAGEMAP_ENTRY;
  14. #define PAGE_ENTRY2(clsid,class) {&clsid, class::_CreatorClass::CreateInstance},
  15. #define PAGE_ENTRY(class) PAGE_ENTRY2(__uuidof(class), class)
  16. #define BEGIN_PAGE_MAP(class) const _PAGEMAP_ENTRY class::s_rgPage[] = {
  17. #define END_PAGE_MAP() {&CLSID_NULL, NULL} };
  18. class CPageFactory :
  19. public CComObjectRoot,
  20. public ITaskPageFactory
  21. {
  22. public:
  23. DECLARE_NOT_AGGREGATABLE(CPageFactory)
  24. BEGIN_COM_MAP(CPageFactory)
  25. COM_INTERFACE_ENTRY(ITaskPageFactory)
  26. END_COM_MAP()
  27. // ITaskPageFactory
  28. STDMETHOD(CreatePage)(REFCLSID rclsidPage, REFIID riid, void **ppv)
  29. {
  30. HRESULT hr = CLASS_E_CLASSNOTAVAILABLE;
  31. for (UINT i = 0; CLSID_NULL != *s_rgPage[i].pclsid; i++)
  32. {
  33. if (rclsidPage == *s_rgPage[i].pclsid)
  34. {
  35. if (NULL != s_rgPage[i].pfnCreateInstance)
  36. {
  37. hr = s_rgPage[i].pfnCreateInstance(NULL, riid, ppv);
  38. }
  39. break;
  40. }
  41. }
  42. return hr;
  43. }
  44. template <class Q>
  45. static HRESULT CreateInstance(Q** pp)
  46. {
  47. return CPageFactory::_CreatorClass::CreateInstance(NULL, __uuidof(Q), (void**)pp);
  48. }
  49. private:
  50. static const _PAGEMAP_ENTRY s_rgPage[];
  51. };
  52. #endif // __PAGEFACT_H_