Windows-rs: implement attribute fails for windows::application_model::core::IFrameworkViewSource

Created on 23 Jan 2021  路  3Comments  路  Source: microsoft/windows-rs

Idk if it's ridiculous to try to stand up a CoreWindow from scratch, but that's what I'm trying to do.

On this line, I am getting the following error when trying to do:

#[implement(windows::application_model::core::IFrameworkViewSource)]
struct ViewSource {
}

Error:

error[E0433]: failed to resolve: could not find `application_model` in `windows`
 --> src\main.rs:4:1
  |
4 | #[implement(windows::application_model::core::IFrameworkViewSource)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `application_model` in `windows`
  |
  = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

What's especially strange is I have implemented the interface:

impl ViewSource {
    fn create_view(&self) -> Result<IFrameworkView> {
        Err(ErrorCode::S_OK.into())
    }
}

and if I remove create_view, the build does complain about the missing api call, so it's as is the macro is working and the failure is bogus?

error[E0433]: failed to resolve: could not find `application_model` in `windows`
 --> src\main.rs:4:1
  |
4 | #[implement(windows::application_model::core::IFrameworkViewSource)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `application_model` in `windows`
  |
  = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unused import: `bindings::windows::application_model::core::*`
 --> src\main.rs:2:5
  |
2 | use bindings::windows::application_model::core::*;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error[E0599]: no method named `create_view` found for struct `ViewSource` in the current scope
 --> src\main.rs:4:1
  |
4 | #[implement(windows::application_model::core::IFrameworkViewSource)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `ViewSource`
5 | struct ViewSource {
  | ----------------- method `create_view` not found for this
  |
  = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

Here are the full files:
main.rs

use windows::*;
use bindings::windows::application_model::core::*;

#[implement(windows::application_model::core::IFrameworkViewSource)]
struct ViewSource {

}

impl ViewSource {
    fn create_view(&self) -> Result<IFrameworkView> {
        Err(ErrorCode::S_OK.into())
    }
}

fn main() {
    println!("hello, world!");
}

bindings/build.rs:

fn main() {
    windows::build!(
        windows::application_model::core::*
        microsoft::graphics::canvas::CanvasImage
    );
}
question

Most helpful comment

I've just updated the uwp branch of Minesweeper if you'd like something to compare against. It implements both IFrameworkViewSource and IFrameworkView.

All 3 comments

This is possible to do. It's just a little tricky as Rust proc macros (e.g. windows::implement) cannot see the surrounding token stream so it doesn't know what Rust use declarations you may be employing, if any. It also doesn't know whether the bindings are generated in a bindings crate or module, if any. This is unfortunate, but I haven't found a good solution for this yet.

So the macro assumes that the type, windows::application_model::core::IFrameworkViewSource in this case, can be resolved as written in the surrounding scope.

Anyway, you can tweak your use declarations as follows to get it to work:

use bindings::windows;
use bindings::windows::*;
use bindings::windows::application_model::core::*;

Implementation support is still under active development - https://github.com/microsoft/windows-rs/issues/81 - so feel free to chime in with your experiences as I continue to work on that feature.

I've just updated the uwp branch of Minesweeper if you'd like something to compare against. It implements both IFrameworkViewSource and IFrameworkView.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

06393993 picture 06393993  路  3Comments

ZCWorks picture ZCWorks  路  3Comments

joverwey picture joverwey  路  3Comments

AyashiNoCeres picture AyashiNoCeres  路  4Comments

kennykerr picture kennykerr  路  5Comments