Skip to content
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

Unable to implement IMFAsyncCallback #3194

Closed
mycrl opened this issue Aug 6, 2024 · 2 comments
Closed

Unable to implement IMFAsyncCallback #3194

mycrl opened this issue Aug 6, 2024 · 2 comments
Labels
question Further information is requested

Comments

@mycrl
Copy link

mycrl commented Aug 6, 2024

Summary

According to #3065, I tried to implement IMFAsyncCallback, but obviously, an error occurred and I don't know where the problem is.

error[E0405]: cannot find trait `IMFAsyncCallback_Impl` in this scope
 --> mft\src\lib.rs:8:6
  |
8 | impl IMFAsyncCallback_Impl for VideoProcessorAsyncCallback_Impl {
  |      ^^^^^^^^^^^^^^^^^^^^^ not found in this scope

Crate manifest

[package]
name = "mft"
version = "0.1.0"
edition = "2021"

[target.'cfg(target_os = "windows")'.dependencies]
windows-core = "0.58.0"

[target.'cfg(target_os = "windows")'.dependencies.windows]
version = "0.58.0"
features = [
    "implement",
    "Win32_System_Com", 
    "Win32_System_Com_StructuredStorage",
    "Win32_Media", 
    "Win32_Media_MediaFoundation", 
]

Crate code

use windows::Win32::Media::MediaFoundation::{IMFAsyncResult, MFASYNC_BLOCKING_CALLBACK, MFASYNC_CALLBACK_QUEUE_MULTITHREADED};
use windows_core::{implement, Param};

#[implement(windows::Win32::Media::MediaFoundation::IMFAsyncCallback)]
pub struct VideoProcessorAsyncCallback;

#[allow(non_snake_case)]
impl IMFAsyncCallback_Impl for VideoProcessorAsyncCallback_Impl {
    unsafe fn GetParameters(
        &self,
        pdwflags: *mut u32,
        pdwqueue: *mut u32,
    ) -> windows::core::Result<()> {
        *pdwflags = MFASYNC_BLOCKING_CALLBACK;
        *pdwqueue = MFASYNC_CALLBACK_QUEUE_MULTITHREADED;

        Ok(())
    }

    unsafe fn Invoke<T>(
        &self,
        pasyncresult: T,
    ) -> windows::core::Result<()>
    where 
        T: Param<IMFAsyncResult>, 
    {
        Ok(())
    }
}
@mycrl mycrl added the bug Something isn't working label Aug 6, 2024
@mycrl mycrl changed the title Unable to implement IMFAsyncResult Unable to implement IMFAsyncCallback Aug 6, 2024
@riverar
Copy link
Collaborator

riverar commented Aug 7, 2024

You're missing a use declaration for the IMFAsyncCallback_Impl type (i.e. use windows::Win32::Media::MediaFoundation::IMFAsyncCallback_Impl). Fixing that gets you to other errors related to generics, etc.

Here's a working skeleton:

#![allow(unused)]

use windows::Win32::Media::MediaFoundation::{
    IMFAsyncCallback, IMFAsyncCallback_Impl, IMFAsyncResult,
};
use windows_core::implement;

#[implement(IMFAsyncCallback)]
pub struct Foo;

impl IMFAsyncCallback_Impl for Foo_Impl {
    fn GetParameters(&self, pdwflags: *mut u32, pdwqueue: *mut u32) -> windows_core::Result<()> {
        todo!()
    }

    fn Invoke(&self, pasyncresult: Option<&IMFAsyncResult>) -> windows_core::Result<()> {
        todo!()
    }
}

fn main() -> windows::core::Result<()> {
    Ok(())
}
[package]
name = "app"
version = "0.0.0"
edition = "2021"
publish = false

[dependencies.windows]
version = "0.58.0"
features = [
    "implement",
    "Win32_Foundation",
    "Win32_Media_MediaFoundation",
]

[dependencies.windows-core]
version = "0.58.0"

@riverar riverar added question Further information is requested and removed bug Something isn't working labels Aug 7, 2024
@mycrl
Copy link
Author

mycrl commented Aug 7, 2024

You're missing a use declaration for the IMFAsyncCallback_Impl type (i.e. use windows::Win32::Media::MediaFoundation::IMFAsyncCallback_Impl). Fixing that gets you to other errors related to generics, etc.

Thank you. I initially thought that the trait of xxx_Impl was automatically generated by implement macro, which led to some misunderstandings for me.

@mycrl mycrl closed this as completed Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants