home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / ADSDK.ZIP / Samples / ActiveDir / GUIDBind / vc / main.cpp < prev   
Encoding:
C/C++ Source or Header  |  1999-04-05  |  1.8 KB  |  79 lines

  1. #define INC_OLE2
  2. #define UNICODE 1
  3. #define _WIN32_DCOM
  4.  
  5. #include <windows.h>
  6. #include <winuser.h>
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <malloc.h>
  12.  
  13. #include <winldap.h>
  14. #include <activeds.h>
  15. #include "ADSIhelpers.h"
  16. #include <assert.h>
  17.  
  18.  
  19. void main()
  20. {
  21. // Initialize COM
  22. CoInitialize(0);
  23.  
  24. WCHAR pwszADsPathObject[1024];
  25. WCHAR pwszBindByGuidStr[1024]; 
  26. HRESULT hr;
  27.  
  28. IADs * pIADsObject = NULL;
  29. IADs * pIADsObjectByGuid = NULL;
  30.  
  31. // Ask the user for a ADsPath to start
  32. _putws(L"This code binds to a directory object by ADsPath, retrieves the GUID,\n"
  33.        L" then rebinds by GUID. \n\nSpecify the ADsPath of the object to bind to :\n");
  34. _getws(pwszADsPathObject);
  35.  
  36.  
  37. if (pwszADsPathObject[0] == NULL) 
  38.     return;
  39.  
  40. wprintf(L"\nBinding to %s\n",pwszADsPathObject);
  41.  
  42. // Bind to initial object
  43. hr = ADsGetObject( pwszADsPathObject,IID_IADs, (void **)& pIADsObject);
  44. if (SUCCEEDED(hr))
  45. {
  46.     BSTR bsGuid = NULL;
  47.     hr = pIADsObject->get_GUID(&bsGuid); 
  48.     
  49.     if (SUCCEEDED(hr))
  50.     {    
  51.         wprintf(L"\n The GUID for\n\n%s\n\nis\n\n%s\n",pwszADsPathObject,bsGuid);
  52.     
  53.         // Build a string for Binding to the object by GUID
  54.         wsprintf(pwszBindByGuidStr,L"LDAP://<GUID=%s>",bsGuid);
  55.  
  56.         // Bind BACK to the Same object using the GUID
  57.         hr = ADsGetObject( pwszBindByGuidStr,IID_IADs, (void **)& pIADsObjectByGuid);
  58.          
  59.         if (SUCCEEDED(hr))
  60.         {    
  61.             wprintf(L"\nSuccessfully RE bound to\n\n%s\n\nUsing the path:\n\n%s\n", pwszADsPathObject,pwszBindByGuidStr);
  62.  
  63.             // Release bind by GUID Object
  64.             pIADsObjectByGuid->Release();
  65.             pIADsObjectByGuid = NULL;
  66.         }
  67.  
  68.         SysFreeString(bsGuid);
  69.     }
  70.  
  71.     pIADsObject->Release();
  72.     pIADsObject = NULL;
  73. }
  74.  
  75. if (FAILED(hr))
  76.     _putws(L"Failed");
  77.     
  78.  
  79. }