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.

131 lines
3.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: QueryUnk.cxx
  7. //
  8. // Contents: Controlling IUnknown interface for IQuery/IRowset
  9. //
  10. // History: 18 Jul 1995 AlanW Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #include <rowset.hxx>
  16. #include "queryunk.hxx"
  17. //+-------------------------------------------------------------------------
  18. //
  19. // Member: CQueryUnknown::QueryInterface, public
  20. //
  21. // Arguments: [ifid] -- Interface id
  22. // [ppiuk] -- Interface return pointer
  23. //
  24. // Returns: Error. No rebind from this class is supported.
  25. //
  26. // History: 18 Jul 1995 AlanW Created
  27. //
  28. //--------------------------------------------------------------------------
  29. STDMETHODIMP CQueryUnknown::QueryInterface( REFIID ifid, void ** ppiuk )
  30. {
  31. *ppiuk = 0;
  32. return E_NOINTERFACE;
  33. }
  34. //+-------------------------------------------------------------------------
  35. //
  36. // Member: CQueryUnknown::AddRef, public
  37. //
  38. // Synopsis: Reference the virtual table.
  39. //
  40. // History: 18 Jul 1995 AlanW Created
  41. //
  42. //--------------------------------------------------------------------------
  43. STDMETHODIMP_(ULONG) CQueryUnknown::AddRef(void)
  44. {
  45. return InterlockedIncrement( (long *)&_ref );
  46. }
  47. //+-------------------------------------------------------------------------
  48. //
  49. // Member: CQueryUnknown::Release, public
  50. //
  51. // Synopsis: De-Reference the virtual table.
  52. //
  53. // Effects: If the ref count goes to 0 then the table is deleted.
  54. //
  55. // History: 18 Jul 1995 AlanW Created
  56. //
  57. //--------------------------------------------------------------------------
  58. STDMETHODIMP_(ULONG) CQueryUnknown::Release(void)
  59. {
  60. long l = InterlockedDecrement( (long *)&_ref );
  61. if ( l <= 0 )
  62. {
  63. // delete the rowsets allocated (if any)
  64. ReInit();
  65. _rUnk.Release(); // final reference, drop the owner's refcount
  66. return 0;
  67. }
  68. return l;
  69. }
  70. //+-------------------------------------------------------------------------
  71. //
  72. // Member: CQueryUnknown::ReInit, public
  73. //
  74. // Synopsis: Prepares for execution of a new query
  75. //
  76. // Arguments: [cRowsets] -- # of rowsets in ppRowsets
  77. // [ppRowsets] -- Array of CRowset pointers
  78. //
  79. // History: 18 Jul 1995 AlanW Created
  80. //
  81. //--------------------------------------------------------------------------
  82. void CQueryUnknown::ReInit( ULONG cRowsets,
  83. CRowset ** ppRowsets )
  84. {
  85. for (unsigned i = 0; i < _cRowsets; i++)
  86. delete _apRowsets[i];
  87. delete [] _apRowsets;
  88. Win4Assert(_ref == 0 || _ref == cRowsets);
  89. if (cRowsets == 0)
  90. _ref = 0;
  91. _cRowsets = cRowsets;
  92. _apRowsets = ppRowsets;
  93. if (cRowsets > 0)
  94. _rUnk.AddRef();
  95. }
  96. //+-------------------------------------------------------------------------
  97. //
  98. // Member: CQueryUnknown::~CQueryUnknown, private
  99. //
  100. // Synopsis: Clean up
  101. //
  102. // History: 18-Jun-93 KyleP Created
  103. //
  104. //--------------------------------------------------------------------------
  105. CQueryUnknown::~CQueryUnknown()
  106. {
  107. ReInit();
  108. }