windows 0.9.1

Rust for Windows
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::*;

use bindings::Windows::Win32::Com::{CoCreateInstance, CoInitializeEx, CLSCTX, COINIT};

/// Initializes COM for use by the calling thread for the multi-threaded apartment (MTA).
pub fn initialize_mta() -> Result<()> {
    unsafe { CoInitializeEx(std::ptr::null_mut(), COINIT::COINIT_MULTITHREADED).ok() }
}

/// Initializes COM for use by the calling thread for a single-threaded apartment (STA).
pub fn initialize_sta() -> Result<()> {
    unsafe { CoInitializeEx(std::ptr::null_mut(), COINIT::COINIT_APARTMENTTHREADED).ok() }
}

/// Creates a COM object with the given CLSID.
pub fn create_instance<T: Interface>(clsid: &Guid) -> Result<T> {
    unsafe { CoCreateInstance(clsid, None, CLSCTX::CLSCTX_ALL) }
}