pub fn open_dialog(params: DialogParams) -> Result<OpenDialogResult, DialogError> {
    // Initialize COM
    com!(CoInitializeEx(
            null_mut(),
            COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE,
        ), "CoInitializeEx")?;

    // Create IFileOpenDialog instance
    let mut file_open_dialog: *mut IFileOpenDialog = null_mut();
    com!(CoCreateInstance(
            &CLSID_FileOpenDialog,
            null_mut(),
            CLSCTX_ALL,
            &IFileOpenDialog::uuidof(),
            &mut file_open_dialog as *mut *mut IFileOpenDialog as *mut *mut c_void,
        ), "CoCreateInstance - IFileOpenDialog")?;
    let file_open_dialog = unsafe { &*file_open_dialog };

    // Perform non open-specific dialog configuration
    configure_file_dialog(file_open_dialog, &params)?;

    show_dialog(file_open_dialog, params.owner)?;

    // Get the item(s) that the user selected in the dialog
    // IFileOpenDialog::GetResults
    let mut shell_item_array: *mut IShellItemArray = null_mut();
    com!(file_open_dialog.GetResults(&mut shell_item_array), "IFileOpenDialog::GetResults")?;

    let shell_item_array = unsafe { &*shell_item_array };

    // IShellItemArray::GetCount
    let mut item_count: u32 = 0;
    com!(shell_item_array.GetCount(&mut item_count), "IShellItemArray::GetCount")?;

    let mut file_paths: Vec<PathBuf> = vec![];
    for i in 0..item_count {
        // IShellItemArray::GetItemAt
        let mut shell_item: *mut IShellItem = null_mut();
        com!(shell_item_array.GetItemAt(i, &mut shell_item), "IShellItemArray::GetItemAt")?;
        let shell_item = unsafe { &*shell_item };

        // Fetch the SFGAO_FILESYSTEM attribute for the file
        let mut attribs: SFGAOF = 0;
        // IShellItem::GetAttributes
        com!(shell_item.GetAttributes(SFGAO_FILESYSTEM, &mut attribs), "IShellItem::GetAttributes")?;

        // Ignore shell items that do not have the SFGAO_FILESYSTEM attribute
        // which indicates that they represent a valid path to a file or folder
        if attribs & SFGAO_FILESYSTEM == 0 {
            continue;
        }

        let file_name = get_shell_item_display_name(&shell_item)?;
        file_paths.push(PathBuf::from(file_name));

        // Free non-owned allocation
        unsafe { shell_item.Release() };
    }

    // IFileDialog::GetFileTypeIndex
    let selected_filter_index = get_file_type_index(file_open_dialog)?;

    // Un-initialize COM
    unsafe {
        CoUninitialize();
    }

    file_paths.get(0).cloned().map(|x| {
        OpenDialogResult {
            selected_file_path: x,
            selected_file_paths: file_paths,
            selected_file_type_index: selected_filter_index
        }
    }).ok_or(DialogError::UnsupportedFilepath)
}
/// Displays an Open Dialog using the provided parameters.
///
/// # Examples
///
/// ```
/// // An entirely default Open File dialog box with no customization
/// let result = wfd::open_dialog(Default::default());
/// ```
/// ```
/// // A folder-picker Open dialog box with a custom dialog title
/// # use std::io;
/// # fn main() -> Result<(), wfd::DialogError> {
/// let params = wfd::DialogParams {
///    options: wfd::FOS_PICKFOLDERS,
///    title: "My custom open folder dialog",
///    ..Default::default()
/// };
/// let result = wfd::open_dialog(params)?;
/// let path = result.selected_file_path;
/// #    Ok(())
/// # }
/// ```
/// ```
/// // An Open dialog box with a custom dialog title and file types
/// # use std::io;
/// # fn main() -> Result<(), wfd::DialogError> {
/// let params = wfd::DialogParams {
///    title: "My custom open file dialog",
///    file_types: vec![("JPG Files", "*.jpg;*.jpeg"), ("PDF Files", "*.pdf")],
///    ..Default::default()
/// };
/// let result = wfd::open_dialog(params)?;
/// let path = result.selected_file_path;
/// #    Ok(())
/// # }
/// ```
///
/// # Errors
/// If a user cancels the dialog, the [`UserCancelled`] error is returned. The only other kinds of
/// errors that can be retured are COM [`HRESULT`] failure codes - usually as the result of invalid
/// combinations of options. These are returned in a [`HResultFailed`] error
///
/// [`UserCancelled`]: enum.FileDialogError.html#variant.UserCancelled
/// [`HResultFailed`]: enum.FileDialogError.html#variant.HResultFailed
/// [`HRESULT`]: https://en.wikipedia.org/wiki/HRESULT
Displays an Open Dialog using the provided parameters.
Displays an Open Dialog using the provided parameters .
pub fn open_dialog(params: DialogParams) -> Result<OpenDialogResult, DialogError> {
    // Initialize COM
    com!(CoInitializeEx(
            null_mut(),
            COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE,
        ), "CoInitializeEx")?;
    // Create IFileOpenDialog instance
    let mut file_open_dialog: *mut IFileOpenDialog = null_mut();
    com!(CoCreateInstance(
            &CLSID_FileOpenDialog,
            null_mut(),
            CLSCTX_ALL,
            &IFileOpenDialog::uuidof(),
            &mut file_open_dialog as *mut *mut IFileOpenDialog as *mut *mut c_void,
        ), "CoCreateInstance - IFileOpenDialog")?;
    let file_open_dialog = unsafe { &*file_open_dialog };
    // Perform non open-specific dialog configuration
    configure_file_dialog(file_open_dialog, &params)?;
    show_dialog(file_open_dialog, params.owner)?;
    // Get the item(s) that the user selected in the dialog
    // IFileOpenDialog::GetResults
    let mut shell_item_array: *mut IShellItemArray = null_mut();
    com!(file_open_dialog.GetResults(&mut shell_item_array), "IFileOpenDialog::GetResults")?;
    let shell_item_array = unsafe { &*shell_item_array };
    // IShellItemArray::GetCount
    let mut item_count: u32 = 0;
    com!(shell_item_array.GetCount(&mut item_count), "IShellItemArray::GetCount")?;
    let mut file_paths: Vec<PathBuf> = vec![];
    for i in 0..item_count {
        // IShellItemArray::GetItemAt
        let mut shell_item: *mut IShellItem = null_mut();
        com!(shell_item_array.GetItemAt(i, &mut shell_item), "IShellItemArray::GetItemAt")?;
        let shell_item = unsafe { &*shell_item };
        // Fetch the SFGAO_FILESYSTEM attribute for the file
        let mut attribs: SFGAOF = 0;
        // IShellItem::GetAttributes
        com!(shell_item.GetAttributes(SFGAO_FILESYSTEM, &mut attribs), "IShellItem::GetAttributes")?;
        // Ignore shell items that do not have the SFGAO_FILESYSTEM attribute
        // which indicates that they represent a valid path to a file or folder
        if attribs & SFGAO_FILESYSTEM == 0 {
            continue;
        }
        let file_name = get_shell_item_display_name(&shell_item)?;
        file_paths.push(PathBuf::from(file_name));
        // Free non-owned allocation
        unsafe { shell_item.Release() };
    }
    // IFileDialog::GetFileTypeIndex
    let selected_filter_index = get_file_type_index(file_open_dialog)?;
    // Un-initialize COM
    unsafe {
        CoUninitialize();
    }
    file_paths.get(0).cloned().map(|x| {
        OpenDialogResult {
            selected_file_path: x,
            selected_file_paths: file_paths,
            selected_file_type_index: selected_filter_index
        }
    }).ok_or(DialogError::UnsupportedFilepath)
}
pub fn open_dialog ( params : DialogParams ) -> Result < OpenDialogResult , DialogError > { // Initialize COM com ! ( CoInitializeEx ( null_mut ( ) COINIT_APARTMENTTHREADED COINIT_DISABLE_OLE1DDE ) " " ) ? ; // Create IFileOpenDialog instance let mut file_open_dialog : * mut IFileOpenDialog = null_mut ( ) ; com ! ( CoCreateInstance ( CLSID_FileOpenDialog null_mut ( ) CLSCTX_ALL IFileOpenDialog uuidof ( ) mut file_open_dialog as mut mut IFileOpenDialog as mut mut c_void ) " " ) ? ; let file_open_dialog = unsafe { & * file_open_dialog } ; // Perform non open-specific dialog configuration configure_file_dialog ( file_open_dialog , & params ) ? ; show_dialog ( file_open_dialog , params . owner ) ? ; // Get the item(s) that the user selected in the dialog // IFileOpenDialog::GetResults let mut shell_item_array : * mut IShellItemArray = null_mut ( ) ; com ! ( file_open_dialog GetResults ( mut shell_item_array ) " " ) ? ; let shell_item_array = unsafe { & * shell_item_array } ; // IShellItemArray::GetCount let mut item_count : u32 = 0 ; com ! ( shell_item_array GetCount ( mut item_count ) " " ) ? ; let mut file_paths : Vec < PathBuf > = vec ! [ ] ; for i in 0 .. item_count { // IShellItemArray::GetItemAt let mut shell_item : * mut IShellItem = null_mut ( ) ; com ! ( shell_item_array GetItemAt ( i mut shell_item ) " " ) ? ; let shell_item = unsafe { & * shell_item } ; // Fetch the SFGAO_FILESYSTEM attribute for the file let mut attribs : SFGAOF = 0 ; // IShellItem::GetAttributes com ! ( shell_item GetAttributes ( SFGAO_FILESYSTEM mut attribs ) " " ) ? ; // Ignore shell items that do not have the SFGAO_FILESYSTEM attribute // which indicates that they represent a valid path to a file or folder if attribs & SFGAO_FILESYSTEM == 0 { continue ; } let file_name = get_shell_item_display_name ( & shell_item ) ? ; file_paths . push ( PathBuf :: from ( file_name ) ) ; // Free non-owned allocation unsafe { shell_item . Release ( ) } ; } // IFileDialog::GetFileTypeIndex let selected_filter_index = get_file_type_index ( file_open_dialog ) ? ; // Un-initialize COM unsafe { CoUninitialize ( ) ; } file_paths . get ( 0 ) . cloned ( ) . map ( | x | { OpenDialogResult { selected_file_path : x , selected_file_paths : file_paths , selected_file_type_index : selected_filter_index } } ) . ok_or ( DialogError :: UnsupportedFilepath ) }
Displays an Open Dialog using the provided parameters.
Displays an Open Dialog using the provided parameters .
params
DialogParams
examples
```
An entirely default Open File dialog box with no customization
let result = wfd::open_dialog(Default::default());
```
```
A folder-picker Open dialog box with a custom dialog title
` ` ` An entirely default Open File dialog box with no customization let result = wfd :: open_dialog ( Default :: default () ) ; ` ` ` ` ` ` A folder - picker Open dialog box with a custom dialog title
use std::io;
None
fn main() -> result<(), wfd::dialogerror> {
let params = wfd::DialogParams {
options: wfd::FOS_PICKFOLDERS,
title: "My custom open folder dialog",
Default::default()
};
let result = wfd::open_dialog(params)?;
let path = result.selected_file_path.
let params = wfd :: DialogParams { options : wfd :: FOS_PICKFOLDERS title : " My custom open folder dialog " Default :: default () } ; let result = wfd :: open_dialog ( params ) ? ; let path = result . selected_file_path .
ok(())
None
}
```
```
An Open dialog box with a custom dialog title and file types
` ` ` ` ` ` An Open dialog box with a custom dialog title and file types
use std::io;
None
fn main() -> result<(), wfd::dialogerror> {
let params = wfd::DialogParams {
title: "My custom open file dialog",
file_types: vec![("JPG Files", "*.jpg;*.jpeg"), ("PDF Files", "*.pdf")],
Default::default()
};
let result = wfd::open_dialog(params)?;
let path = result.selected_file_path.
let params = wfd :: DialogParams { title : " My custom open file dialog " file_types : vec! [ ( " JPG Files " " * . jpg ; * . jpeg " ) ( " PDF Files " " * . pdf " ) ] Default :: default () } ; let result = wfd :: open_dialog ( params ) ? ; let path = result . selected_file_path .
ok(())
None
}
None
errors
If a user cancels the dialog, the [`UserCancelled`] error is returned. The only other kinds of
errors that can be retured are COM [`HRESULT`] failure codes - usually as the result of invalid
combinations of options. These are returned in a [`HResultFailed`] error


If a user cancels the dialog the [ ` UserCancelled ` ] error is returned . The only other kinds of errors that can be retured are COM [ ` HRESULT ` ] failure codes - usually as the result of invalid combinations of options . These are returned in a [ ` HResultFailed ` ] error