Leaked source code of windows server 2003
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.

116 lines
2.3 KiB

  1. //
  2. // enumguid.h
  3. //
  4. #ifndef ENUMGUID_H
  5. #define ENUMGUID_H
  6. #include "private.h"
  7. #include "comcat.h"
  8. // I would love to make this a class,
  9. // but I can't get the compiler to accept a run-time template arg
  10. typedef struct _SHARED_GUID_ARRAY
  11. {
  12. ULONG cRef;
  13. ULONG cGuid;
  14. GUID rgGuid[1]; // one or more...
  15. } SHARED_GUID_ARRAY;
  16. inline void SGA_AddRef(SHARED_GUID_ARRAY *pga)
  17. {
  18. pga->cRef++;
  19. }
  20. inline void SGA_Release(SHARED_GUID_ARRAY *pga)
  21. {
  22. if (pga == NULL)
  23. return;
  24. Assert(pga->cRef > 0);
  25. if (--pga->cRef == 0)
  26. {
  27. cicMemFree(pga);
  28. }
  29. }
  30. inline SHARED_GUID_ARRAY *SGA_Alloc(ULONG cGuid)
  31. {
  32. return (SHARED_GUID_ARRAY *)cicMemAlloc(sizeof(SHARED_GUID_ARRAY)+sizeof(GUID)*cGuid-sizeof(GUID));
  33. }
  34. inline BOOL SGA_ReAlloc(SHARED_GUID_ARRAY **ppga, ULONG cGuid)
  35. {
  36. SHARED_GUID_ARRAY *pga;
  37. pga = (SHARED_GUID_ARRAY *)cicMemReAlloc(*ppga, sizeof(SHARED_GUID_ARRAY)+sizeof(GUID)*cGuid-sizeof(GUID));
  38. if (pga != NULL)
  39. {
  40. *ppga = pga;
  41. return TRUE;
  42. }
  43. return FALSE;
  44. }
  45. inline SHARED_GUID_ARRAY *SGA_Init(ULONG cGuid, const GUID *prgGuid)
  46. {
  47. SHARED_GUID_ARRAY *pga;
  48. pga = SGA_Alloc(cGuid);
  49. if (pga == NULL)
  50. return NULL;
  51. pga->cRef = 1;
  52. pga->cGuid = cGuid;
  53. if (prgGuid != NULL)
  54. {
  55. memcpy(pga->rgGuid, prgGuid, cGuid*sizeof(GUID));
  56. }
  57. return pga;
  58. }
  59. class CEnumGuid : public IEnumGUID,
  60. public CComObjectRootImmx
  61. {
  62. public:
  63. CEnumGuid();
  64. virtual ~CEnumGuid();
  65. BEGIN_COM_MAP_IMMX(CEnumGuid)
  66. COM_INTERFACE_ENTRY(IEnumGUID)
  67. END_COM_MAP_IMMX()
  68. IMMX_OBJECT_IUNKNOWN_FOR_ATL()
  69. // derived class supplies an _Init() method here
  70. // It must initialize:
  71. // _nCur
  72. // _pga
  73. //
  74. // the default dtor will clean these guys up.
  75. virtual BOOL _Init(ULONG cGuid, const GUID *prgGuid)
  76. {
  77. _pga = SGA_Init(cGuid, prgGuid);
  78. return (_pga != NULL);
  79. }
  80. STDMETHODIMP Clone(IEnumGUID **pClone);
  81. STDMETHODIMP Next(ULONG ulCount, GUID *pguid, ULONG *pcFetched);
  82. STDMETHODIMP Reset();
  83. STDMETHODIMP Skip(ULONG ulCount);
  84. protected:
  85. int _nCur;
  86. SHARED_GUID_ARRAY *_pga;
  87. DBG_ID_DECLARE;
  88. };
  89. #endif // ENUMGUID_H