Skip to content

Commit

Permalink
Fix process not existing successfully (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangdaoyuan committed Mar 11, 2023
1 parent b55c6f6 commit a29f009
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib.rs
@@ -1,5 +1,6 @@
use std::{
ffi::OsString,
mem::ManuallyDrop,
os::windows::prelude::{OsStrExt, OsStringExt},
path::{Path, PathBuf},
};
Expand Down Expand Up @@ -51,7 +52,7 @@ pub struct Monitor {

#[derive(Debug)]
pub struct DesktopWallpaper {
interface: IDesktopWallpaper,
interface: ManuallyDrop<IDesktopWallpaper>,
}

impl DesktopWallpaper {
Expand All @@ -61,7 +62,9 @@ impl DesktopWallpaper {
CoCreateInstance(&DesktopWallpaper, None, CLSCTX_LOCAL_SERVER)?
};

Ok(Self { interface })
Ok(Self {
interface: ManuallyDrop::new(interface),
})
}

pub fn get_monitors(&self) -> Result<Vec<Monitor>> {
Expand Down Expand Up @@ -138,6 +141,7 @@ impl DesktopWallpaper {
impl Drop for DesktopWallpaper {
fn drop(&mut self) {
unsafe {
ManuallyDrop::drop(&mut self.interface);
CoFreeUnusedLibraries();
CoUninitialize();
}
Expand Down

0 comments on commit a29f009

Please sign in to comment.