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.

107 lines
2.5 KiB

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