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.

141 lines
3.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: query.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "pch.h"
  11. #include "attrqry.h"
  12. #ifdef DEBUG_ALLOCATOR
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. #endif
  19. ///////////////////////////////////////////////////////////////////////////////
  20. CADSIQueryObject2::CADSIQueryObject2()
  21. {
  22. m_bInitialized = FALSE;
  23. m_pwszFilter = NULL;
  24. m_pObj = NULL;
  25. m_SearchHandle = NULL;
  26. }
  27. CADSIQueryObject2::~CADSIQueryObject2()
  28. {
  29. if (m_SearchHandle)
  30. {
  31. m_pObj->CloseSearchHandle (m_SearchHandle);
  32. }
  33. if (aSearchPref != NULL)
  34. {
  35. delete aSearchPref;
  36. aSearchPref = NULL;
  37. }
  38. }
  39. HRESULT CADSIQueryObject2::Init(IDirectorySearch * pObj)
  40. {
  41. HRESULT hr = S_OK;
  42. m_pObj = pObj;
  43. m_bInitialized = TRUE;
  44. return hr;
  45. }
  46. HRESULT CADSIQueryObject2::SetAttributeList (LPTSTR *pszAttribs, INT cAttrs)
  47. {
  48. m_pszAttribs = pszAttribs;
  49. m_nAttrs = cAttrs;
  50. return S_OK;
  51. }
  52. const int nSearchPrefs = 4;
  53. HRESULT CADSIQueryObject2::SetSearchPrefs (ADS_SCOPEENUM scope, ULONG nMaxObjectCount)
  54. {
  55. HRESULT hr;
  56. int nNumPrefs = nSearchPrefs;
  57. if (nMaxObjectCount == 0)
  58. {
  59. nNumPrefs--;
  60. }
  61. aSearchPref = new ADS_SEARCHPREF_INFO[nNumPrefs];
  62. if (m_bInitialized)
  63. {
  64. aSearchPref[0].dwSearchPref = ADS_SEARCHPREF_SEARCH_SCOPE;
  65. aSearchPref[0].vValue.dwType = ADSTYPE_INTEGER;
  66. aSearchPref[0].vValue.Integer = scope;
  67. aSearchPref[1].dwSearchPref = ADS_SEARCHPREF_ASYNCHRONOUS;
  68. aSearchPref[1].vValue.dwType = ADSTYPE_BOOLEAN;
  69. aSearchPref[1].vValue.Boolean = TRUE;
  70. aSearchPref[2].dwSearchPref = ADS_SEARCHPREF_PAGESIZE;
  71. aSearchPref[2].vValue.dwType = ADSTYPE_INTEGER;
  72. aSearchPref[2].vValue.Integer = QUERY_PAGESIZE;
  73. if (nMaxObjectCount > 0)
  74. {
  75. aSearchPref[3].dwSearchPref = ADS_SEARCHPREF_SIZE_LIMIT;
  76. aSearchPref[3].vValue.dwType = ADSTYPE_INTEGER;
  77. aSearchPref[3].vValue.Integer = nMaxObjectCount;
  78. }
  79. hr = m_pObj->SetSearchPreference (aSearchPref, nNumPrefs);
  80. delete aSearchPref;
  81. aSearchPref = NULL;
  82. }
  83. else
  84. {
  85. hr = E_ADS_BAD_PATHNAME;
  86. }
  87. return hr;
  88. }
  89. const int NUM_PREFS=3;
  90. HRESULT CADSIQueryObject2::DoQuery()
  91. {
  92. HRESULT hr;
  93. if (m_bInitialized)
  94. {
  95. hr = m_pObj->ExecuteSearch (m_pwszFilter,
  96. m_pszAttribs,
  97. m_nAttrs,
  98. &m_SearchHandle);
  99. }
  100. else
  101. {
  102. hr = E_ADS_BAD_PATHNAME;
  103. }
  104. return hr;
  105. }
  106. HRESULT CADSIQueryObject2::GetNextRow()
  107. {
  108. if (m_bInitialized)
  109. {
  110. return m_pObj->GetNextRow (m_SearchHandle);
  111. }
  112. return E_ADS_BAD_PATHNAME;
  113. }
  114. HRESULT CADSIQueryObject2::GetColumn(LPWSTR Attribute, PADS_SEARCH_COLUMN pColumnData)
  115. {
  116. if (m_bInitialized)
  117. {
  118. return m_pObj->GetColumn (m_SearchHandle,
  119. Attribute,
  120. pColumnData);
  121. }
  122. return E_ADS_BAD_PATHNAME;
  123. }