I'm using rust for windows to use the win32 API.
However, I need to initialize com library to use some windows APIs, but I cannot find some classes ID (CLSID), to create an instance.
I need to find the Speech ISpVoice CLSID to use in my instance creation.
CLSID_SpVoice is the CLSID.
Also, I cannot find some macros like "FAILED", and "SUCCEEDED".
If anyone can direct me, that would be appreciated!
Also, if there's any error in my code, please highlight it me.
Code:
use windows::Win32::System::Com::{CoInitializeEx, CoCreateInstance};
use windows::Win32::System::{Com, Ole};
use windows::core::{ HRESULT, Error };
use windows::Win32::Media::Speech::ISpVoice;
fn main() {
let speaker: ISpVoice;
unsafe {
if CoInitializeEx(std::ptr::null(), Com::COINIT_MULTITHREADED) ==Result::Ok(()) {
let hr: HRESULT = CoCreateInstance(, punkouter, dwclscontext)
}
}
}
If anything is unclear, please let me know!
The
windowscrate declares theSpVoiceconstant which is the value of theCLSID_SpVoiceclass ID. As you have discovered, that's theCLSIDyou want to pass intoCoCreateInstance.The latter returns a
windows::core::Result<T>, which models the same semantics as C code using theSUCCEEDEDandFAILEDmacros would. You can eithermatchon theOkorErrvariants manually, or use the?operator for convenient error propagation:In case you need a
CLSIDthat's not available through thewindowscrate, you can always construct aGUIDconstant using eitherfrom_valuesorfrom_u128:Note that the value is exactly the value you were given in a comment. Your assessment that C++ and Rust were any different with respect to COM is unfounded. They are indeed the same thing, just with different syntax.