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

    // Create IFileSaveDialog instance
    let mut file_save_dialog: *mut IFileSaveDialog;
    file_save_dialog = null_mut();
    com!(CoCreateInstance(
            &CLSID_FileSaveDialog,
            null_mut(),
            CLSCTX_ALL,
            &IFileSaveDialog::uuidof(),
            &mut file_save_dialog as *mut *mut IFileSaveDialog as *mut *mut c_void,
        )
    , "CoCreateInstance - FileSaveDialog")?;
    let file_save_dialog = unsafe { &*file_save_dialog };

    // IFileDialog::SetSaveAsItem
    if params.save_as_item != "" {
        let mut item: *mut IShellItem = null_mut();
        let path = params.save_as_item.as_null_term_utf16();
        com!(SHCreateItemFromParsingName(path.as_ptr(), null_mut(), &IShellItem::uuidof(), &mut item as *mut *mut IShellItem as *mut *mut c_void), "SHCreateItemFromParsingName")?;
        com!(file_save_dialog.SetSaveAsItem(item), "IFileDialog::SetSaveAsItem")?;
        unsafe {
            let item = &*item;
            item.Release();
        }
    }

    // Perform non save-specific dialog configuration
    configure_file_dialog(file_save_dialog, &params)?;

    show_dialog(file_save_dialog, params.owner)?;

    // IFileDialog::GetResult
    let mut shell_item: *mut IShellItem = null_mut();
    com!(file_save_dialog.GetResult(&mut shell_item), "IFileDialog::GetResult")?;
    let shell_item = unsafe { &*shell_item };
    let file_name = get_shell_item_display_name(&shell_item)?;
    unsafe { shell_item.Release() };

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

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

    let result = SaveDialogResult {
        selected_filter_index,
        selected_file_path: PathBuf::from(file_name),
    };

    Ok(result)
}
/// Displays a Save Dialog using the provided parameters.
///
/// # Examples
///
/// ```
/// # fn main() -> Result<(), wfd::DialogError> {
/// // An entirely default Save File dialog box with no customization
/// let result = wfd::save_dialog(Default::default())?;
/// #    Ok(())
/// # }
/// ```
/// ```
/// # fn main() -> Result<(), wfd::DialogError> {
/// // A Save File dialog box with a custom dialog title and file types///
/// let params = wfd::DialogParams {
///    title: "My custom save file dialog",
///    file_types: vec![("JPG Files", "*.jpg;*.jpeg"), ("PDF Files", "*.pdf")],
///    ..Default::default()
/// };
/// let result = wfd::save_dialog(params)?;
/// #    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 a Save Dialog using the provided parameters.
Displays a Save Dialog using the provided parameters .
pub fn save_dialog(params: DialogParams) -> Result<SaveDialogResult, DialogError> {
    // Initialize COM
    com!(CoInitializeEx(
            null_mut(),
            COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE,
        )
    , "CoInitializeEx")?;
    // Create IFileSaveDialog instance
    let mut file_save_dialog: *mut IFileSaveDialog;
    file_save_dialog = null_mut();
    com!(CoCreateInstance(
            &CLSID_FileSaveDialog,
            null_mut(),
            CLSCTX_ALL,
            &IFileSaveDialog::uuidof(),
            &mut file_save_dialog as *mut *mut IFileSaveDialog as *mut *mut c_void,
        )
    , "CoCreateInstance - FileSaveDialog")?;
    let file_save_dialog = unsafe { &*file_save_dialog };
    // IFileDialog::SetSaveAsItem
    if params.save_as_item != "" {
        let mut item: *mut IShellItem = null_mut();
        let path = params.save_as_item.as_null_term_utf16();
        com!(SHCreateItemFromParsingName(path.as_ptr(), null_mut(), &IShellItem::uuidof(), &mut item as *mut *mut IShellItem as *mut *mut c_void), "SHCreateItemFromParsingName")?;
        com!(file_save_dialog.SetSaveAsItem(item), "IFileDialog::SetSaveAsItem")?;
        unsafe {
            let item = &*item;
            item.Release();
        }
    }
    // Perform non save-specific dialog configuration
    configure_file_dialog(file_save_dialog, &params)?;
    show_dialog(file_save_dialog, params.owner)?;
    // IFileDialog::GetResult
    let mut shell_item: *mut IShellItem = null_mut();
    com!(file_save_dialog.GetResult(&mut shell_item), "IFileDialog::GetResult")?;
    let shell_item = unsafe { &*shell_item };
    let file_name = get_shell_item_display_name(&shell_item)?;
    unsafe { shell_item.Release() };
    // IFileDialog::GetFileTypeIndex
    let selected_filter_index = get_file_type_index(file_save_dialog)?;
    // Un-initialize COM
    unsafe {
        CoUninitialize();
    }
    let result = SaveDialogResult {
        selected_filter_index,
        selected_file_path: PathBuf::from(file_name),
    };
    Ok(result)
}
pub fn save_dialog ( params : DialogParams ) -> Result < SaveDialogResult , DialogError > { // Initialize COM com ! ( CoInitializeEx ( null_mut ( ) COINIT_APARTMENTTHREADED COINIT_DISABLE_OLE1DDE ) " " ) ? ; // Create IFileSaveDialog instance let mut file_save_dialog : * mut IFileSaveDialog ; file_save_dialog = null_mut ( ) ; com ! ( CoCreateInstance ( CLSID_FileSaveDialog null_mut ( ) CLSCTX_ALL IFileSaveDialog uuidof ( ) mut file_save_dialog as mut mut IFileSaveDialog as mut mut c_void ) " " ) ? ; let file_save_dialog = unsafe { & * file_save_dialog } ; // IFileDialog::SetSaveAsItem if params . save_as_item != " " { let mut item : * mut IShellItem = null_mut ( ) ; let path = params . save_as_item . as_null_term_utf16 ( ) ; com ! ( SHCreateItemFromParsingName ( path as_ptr ( ) null_mut ( ) IShellItem uuidof ( ) mut item as mut mut IShellItem as mut mut c_void ) " " ) ? ; com ! ( file_save_dialog SetSaveAsItem ( item ) " " ) ? ; unsafe { let item = & * item ; item . Release ( ) ; } } // Perform non save-specific dialog configuration configure_file_dialog ( file_save_dialog , & params ) ? ; show_dialog ( file_save_dialog , params . owner ) ? ; // IFileDialog::GetResult let mut shell_item : * mut IShellItem = null_mut ( ) ; com ! ( file_save_dialog GetResult ( mut shell_item ) " " ) ? ; let shell_item = unsafe { & * shell_item } ; let file_name = get_shell_item_display_name ( & shell_item ) ? ; unsafe { shell_item . Release ( ) } ; // IFileDialog::GetFileTypeIndex let selected_filter_index = get_file_type_index ( file_save_dialog ) ? ; // Un-initialize COM unsafe { CoUninitialize ( ) ; } let result = SaveDialogResult { selected_filter_index , selected_file_path : PathBuf :: from ( file_name ) , } ; Ok ( result ) }
Displays a Save Dialog using the provided parameters.
Displays a Save Dialog using the provided parameters .
params
DialogParams
examples
None
fn main() -> result<(), wfd::dialogerror> {
An entirely default Save File dialog box with no customization
let result = wfd::save_dialog(Default::default())?.
An entirely default Save File dialog box with no customization let result = wfd :: save_dialog ( Default :: default () ) ? .
ok(())
None
}
None
fn main() -> result<(), wfd::dialogerror> {
A Save File dialog box with a custom dialog title and file types
let params = wfd::DialogParams {
title: "My custom save file dialog",
file_types: vec![("JPG Files", "*.jpg;*.jpeg"), ("PDF Files", "*.pdf")],
Default::default()
};
let result = wfd::save_dialog(params)?.
A Save File dialog box with a custom dialog title and file types let params = wfd :: DialogParams { title : " My custom save file dialog " file_types : vec! [ ( " JPG Files " " * . jpg ; * . jpeg " ) ( " PDF Files " " * . pdf " ) ] Default :: default () } ; let result = wfd :: save_dialog ( params ) ? .
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