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.

105 lines
4.8 KiB

  1. #define ARRAYLEN(a) (sizeof(a) / sizeof((a)[0]))
  2. #define BREAK_ON_FAIL(hr) if (FAILED(hr)) { break; } else 1;
  3. #define BREAK_ON_ERROR(lr) if ((lr) != ERROR_SUCCESS) { break; } else 1;
  4. #ifndef offsetof
  5. #define offsetof(type,field) ((size_t)&(((type*)0)->field))
  6. #endif
  7. //---------------------------------------------------------------
  8. // IUnknown
  9. //---------------------------------------------------------------
  10. //
  11. // This declares the set of IUnknown methods and is for general-purpose
  12. // use inside classes that inherit from IUnknown
  13. //
  14. #define DECLARE_IUNKNOWN_METHODS \
  15. STDMETHOD(QueryInterface) (REFIID riid, LPVOID FAR* ppvObj); \
  16. STDMETHOD_(ULONG,AddRef) (void); \
  17. STDMETHOD_(ULONG,Release) (void)
  18. //
  19. // This is for use in declaring non-aggregatable objects. It declares the
  20. // IUnknown methods and reference counter, m_ulRefs.
  21. // m_ulRefs should be initialized to 1 in the constructor of the object
  22. //
  23. #define DECLARE_STANDARD_IUNKNOWN \
  24. DECLARE_IUNKNOWN_METHODS; \
  25. ULONG m_ulRefs
  26. //
  27. // NOTE: this does NOT implement QueryInterface, which must be
  28. // implemented by each object
  29. //
  30. #define IMPLEMENT_STANDARD_IUNKNOWN(cls) \
  31. STDMETHODIMP_(ULONG) cls##::AddRef() \
  32. { return InterlockedIncrement((LONG*)&m_ulRefs); } \
  33. STDMETHODIMP_(ULONG) cls##::Release() \
  34. { ULONG ulRet = InterlockedDecrement((LONG*)&m_ulRefs); \
  35. if (0 == ulRet) { delete this; } \
  36. return ulRet; }
  37. //-----------------------------------------------------------------------------
  38. // IClassFactory
  39. //-----------------------------------------------------------------------------
  40. #define JF_IMPLEMENT_CLASSFACTORY(cls) \
  41. class cls##CF : public IClassFactory \
  42. { \
  43. public: \
  44. STDMETHOD(QueryInterface)(REFIID riid, LPVOID *ppvObj); \
  45. STDMETHOD_(ULONG,AddRef)(void); \
  46. STDMETHOD_(ULONG,Release)(void); \
  47. \
  48. STDMETHOD(CreateInstance)(IUnknown* pUnkOuter, \
  49. REFIID riid, LPVOID* ppvObj); \
  50. STDMETHOD(LockServer)(BOOL fLock); \
  51. }; \
  52. \
  53. STDMETHODIMP \
  54. cls##CF::QueryInterface(REFIID riid, LPVOID* ppvObj) \
  55. { \
  56. if (IsEqualIID(IID_IUnknown, riid) || \
  57. IsEqualIID(IID_IClassFactory, riid)) \
  58. { \
  59. *ppvObj = (IUnknown*)(IClassFactory*) this; \
  60. this->AddRef(); \
  61. return S_OK; \
  62. } \
  63. \
  64. *ppvObj = NULL; \
  65. return E_NOINTERFACE; \
  66. } \
  67. \
  68. STDMETHODIMP_(ULONG) \
  69. cls##CF::AddRef() \
  70. { \
  71. return CDll::AddRef(); \
  72. } \
  73. \
  74. STDMETHODIMP_(ULONG) \
  75. cls##CF::Release() \
  76. { \
  77. return CDll::Release(); \
  78. } \
  79. \
  80. STDMETHODIMP \
  81. cls##CF::LockServer(BOOL fLock) \
  82. { \
  83. CDll::LockServer(fLock); \
  84. \
  85. return S_OK; \
  86. }