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.

163 lines
3.6 KiB

  1. //
  2. // enumsrvmru.cpp: Implements IEnumStr for the server MRU list
  3. // used by autocomplete code
  4. //
  5. // Copyright Microsoft Corporation 2000
  6. #include "stdafx.h"
  7. #ifndef OS_WINCE
  8. #define TRC_GROUP TRC_GROUP_UI
  9. #define TRC_FILE "enumsrvmru"
  10. #include <atrcapi.h>
  11. #include "enumsrvmru.h"
  12. STDMETHODIMP CEnumSrvMru::QueryInterface(
  13. REFIID riid,
  14. void **ppvObject)
  15. {
  16. DC_BEGIN_FN("QueryInterface");
  17. TRC_ASSERT(ppvObject, (TB,_T("ppvObject is NULL\n")));
  18. if(!ppvObject)
  19. {
  20. return E_INVALIDARG;
  21. }
  22. if ( IID_IEnumString == riid )
  23. *ppvObject = (void *)((IEnumString*)this);
  24. else if ( IID_IUnknown == riid )
  25. *ppvObject = (void *)((IUnknown *)this);
  26. else
  27. {
  28. *ppvObject = 0;
  29. return E_NOINTERFACE;
  30. }
  31. AddRef();
  32. DC_END_FN();
  33. return S_OK;
  34. } //QueryInterface
  35. STDMETHODIMP_(ULONG) CEnumSrvMru::AddRef()
  36. {
  37. return InterlockedIncrement(&_refCount);
  38. } //AddRef
  39. STDMETHODIMP_(ULONG) CEnumSrvMru::Release()
  40. {
  41. DC_BEGIN_FN("Release");
  42. TRC_ASSERT(_refCount > 0, (TB,_T("_refCount invalid %d"), _refCount));
  43. LONG refCount = InterlockedDecrement(&_refCount);
  44. if ( refCount <= 0 )
  45. delete this;
  46. DC_END_FN();
  47. return (ULONG) refCount;
  48. } //Release
  49. //Clone a copy of this object
  50. STDMETHODIMP CEnumSrvMru::Clone(IEnumString ** ppEnumStr)
  51. {
  52. return E_NOTIMPL;
  53. }
  54. //
  55. // Next enum
  56. // celt - number of elements requested
  57. // rgelt - array of elements to return
  58. // pceltFetched - pointer to number of elements actually supplied
  59. //
  60. STDMETHODIMP CEnumSrvMru::Next( ULONG celt,
  61. LPOLESTR * rgelt,
  62. ULONG * pceltFetched )
  63. {
  64. DC_BEGIN_FN("Next");
  65. *pceltFetched = 0;
  66. while( _iCurrEnum < SH_NUM_SERVER_MRU &&
  67. *pceltFetched < celt)
  68. {
  69. //Need to allocate powerful COM memory
  70. //caller frees
  71. LPOLESTR pwzMRU= (LPOLESTR)CoTaskMemAlloc(SH_MAX_ADDRESS_LENGTH*sizeof(OLECHAR));
  72. if(!pwzMRU)
  73. {
  74. return E_OUTOFMEMORY;
  75. }
  76. DC_WSTRNCPY(pwzMRU, _szMRU[_iCurrEnum++], SH_MAX_ADDRESS_LENGTH);
  77. rgelt[(*pceltFetched)++] = pwzMRU;
  78. }
  79. //
  80. // Fill in remaining request items with NULLS
  81. //
  82. ULONG cAdded = *pceltFetched;
  83. while (cAdded < celt)
  84. {
  85. rgelt[cAdded++] = NULL;
  86. }
  87. DC_END_FN();
  88. return *pceltFetched == celt ? S_OK : S_FALSE;
  89. }
  90. //
  91. // Skips celt elements
  92. // if cannot skip as many as requested don't skip any
  93. //
  94. STDMETHODIMP CEnumSrvMru::Skip( ULONG celt )
  95. {
  96. DC_BEGIN_FN("Next");
  97. TRC_ASSERT(_iCurrEnum < SH_NUM_SERVER_MRU, (TB,_T("_iCurEnum out of range: %d"),
  98. _iCurrEnum));
  99. if(_iCurrEnum + celt < SH_NUM_SERVER_MRU)
  100. {
  101. _iCurrEnum += celt;
  102. return S_OK;
  103. }
  104. DC_END_FN();
  105. return S_FALSE;
  106. }
  107. //
  108. // Initialize the string collection with strings
  109. // from the TscSettings's server MRU list
  110. //
  111. BOOL CEnumSrvMru::InitializeFromTscSetMru( CTscSettings* pTscSet)
  112. {
  113. DC_BEGIN_FN("InitializeFromSHMru");
  114. USES_CONVERSION;
  115. TRC_ASSERT(pTscSet, (TB,_T("pTscSet NULL")));
  116. if(!pTscSet)
  117. {
  118. return FALSE;
  119. }
  120. for(int i=0; i<TSC_NUM_SERVER_MRU; i++)
  121. {
  122. PWCHAR wszServer = T2W( (LPTSTR)pTscSet->GetMRUServer(i));
  123. if(!wszServer)
  124. {
  125. return FALSE;
  126. }
  127. DC_WSTRNCPY(_szMRU[i], wszServer, SH_MAX_ADDRESS_LENGTH);
  128. }
  129. DC_END_FN();
  130. return TRUE;
  131. }
  132. #endif //OS_WINCE