Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // In cargo.toml:
- /*
- [dependencies]
- winapi = "0.2.8"
- ole32-sys = "0.2.0"
- shell32-sys = "0.1.1"
- uuid-sys = "0.1.1"
- widestring = "0.2.2"
- */
- extern crate shell32;
- extern crate winapi;
- extern crate uuid;
- extern crate widestring;
- extern crate ole32;
- use std::ptr;
- use widestring::WideCString;
- fn get_downloads_directory_windows() -> Option<String> {
- unsafe {
- let mut pname : winapi::LPWSTR = ptr::null_mut();
- let hresult = shell32::SHGetKnownFolderPath(&uuid::FOLDERID_Downloads, 0, ptr::null_mut(), &mut pname);
- if hresult == winapi::S_OK {
- let sys_downloads_cs = WideCString::from_ptr_str(pname);
- ole32::CoTaskMemFree(pname as winapi::LPVOID);
- Some(sys_downloads_cs.to_string_lossy())
- }
- else { None }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement