Update winapi version from 0.2 to 0.3 (#202)

Adds only the necessary cargo features to reduce compile time and reduce
the chance of linking errors occurring for unused libraries (e.g.
d3d12.dll fails to link on my win10 VM).

I thought I'd try and land this before before working on the wasapi
backend implementation for #201.

Tested both beep.rs and enumerate.rs and they work fine with the update.
This commit is contained in:
mitchmindtree 2018-02-08 03:36:59 +11:00 • committed by Pierre Krieger
parent 3ff9e6fe65
commit b47e46a4ac
5 changed files with 158 additions and 122 deletions

View file

@ -1,15 +1,16 @@
//! Handles COM initialization and cleanup.
use super::check_result;
use super::ole32;
use super::winapi;
use std::ptr;
use super::winapi::um::objbase::{COINIT_MULTITHREADED};
use super::winapi::um::combaseapi::{CoInitializeEx, CoUninitialize};
thread_local!(static COM_INITIALIZED: ComInitialized = {
unsafe {
// this call can fail if another library initialized COM in single-threaded mode
// handling this situation properly would make the API more annoying, so we just don't care
check_result(ole32::CoInitializeEx(ptr::null_mut(), winapi::COINIT_MULTITHREADED)).unwrap();
check_result(CoInitializeEx(ptr::null_mut(), COINIT_MULTITHREADED)).unwrap();
ComInitialized(ptr::null_mut())
}
});
@ -23,7 +24,7 @@ struct ComInitialized(*mut ());
impl Drop for ComInitialized {
#[inline]
fn drop(&mut self) {
unsafe { ole32::CoUninitialize() };
unsafe { CoUninitialize() };
}
}