home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / ADSDK.ZIP / Samples / Start / Enum / vc / Enum.cpp next >
Encoding:
C/C++ Source or Header  |  1999-01-18  |  1.4 KB  |  74 lines

  1. // Enum.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "stdio.h"
  6. #include "activeds.h"
  7.  
  8.  
  9.  
  10.  
  11. int main(int argc, char* argv[])
  12. {
  13.     HRESULT hr;
  14.     IADsContainer *pCont;
  15.     CoInitialize(NULL);
  16.     
  17.  
  18.     ////////////////////////////////
  19.     // Bind to a domain object
  20.     //////////////////////////////////
  21.     hr = ADsGetObject(L"WinNT://INDEPENDENCE", IID_IADsContainer, (void**) &pCont );
  22.     if ( !SUCCEEDED(hr) )
  23.     {
  24.         return 0;
  25.     }
  26.  
  27.     /////////////////////////////////
  28.     // Enumerate
  29.     /////////////////////////////////
  30.     IEnumVARIANT *pEnum = NULL;
  31.     hr = ADsBuildEnumerator( pCont, &pEnum );
  32.     if ( SUCCEEDED(hr) )
  33.     {
  34.         VARIANT var;
  35.         ULONG   lFetch;
  36.         IADs   *pChild=NULL;
  37.         VariantInit(&var);
  38.  
  39.         while( SUCCEEDED(ADsEnumerateNext( pEnum, 1, &var, &lFetch )) && lFetch == 1 )
  40.         {
  41.             hr = V_DISPATCH(&var)->QueryInterface( IID_IADs, (void**) &pChild );
  42.             if ( SUCCEEDED(hr) )
  43.             {
  44.                 BSTR bstrName;
  45.                 BSTR bstrClass;
  46.                 // Get more information on the child classes
  47.                 pChild->get_Name(&bstrName);
  48.                 pChild->get_Class(&bstrClass);
  49.  
  50.                 printf("%S\t(%S)\n", bstrName, bstrClass );
  51.  
  52.                 // Clean-up
  53.                 SysFreeString(bstrName);
  54.                 SysFreeString(bstrClass);
  55.  
  56.                 pChild->Release();
  57.  
  58.             }
  59.             VariantClear(&var);
  60.         }
  61.  
  62.     }
  63.  
  64.     if ( pEnum )
  65.     {
  66.         ADsFreeEnumerator( pEnum );
  67.     }
  68.  
  69.     pCont->Release();
  70.  
  71.     CoUninitialize();
  72.     return 0;
  73. }
  74.