home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / ADSDK.ZIP / Samples / General / ADQI / ADsPropertyList.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-08  |  4.3 KB  |  197 lines

  1. //----------------------------------------------------------------------------
  2. //
  3. //  Microsoft Active Directory 2.5 Sample Code
  4. //
  5. //  Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. //  File:       ADsPropertyList.cpp
  8. //
  9. //  Contents:   IADsPropertyList, IADsPropertyEntry and IADsPropertyValue usage
  10. //
  11. //
  12. //----------------------------------------------------------------------------
  13.  
  14. #include "stdafx.h"
  15. #include "ADQI.h"
  16. #include "ADsPropertyList.h"
  17.  
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CDlgIADsPropertyList dialog
  26.  
  27.  
  28. CDlgIADsPropertyList::CDlgIADsPropertyList(LPUNKNOWN pUnk, CWnd* pParent /*=NULL*/)
  29.     : CDialog(CDlgIADsPropertyList::IDD, pParent)
  30. {
  31.     //{{AFX_DATA_INIT(CDlgIADsPropertyList)
  32.     m_sAttribute = _T("");
  33.     //}}AFX_DATA_INIT
  34.  
  35.     HRESULT hr;
  36.     m_pPropList = NULL;
  37.     hr = pUnk->QueryInterface( IID_IADsPropertyList, (void **) &m_pPropList );
  38.     if ( !SUCCEEDED(hr) )
  39.     {
  40.         AfxMessageBox(_T("Fatal Error! QI for IADsPropertyList failed"));
  41.         return;
  42.     }
  43.     pUnk->Release();
  44.  
  45.     
  46.     //////////////////////////////////////////
  47.     // Retrieve the data to the cache
  48.     ////////////////////////////////////////////
  49.     IADs *pADs=NULL;
  50.     hr = m_pPropList->QueryInterface( IID_IADs, (void**) &pADs );
  51.     if ( SUCCEEDED(hr) )
  52.     {
  53.         hr = pADs->GetInfo();
  54.         pADs->Release();
  55.     }
  56.  
  57.  
  58.  
  59. }
  60.  
  61. CDlgIADsPropertyList::~CDlgIADsPropertyList()
  62. {
  63.     if ( m_pPropList )
  64.     {
  65.          m_pPropList->Release();
  66.     }
  67.  
  68. }
  69.  
  70. void CDlgIADsPropertyList::DoDataExchange(CDataExchange* pDX)
  71. {
  72.     CDialog::DoDataExchange(pDX);
  73.     //{{AFX_DATA_MAP(CDlgIADsPropertyList)
  74.     DDX_Control(pDX, IDC_VALUELIST, m_cValueList);
  75.     DDX_Control(pDX, IDC_ADSTYPE, m_cADsType);
  76.     DDX_Text(pDX, IDC_ATTRIBUTE, m_sAttribute);
  77.     //}}AFX_DATA_MAP
  78. }
  79.  
  80.  
  81. BEGIN_MESSAGE_MAP(CDlgIADsPropertyList, CDialog)
  82.     //{{AFX_MSG_MAP(CDlgIADsPropertyList)
  83.     ON_BN_CLICKED(IDC_GET, OnGet)
  84.     ON_BN_CLICKED(IDC_PURGE, OnPurge)
  85.     //}}AFX_MSG_MAP
  86. END_MESSAGE_MAP()
  87.  
  88. /////////////////////////////////////////////////////////////////////////////
  89. // CDlgIADsPropertyList message handlers
  90. //
  91. //
  92. //  IADsPropertyList->Next
  93. //  IADsPropertyEnty
  94. //
  95.  
  96.  
  97. BOOL CDlgIADsPropertyList::OnInitDialog() 
  98. {
  99.     CDialog::OnInitDialog();
  100.     m_cADsType.SetCurSel(ADSTYPE_CASE_IGNORE_STRING-1);    //Most attributes are string
  101.     return TRUE;  // return TRUE unless you set the focus to a control
  102.                   // EXCEPTION: OCX Property Pages should return FALSE
  103. }
  104.  
  105.  
  106.  
  107. /////////////////////////////////////////////////////////
  108. // Demonstrate:
  109. // IADsPropertyList::GetPropertyItem
  110. // IADsPropertyEntry
  111. //
  112. void CDlgIADsPropertyList::OnGet() 
  113. {
  114.     
  115.     HRESULT hr;
  116.     CString s;
  117.     BSTR    bstr;
  118.     VARIANT var;
  119.     IDispatch *pDispatch;
  120.     IADsPropertyEntry *pEntry;
  121.     IADsPropertyValue *pValue;
  122.     LONG  lADsType;
  123.     
  124.  
  125.     UpdateData(TRUE);
  126.     m_cValueList.ResetContent();
  127.  
  128.     bstr = m_sAttribute.AllocSysString();
  129.     hr = m_pPropList->GetPropertyItem( bstr, m_cADsType.GetCurSel()+1, &var );
  130.     SysFreeString( bstr );
  131.  
  132.  
  133.     if ( SUCCEEDED(hr) )
  134.     {
  135.         pDispatch = V_DISPATCH( &var );
  136.         hr = pDispatch->QueryInterface( IID_IADsPropertyEntry, (void**) &pEntry );
  137.         VariantClear( &var );
  138.  
  139.         // IADsPropertyEntry
  140.         if ( SUCCEEDED(hr) )
  141.         {
  142.             CPtrList dList;
  143.  
  144.             // get_Values return array of VT_DISPATH
  145.              hr = pEntry->get_Values( &var );
  146.              
  147.               
  148.              pEntry->get_ADsType( &lADsType);
  149.  
  150.              hr = VariantToPtrList( var, dList );
  151.  
  152.              pEntry->Release(); 
  153.  
  154.              ////////////////////////////
  155.              // IADsPropertyValue
  156.              /////////////////////////////
  157.              if ( SUCCEEDED(hr) )
  158.              {
  159.                 POSITION pos;
  160.                 pos = dList.GetHeadPosition();
  161.                 while ( pos != NULL )
  162.                 {
  163.                     pDispatch = (IDispatch*) dList.GetAt(pos);
  164.                     hr = pDispatch->QueryInterface( IID_IADsPropertyValue, (void**) &pValue );
  165.                 
  166.                     if ( SUCCEEDED(hr) )
  167.                     {
  168.                         pValue->AddRef();
  169.                         hr = PropertyValueToString( lADsType, pValue, s );
  170.                         m_cValueList.AddString( s );
  171.                         pValue->Release();
  172.                     }
  173.                     dList.GetNext(pos);
  174.                 }
  175.             
  176.              }
  177.  
  178.              dList.RemoveAll();
  179.              VariantClear(&var);
  180.  
  181.         }
  182.  
  183.     }
  184. }
  185.  
  186. void CDlgIADsPropertyList::OnPurge() 
  187. {
  188.   HRESULT hr;
  189.   
  190.   hr = m_pPropList->PurgePropertyList();
  191.  
  192.   if ( !SUCCEEDED(hr) )
  193.   {
  194.       AfxMessageBox(GetErrorMessage(hr));
  195.   }
  196. }
  197.