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.

106 lines
2.5 KiB

  1. // EnumVar.cpp: implementation of the CEnumVar class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include <COMDEF.h>
  6. #include "MigrVar.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. //////////////////////////////////////////////////////////////////////
  13. // Construction/Destruction
  14. //////////////////////////////////////////////////////////////////////
  15. CEnumVar::CEnumVar(IEnumVARIANT * pEnum)
  16. {
  17. m_pEnum = pEnum;
  18. m_pEnum->AddRef();
  19. }
  20. CEnumVar::~CEnumVar()
  21. {
  22. m_pEnum->Release();
  23. }
  24. BOOL CEnumVar::Next(long flag, SAttrInfo * pAttr)
  25. {
  26. // This function enumerates through and gets name strings for the Values
  27. ULONG ulFetched=0;
  28. IADs * pADs=NULL;
  29. _variant_t var;
  30. BSTR bstrName;
  31. if ( !m_pEnum )
  32. {
  33. return FALSE;
  34. }
  35. HRESULT hr = m_pEnum->Next(1, &var, &ulFetched);
  36. if ( ulFetched == 0 || FAILED(hr) )
  37. return FALSE;
  38. if ( var.vt == VT_BSTR )
  39. {
  40. // We have a bstring so lets just return that as names
  41. wcscpy(pAttr->sName, var.bstrVal);
  42. wcscpy(pAttr->sSamName, var.bstrVal);
  43. }
  44. else
  45. {
  46. if ( flag == NULL )
  47. return FALSE;
  48. // We have a Dispatch Pointer
  49. IDispatch * pDisp = V_DISPATCH(&var);
  50. // We ask for a IAds pointer
  51. hr = pDisp->QueryInterface( IID_IADs, (void**)&pADs);
  52. // and Ask IAds pointer to give us the name of the container.
  53. // Now fill up information that they need.
  54. // Common Name
  55. if ( flag | F_Name )
  56. {
  57. hr = pADs->get_Name(&bstrName);
  58. if ( FAILED(hr) )
  59. return FALSE;
  60. wcscpy( pAttr->sName, bstrName);
  61. }
  62. // SAM Account Name
  63. if ( flag | F_SamName )
  64. {
  65. hr = pADs->Get(L"sAMAccountName", &var);
  66. if ( FAILED(hr) )
  67. return FALSE;
  68. wcscpy( pAttr->sSamName, var.bstrVal);
  69. }
  70. // Class name of the object.
  71. if ( flag | F_Class )
  72. {
  73. hr = pADs->get_Class(&bstrName);
  74. if ( FAILED(hr) )
  75. return FALSE;
  76. wcscpy( pAttr->sClass, bstrName);
  77. }
  78. // Group Type
  79. /* if ( flag | F_GroupType )
  80. {
  81. hr = pADs->Get(L"groupType", &var);
  82. if ( FAILED(hr) )
  83. {
  84. var.vt = VT_I4;
  85. var.lVal = -1;
  86. }
  87. pAttr->groupType = var.lVal;
  88. }
  89. */ }
  90. return TRUE;
  91. }