home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / ADSDK.ZIP / Samples / Start / Schema / vc / Schema.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-19  |  1.3 KB  |  65 lines

  1. // Schema.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. int main(int argc, char* argv[])
  10. {
  11.     IADsContainer *pSchema=NULL;
  12.     HRESULT hr;
  13.  
  14.     CoInitialize(NULL);
  15.  
  16.     hr = ADsGetObject(L"WinNT://INDEPENDENCE/Schema", IID_IADsContainer, (void**) &pSchema );
  17.  
  18.     if ( !SUCCEEDED(hr) )
  19.     {
  20.         return hr;
  21.     }
  22.  
  23.  
  24.     ////////////// Enumerate Schema objects ///////////////////////////////////
  25.     IEnumVARIANT *pEnum = NULL;
  26.     hr = ADsBuildEnumerator( pSchema, &pEnum );
  27.     pSchema->Release(); // no longer needed, since we have the enumerator already
  28.     
  29.     if ( SUCCEEDED(hr) )
  30.     {
  31.         VARIANT var;
  32.         ULONG lFetch;
  33.         IADs *pChild=NULL;
  34.         VariantInit(&var);
  35.         
  36.         while( SUCCEEDED(ADsEnumerateNext( pEnum, 1, &var, &lFetch )) && lFetch == 1 )
  37.         {
  38.             hr = V_DISPATCH(&var)->QueryInterface( IID_IADs, (void**) &pChild );
  39.             if ( SUCCEEDED(hr) )
  40.             {
  41.                 BSTR bstrName;
  42.                 BSTR bstrClass;
  43.                 // Get more information on the child classes
  44.                 pChild->get_Name(&bstrName);
  45.                 pChild->get_Class(&bstrClass);
  46.                 
  47.                 printf("%S\t\t(%S)\n", bstrName, bstrClass );
  48.                 
  49.                 // Clean-up
  50.                 SysFreeString(bstrName);
  51.                 SysFreeString(bstrClass);
  52.                 
  53.                 pChild->Release();
  54.             }
  55.             VariantClear(&var);
  56.         }
  57.     }
  58.  
  59.     CoUninitialize();
  60.  
  61.  
  62.  
  63.     return 0;
  64. }
  65.