Answer the question
In order to leave comments, you need to log in
Rust WinApi and ReadDirectoryChangesW?
Hello, I recently started learning Rust, and I want to know what file was added or deleted in a particular directory. I found the functions winapi::um::winbase::ReadDirectoryChangesW and I wanted to implement it.
#[cfg(windows)]
extern crate winapi;
use std::ffi::CString;
extern crate schedule_recv;
use winapi::um::fileapi::{CreateFileA, OPEN_EXISTING};
use winapi::um::winbase::{ReadDirectoryChangesW, FILE_FLAG_BACKUP_SEMANTICS};
use winapi::um::winnt::{FILE_LIST_DIRECTORY, FILE_NOTIFY_CHANGE_FILE_NAME, FILE_SHARE_READ};
fn main() {
unsafe {
// ..
let hDir = CreateFileA(
CString::new("C:/Users/Admin/Desktop/tmp/")
.unwrap()
.as_ptr(),
FILE_LIST_DIRECTORY,
FILE_SHARE_READ,
None.unwrap(),
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS,
None.unwrap(),
);
let x = ReadDirectoryChangesW(
hDir,
std::ptr::null_mut(),
0,
0,
FILE_NOTIFY_CHANGE_FILE_NAME,
std::ptr::null_mut(),
None.unwrap(),
None.unwrap(),
);
// ...
}
}
Answer the question
In order to leave comments, you need to log in
The crash is probably due to `None.unwrap()` - this expression will always cause a panic in general, because the point of unwrap is precisely this: unwrap the value if it is Some, or crash the application.
You can, for example, read https://habrahabr.ru/post/270371/ .
------
Well, yes, the task is precisely to implement this yourself? And then you can already take something ready. https://crates.io/crates/notify some, for example.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question