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.

114 lines
2.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: cqi.cxx
  7. //
  8. // Contents: implementations for QueryInterface test
  9. //
  10. // Functions:
  11. // CQI::CQI
  12. // CQI::~CQI
  13. // CQI::QueryInterface
  14. //
  15. // History: 06-Aug-92 Rickhi Created
  16. //
  17. //--------------------------------------------------------------------------
  18. #include <headers.cxx>
  19. #pragma hdrstop
  20. #include <cqisrv.hxx> // class definition
  21. //+-------------------------------------------------------------------------
  22. //
  23. // Method: CQI::CQI
  24. //
  25. // Synopsis: Creates an instance of CQI
  26. //
  27. // History: 06-Aug-92 Rickhi Created
  28. //
  29. //--------------------------------------------------------------------------
  30. CQI::CQI(void) : _cRefs(1)
  31. {
  32. }
  33. CQI::~CQI(void)
  34. {
  35. // automatic actions are enough
  36. }
  37. //+-------------------------------------------------------------------------
  38. //
  39. // Method: CQI::AddRef/Release
  40. //
  41. // Synopsis: track reference counts
  42. //
  43. // History: 06-Aug-92 Rickhi Created
  44. //
  45. //--------------------------------------------------------------------------
  46. STDMETHODIMP_(ULONG) CQI::AddRef(void)
  47. {
  48. InterlockedIncrement((LONG *)&_cRefs);
  49. return _cRefs;
  50. }
  51. STDMETHODIMP_(ULONG) CQI::Release(void)
  52. {
  53. if (InterlockedDecrement((LONG *)&_cRefs) == 0)
  54. {
  55. delete this;
  56. return 0;
  57. }
  58. return _cRefs;
  59. }
  60. //+-------------------------------------------------------------------------
  61. //
  62. // Method: CQI::QueryInterface
  63. //
  64. // Synopsis: returns ptr to requested interface.
  65. //
  66. // DANGER: this returns SUCCESS on almost every interface,
  67. // though the only valid methods on any interface are IUnknown.
  68. //
  69. // Arguments: [riid] - interface instance requested
  70. // [ppv] - where to put pointer to interface instance
  71. //
  72. // Returns: S_OK or E_NOINTERFACE
  73. //
  74. // History: 06-Aug-92 Rickhi Created
  75. //
  76. //--------------------------------------------------------------------------
  77. STDMETHODIMP CQI::QueryInterface(REFIID riid, void **ppv)
  78. {
  79. // the interface cant be one of these or marshalling will fail.
  80. if (IsEqualIID(riid,IID_IUnknown) ||
  81. IsEqualIID(riid,IID_IAdviseSink) ||
  82. IsEqualIID(riid,IID_IDataObject) ||
  83. IsEqualIID(riid,IID_IOleObject) ||
  84. IsEqualIID(riid,IID_IOleClientSite) ||
  85. IsEqualIID(riid,IID_IParseDisplayName) ||
  86. IsEqualIID(riid,IID_IPersistStorage) ||
  87. IsEqualIID(riid,IID_IPersistFile) ||
  88. IsEqualIID(riid,IID_IStorage) ||
  89. IsEqualIID(riid,IID_IOleContainer) ||
  90. IsEqualIID(riid,IID_IOleItemContainer) ||
  91. IsEqualIID(riid,IID_IOleInPlaceSite) ||
  92. IsEqualIID(riid,IID_IOleInPlaceActiveObject) ||
  93. IsEqualIID(riid,IID_IOleInPlaceObject) ||
  94. IsEqualIID(riid,IID_IOleInPlaceUIWindow) ||
  95. IsEqualIID(riid,IID_IOleInPlaceFrame) ||
  96. IsEqualIID(riid,IID_IOleWindow))
  97. {
  98. *ppv = (void *)(IUnknown *) this;
  99. AddRef();
  100. return S_OK;
  101. }
  102. else
  103. {
  104. *ppv = NULL;
  105. return E_NOINTERFACE;
  106. }
  107. }