protected override bool RunDialog(IntPtr hWndOwner) { IntPtr zero = IntPtr.Zero; bool flag = false; System.Windows.Forms.UnsafeNativeMethods.Shell32.SHGetSpecialFolderLocation(hWndOwner, (int) this.rootFolder, ref zero); if (zero == IntPtr.Zero) { System.Windows.Forms.UnsafeNativeMethods.Shell32.SHGetSpecialFolderLocation(hWndOwner, 0, ref zero); if (zero == IntPtr.Zero) { throw new InvalidOperationException(System.Windows.Forms.SR.GetString("FolderBrowserDialogNoRootFolder")); } } int num = 0x40; if (!this.showNewFolderButton) { num += 0x200; } if (Control.CheckForIllegalCrossThreadCalls && (Application.OleRequired() != ApartmentState.STA)) { throw new ThreadStateException(System.Windows.Forms.SR.GetString("DebuggingExceptionOnly", new object[] { System.Windows.Forms.SR.GetString("ThreadMustBeSTA") })); } IntPtr pidl = IntPtr.Zero; IntPtr hglobal = IntPtr.Zero; IntPtr pszPath = IntPtr.Zero; try { System.Windows.Forms.UnsafeNativeMethods.BROWSEINFO lpbi = new System.Windows.Forms.UnsafeNativeMethods.BROWSEINFO(); hglobal = Marshal.AllocHGlobal((int) (260 * Marshal.SystemDefaultCharSize)); pszPath = Marshal.AllocHGlobal((int) (260 * Marshal.SystemDefaultCharSize)); this.callback = new System.Windows.Forms.UnsafeNativeMethods.BrowseCallbackProc(this.FolderBrowserDialog_BrowseCallbackProc); lpbi.pidlRoot = zero; lpbi.hwndOwner = hWndOwner; lpbi.pszDisplayName = hglobal; lpbi.lpszTitle = this.descriptionText; lpbi.ulFlags = num; lpbi.lpfn = this.callback; lpbi.lParam = IntPtr.Zero; lpbi.iImage = 0; pidl = System.Windows.Forms.UnsafeNativeMethods.Shell32.SHBrowseForFolder(lpbi); if (pidl != IntPtr.Zero) { System.Windows.Forms.UnsafeNativeMethods.Shell32.SHGetPathFromIDList(pidl, pszPath); this.selectedPathNeedsCheck = true; this.selectedPath = Marshal.PtrToStringAuto(pszPath); flag = true; } } finally { System.Windows.Forms.UnsafeNativeMethods.CoTaskMemFree(zero); if (pidl != IntPtr.Zero) { System.Windows.Forms.UnsafeNativeMethods.CoTaskMemFree(pidl); } if (pszPath != IntPtr.Zero) { Marshal.FreeHGlobal(pszPath); } if (hglobal != IntPtr.Zero) { Marshal.FreeHGlobal(hglobal); } this.callback = null; } return flag; }
protected override bool RunDialog(IntPtr hWndOwner) { IntPtr zero = IntPtr.Zero; bool flag = false; System.Windows.Forms.UnsafeNativeMethods.Shell32.SHGetSpecialFolderLocation(hWndOwner, (int)this.rootFolder, ref zero); if (zero == IntPtr.Zero) { System.Windows.Forms.UnsafeNativeMethods.Shell32.SHGetSpecialFolderLocation(hWndOwner, 0, ref zero); if (zero == IntPtr.Zero) { throw new InvalidOperationException(System.Windows.Forms.SR.GetString("FolderBrowserDialogNoRootFolder")); } } int num = 0x40; if (!this.showNewFolderButton) { num += 0x200; } if (Control.CheckForIllegalCrossThreadCalls && (Application.OleRequired() != ApartmentState.STA)) { throw new ThreadStateException(System.Windows.Forms.SR.GetString("DebuggingExceptionOnly", new object[] { System.Windows.Forms.SR.GetString("ThreadMustBeSTA") })); } IntPtr pidl = IntPtr.Zero; IntPtr hglobal = IntPtr.Zero; IntPtr pszPath = IntPtr.Zero; try { System.Windows.Forms.UnsafeNativeMethods.BROWSEINFO lpbi = new System.Windows.Forms.UnsafeNativeMethods.BROWSEINFO(); hglobal = Marshal.AllocHGlobal((int)(260 * Marshal.SystemDefaultCharSize)); pszPath = Marshal.AllocHGlobal((int)(260 * Marshal.SystemDefaultCharSize)); this.callback = new System.Windows.Forms.UnsafeNativeMethods.BrowseCallbackProc(this.FolderBrowserDialog_BrowseCallbackProc); lpbi.pidlRoot = zero; lpbi.hwndOwner = hWndOwner; lpbi.pszDisplayName = hglobal; lpbi.lpszTitle = this.descriptionText; lpbi.ulFlags = num; lpbi.lpfn = this.callback; lpbi.lParam = IntPtr.Zero; lpbi.iImage = 0; pidl = System.Windows.Forms.UnsafeNativeMethods.Shell32.SHBrowseForFolder(lpbi); if (pidl != IntPtr.Zero) { System.Windows.Forms.UnsafeNativeMethods.Shell32.SHGetPathFromIDList(pidl, pszPath); this.selectedPathNeedsCheck = true; this.selectedPath = Marshal.PtrToStringAuto(pszPath); flag = true; } } finally { System.Windows.Forms.UnsafeNativeMethods.CoTaskMemFree(zero); if (pidl != IntPtr.Zero) { System.Windows.Forms.UnsafeNativeMethods.CoTaskMemFree(pidl); } if (pszPath != IntPtr.Zero) { Marshal.FreeHGlobal(pszPath); } if (hglobal != IntPtr.Zero) { Marshal.FreeHGlobal(hglobal); } this.callback = null; } return(flag); }