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.

74 lines
1.9 KiB

  1. // EnumExch.cpp : Implementation of CExEnumApp and DLL registration.
  2. #include "stdafx.h"
  3. #include "ExLdap.h"
  4. #include "ExEnum.h"
  5. #include "EnumExch.h"
  6. #import "\bin\McsVarSetMin.tlb" no_namespace
  7. /////////////////////////////////////////////////////////////////////////////
  8. //
  9. STDMETHODIMP CEnumExch::OpenServer(BSTR exchangeServer,BSTR cred,BSTR password)
  10. {
  11. DWORD rc = 0;
  12. m_e.m_connection.SetCredentials(cred,password);
  13. if ( ! rc )
  14. {
  15. rc = m_e.InitConnection(exchangeServer,LDAP_PORT);
  16. }
  17. return HRESULT_FROM_WIN32(rc);
  18. }
  19. STDMETHODIMP CEnumExch::DoQuery(BSTR query, ULONG scope, BSTR basepoint, IUnknown **pVS)
  20. {
  21. // build the attribute list
  22. IVarSetPtr pVarSet = (*pVS);
  23. _bstr_t attrName;
  24. long nAttributes = pVarSet->get(L"EnumExch.NumAttributes");
  25. WCHAR ** ppAttributes = new PWCHAR[nAttributes + 1];
  26. long i;
  27. WCHAR key[100];
  28. WCHAR ** vals = NULL;
  29. DWORD rc = 0;
  30. for ( i = 0 ;i <= nAttributes ; i++ )
  31. ppAttributes[i] = NULL;
  32. for ( i = 0 ; i < nAttributes ; i++ )
  33. {
  34. swprintf(key,L"EnumExch.Attributes.%ld",i);
  35. attrName = pVarSet->get(key);
  36. ppAttributes[i] = new WCHAR[attrName.length() + 1];
  37. UStrCpy(ppAttributes[i],(WCHAR*)attrName);
  38. }
  39. // Call the enumerator
  40. rc = m_e.Open(query,basepoint,(SHORT)scope,100,nAttributes,ppAttributes);
  41. long count = 0;
  42. if (! rc )
  43. {
  44. while ( 0 == ( rc = m_e.Next(&vals)) )
  45. {
  46. for ( i = 0 ; i < nAttributes ; i++ )
  47. {
  48. swprintf(key,L"EnumExch.Values.%ld.%ld",count,i);
  49. pVarSet->put(key,vals[i]);
  50. }
  51. count++;
  52. }
  53. if ( rc == ERROR_NOT_FOUND )
  54. {
  55. rc = 0;
  56. }
  57. }
  58. return HRESULT_FROM_WIN32(rc);
  59. }