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.

70 lines
1.7 KiB

  1. #if !defined(CTRL__SmObject_h__INCLUDED)
  2. #define CTRL__SmObject_h__INCLUDED
  3. #pragma once
  4. /***************************************************************************\
  5. *****************************************************************************
  6. *
  7. * class SmObjectT
  8. *
  9. * SmObjectT defines a common implementation class for building COM objects.
  10. * To create a new object type
  11. * - Define an interface
  12. * - Create a class that implements that interface except the COM functions
  13. * - Derive a class from SmObjectT that provides a Build() function to create
  14. * new instances.
  15. *
  16. *****************************************************************************
  17. \***************************************************************************/
  18. template <class base, class iface>
  19. class SmObjectT : public base
  20. {
  21. // Operations
  22. public:
  23. STDMETHOD(QueryInterface)(REFIID riid, void ** ppv)
  24. {
  25. if (ppv == NULL) {
  26. return E_POINTER;
  27. }
  28. int idx = 0;
  29. while (1) {
  30. if (IsEqualIID(riid, *base::s_rgpIID[idx])) {
  31. AddRef();
  32. iface * p = (iface *) this;
  33. *ppv = p;
  34. return S_OK;
  35. }
  36. idx++;
  37. if (base::s_rgpIID[idx] == NULL) {
  38. break;
  39. }
  40. }
  41. return E_NOINTERFACE;
  42. }
  43. STDMETHOD_(ULONG, AddRef)()
  44. {
  45. return ++m_cRef;
  46. }
  47. STDMETHOD_(ULONG, Release)()
  48. {
  49. ULONG ul = --m_cRef;
  50. if (ul == 0) {
  51. delete this;
  52. }
  53. return ul;
  54. }
  55. // Data
  56. protected:
  57. ULONG m_cRef;
  58. };
  59. #endif // CTRL__SmObject_h__INCLUDED