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.

38 lines
1.5 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All rights reserved.
  2. //
  3. // Helper classes for implementing IUnknown.
  4. //
  5. #pragma once
  6. // Implements AddRef/Release with ref count beginning at 1. Also handles module locking.
  7. class ComRefCount
  8. : public IUnknown
  9. {
  10. public:
  11. ComRefCount();
  12. virtual ~ComRefCount() {}
  13. // IUnknown
  14. STDMETHOD_(ULONG, AddRef)();
  15. STDMETHOD_(ULONG, Release)();
  16. private:
  17. long m_cRef;
  18. };
  19. // Use this macro to declare AddRef and Release in the public section of your derived class. This is necessary because
  20. // the IUnknown section of any interfaces aren't linked to the methods in this base class.
  21. #define ComRefCountAddRefRelease STDMETHOD_(ULONG, AddRef)() { return ComRefCount::AddRef(); } STDMETHOD_(ULONG, Release)() { return ComRefCount::Release(); }
  22. // Implements QueryInterface for a single interface (in addition to IUnknown). You must pass the IID of your interface (iidExpected)
  23. // and a pointer to that interface (pvInterface).
  24. class ComSingleInterface
  25. : public ComRefCount
  26. {
  27. public:
  28. STDMETHOD(QueryInterface)(const IID &iid, void **ppv, const IID&iidExpected, void *pvInterface);
  29. };
  30. // Use this macro to declare AddRef, Release, and QueryInterface function in the public section of your derived class.
  31. #define ComSingleInterfaceUnknownMethods(IMyInterface) ComRefCountAddRefRelease STDMETHOD(QueryInterface)(const IID &iid, void **ppv) { return ComSingleInterface::QueryInterface(iid, ppv, IID_##IMyInterface, static_cast<IMyInterface*>(this)); }