protected override bool RunDialog(IntPtr hwndOwner) { using (var setupDlg = new System.Windows.Forms.OpenFileDialog()) { if (!string.IsNullOrEmpty(InitialDirectory)) { setupDlg.InitialDirectory = InitialDirectory; } setupDlg.Title = Title; setupDlg.AddExtension = false; setupDlg.CheckFileExists = false; setupDlg.DereferenceLinks = true; //setupDlg.Multiselect = MultiSelect; try { object realDlg = setupDlg.GetType().CallMethod("CreateVistaDialog", setupDlg); setupDlg.GetType().CallMethod("OnBeforeVistaDialog", setupDlg, realDlg); uint options = (uint)PubDialogType.CallMethod("GetOptions", setupDlg); HiddenDialogType.CallMethod("SetOptions", realDlg, options | FOS_PICKFOLDERS); object dlgEvents = Activator.CreateInstance(DialogEventsType, setupDlg); uint cookie = 0; object[] parameters = new object[] { dlgEvents, cookie }; HiddenDialogType.CallMethod("Advise", realDlg, parameters); cookie = (uint)parameters[1]; try { int result = (int)HiddenDialogType.CallMethod("Show", realDlg, hwndOwner); if (result == 0) { SelectedPath = setupDlg.FileName; //SelectedPaths = setupDlg.FileNames; return(true); } } finally { HiddenDialogType.CallMethod("Unadvise", realDlg, cookie); //GC.KeepAlive(dlgEvents); } } catch { __errored = false; throw; } } return(false); }