1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use crate::HRESULT;

#[derive(Debug, PartialEq, Clone)]
pub enum Error {
    /// Window is not found
    WindowNotFound,

    /// Desktop with given ID is not found
    DesktopNotFound,

    /// Unable to create service, ensure that explorer.exe is running
    ServiceNotCreated,

    /// Some unhandled COM error
    ComError(HRESULT),

    /// This should not happen, this means that successful COM call allocated a
    /// null pointer, in this case it is an error in the COM service, or it's
    /// usage.
    ComAllocatedNullPtr,
}

impl From<HRESULT> for Error {
    fn from(hr: HRESULT) -> Self {
        Error::ComError(hr)
    }
}
impl From<HRESULT> for Result<(), Error> {
    fn from(item: HRESULT) -> Self {
        if !item.failed() {
            Ok(())
        } else {
            Err(item.into())
        }
    }
}