home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / dotNETSDK / SETUP.EXE / netfxsd1.cab / FL_ActiveDir_cs________.3643236F_FC70_11D3_A536_0090278A1BB8 < prev    next >
Encoding:
Text File  |  2001-08-27  |  2.6 KB  |  111 lines

  1. // Copyright
  2. // Microsoft Corporation
  3. // All rights reserved
  4.  
  5. // ActiveDir.cs
  6.  
  7. using System;
  8. using System.Text;
  9. using System.Runtime.InteropServices;
  10. using System.Threading;
  11.  
  12. /*
  13. typedef struct 
  14. {
  15.     DWORD           cbStruct;
  16.     HWND            hwndOwner;
  17.     LPCWSTR         pszCaption;
  18.     LPCWSTR         pszTitle;
  19.     LPCWSTR         pszRoot;
  20.     LPWStr          pszPath;
  21.     ULONG           cchPath;
  22.     DWORD           dwFlags;
  23.     BFFCALLBACK     pfnCallback;
  24.     LPARAM          lParam;
  25.     DWORD           dwReturnFormat;
  26.     LPCWSTR         pUserName;
  27.     LPCWSTR         pPassword;
  28.     LPWStr          pszObjectClass;
  29.     ULONG           cchObjectClass;
  30. } DSBROWSEINFOW, *PDSBROWSEINFOW;
  31. */
  32.  
  33. // all strings in structure will be marshaled as LPWStr
  34. [ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Unicode )]
  35. public struct DSBrowseInfo
  36. {
  37.     public int structSize;
  38.     public IntPtr dlgOwner;
  39.     
  40.     public string dlgCaption;
  41.     public string treeViewTitle;
  42.     public string rootPath;
  43.     
  44.     // in/out string must be declared as String in struct/class, 
  45.     // not as StringBuilder
  46.     public string path;    
  47.     public int pathSize;
  48.     
  49.     public int flags;
  50.     public IntPtr callback;
  51.     public IntPtr lParam;
  52.     public int returnFormat;
  53.     
  54.     public string userName;
  55.     public string password;
  56.     
  57.     public string objectClass;
  58.     public int objectClassSize;
  59. };
  60.  
  61. public class LibWrap
  62. {
  63.     //int DsBrowseForContainer(PDSBROWSEINFO pInfo);
  64.     
  65.     [ DllImport( "dsuiext.dll", CharSet=CharSet.Unicode )]
  66.     public static extern int DsBrowseForContainerW( ref DSBrowseInfo info );
  67.  
  68.     public const int DSBI_ENTIREDIRECTORY = 0x00090000;    
  69. }
  70.  
  71. class App
  72. {
  73.     public const int MAX_PATH = 256;
  74.  
  75.     // Must be marked as STA since default is MTA. DsBrowseForContainerW calls 
  76.     // CoInitialize, which initializes the COM library as STA.
  77.     
  78.     [ STAThread ]
  79.     public static void Main()
  80.     {
  81.         // initialize all members
  82.         DSBrowseInfo dsbi = new DSBrowseInfo();
  83.         
  84.         dsbi.structSize = Marshal.SizeOf( dsbi );
  85.         dsbi.dlgCaption = "The container picker";
  86.         dsbi.treeViewTitle = "Pick a container for this example.";
  87.         
  88.         dsbi.path = new string( new char[ MAX_PATH ]);
  89.         dsbi.pathSize = dsbi.path.Length;
  90.         
  91.         dsbi.flags = LibWrap.DSBI_ENTIREDIRECTORY;
  92.         
  93.         dsbi.objectClass = new string( new char[ MAX_PATH ]);
  94.         dsbi.objectClassSize = dsbi.objectClass.Length;
  95.  
  96.         Console.WriteLine( "Call DSBrowseForContainer..." );
  97.         
  98.         int status = LibWrap.DsBrowseForContainerW( ref dsbi );
  99.         
  100.         Console.WriteLine( "The status is " + status );
  101.         if( status == 1 )
  102.         {
  103.             Console.WriteLine( "The path is " + dsbi.path );
  104.         }
  105.         else 
  106.         {
  107.             Console.WriteLine( "Call failed!" );
  108.         }
  109.     }
  110. }
  111.