-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify non-COM interface parameter bindings #2098
Comments
Hey, that's a confusing error! Getting Rust macros to produce meaningful errors is hard... Anyway, the trick is that the The good news is that I recently provided support for such interfaces: #2066 |
I applied the concepts from the example you provided in (#2066) to my XAudio2 problem and think it works. Now I use the struct XAudio2VoiceCallbacks;
#[interface]
unsafe trait XAudio2VoiceCallbackInterface {
unsafe fn OnBufferEnd(&self, pbuffercontext: *mut ::core::ffi::c_void);
}
impl XAudio2VoiceCallbackInterface_Impl for XAudio2VoiceCallbacks {
unsafe fn OnStreamEnd(&self) {}
} The final goal is to call the let callback_instance = XAudio2VoiceCallbacks {};
let callback_interface = XAudio2VoiceCallbackInterface::new(&callback_instance);
let callback_windows = mem::transmute(callback_interface); Thanks for your time! I am still in the process of learning the rust language and really appreciate the support. |
No, since the So I don't know anything about the XAudio2 API but something like this should get you started:
use windows::{
core::*, Win32::Media::Audio::XAudio2::*, Win32::System::Com::*,
Win32::System::SystemInformation::*,
};
struct Callback;
impl IXAudio2VoiceCallback_Impl for Callback {
fn OnVoiceProcessingPassStart(&self, _: u32) {
todo!()
}
fn OnVoiceProcessingPassEnd(&self) {
todo!()
}
fn OnStreamEnd(&self) {
println!("callback");
}
fn OnBufferStart(&self, _: *mut std::ffi::c_void) {
todo!()
}
fn OnBufferEnd(&self, _: *mut std::ffi::c_void) {
todo!()
}
fn OnLoopEnd(&self, _: *mut std::ffi::c_void) {
todo!()
}
fn OnVoiceError(&self, _: *mut std::ffi::c_void, _: HRESULT) {
todo!()
}
}
fn main() -> Result<()> {
unsafe {
CoInitializeEx(None, COINIT_MULTITHREADED)?;
let mut audio = None;
XAudio2CreateWithVersionInfo(&mut audio, 0, XAUDIO2_DEFAULT_PROCESSOR, NTDDI_VERSION)?;
if let Some(audio) = audio {
// Call the callback interface directly...
let callback = IXAudio2VoiceCallback::new(&Callback);
callback.OnStreamEnd();
// Pass the callback to another API...
let mut source = None;
audio.CreateSourceVoice(
&mut source,
std::ptr::null(),
0,
0.0,
&*callback,
None,
None,
)?;
}
Ok(())
}
} Notice the weird Anyway, I hope that helps. |
Ohhhh wow the |
Great, I'll keep this open to remind me to get rid of the need for that trick. |
Hello, the last couple of days I tried to migrate my XAudio2 project from C++ to Rust and was simply unable to implement the IXAudio2VoiceCallback interface.
I am quite new to the rust language and even after hours of research do not understand why the implement macro doesn't work in my case. I don't think this is a general rust question because the macro is a specific functionality of the windows crate.
I want to call the function CreateSourceVoice on an XAudio2 instance:
To create an implementation for the IXAudio2VoiceCallback interface I use the implement macro:
The compiler error for the implement macro is:
The issue "How to get COM object as "base" Interface without move" shows a similar situation with the IAudioEndpointVolumeCallback interface but in their case it just works. It would be awesome if someone with more windows crate knowledge or more rust experience in generell could help me.
The text was updated successfully, but these errors were encountered: