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

HINSTANCE is apparently not in metadata. #871

Closed
LollipopFt opened this issue Jun 17, 2021 · 7 comments
Closed

HINSTANCE is apparently not in metadata. #871

LollipopFt opened this issue Jun 17, 2021 · 7 comments
Labels
question Further information is requested

Comments

@LollipopFt
Copy link

   Compiling bindings v0.1.0 (C:\Users\lollipopft\rust\projects\winapi\window\bindings)                         
error: `Windows.Win32.Foundation.HINSTANCE` not found in metadata
 --> bindings\build.rs:4:25
  |
4 |             Foundation::HINSTANCE,
  |                         ^^^^^^^^^

error: aborting due to previous error

error: could not compile `bindings`

it gives me this error when my build.rs is

fn main() {
    windows::build!(
        Windows::Win32::{
            Foundation::HINSTANCE,
            UI::WindowsAndMessaging::{WNDCLASSW, WNDCLASS_STYLES, CS_OWNDC, CS_HREDRAW, CS_VREDRAW, DefWindowProcW}
        }
    );
}

am i doing anything wrong?

@kennykerr
Copy link
Collaborator

These types having recently moved around due to changes in the Win32 metadata. As of 0.11.0, it can be found here:

Windows::Win32::Foundation::HINSTANCE

https://microsoft.github.io/windows-docs-rs/doc/bindings/Windows/Win32/Foundation/struct.HINSTANCE.html

Perhaps double check which version of the Windows crate you're using.

@kennykerr kennykerr added the question Further information is requested label Jun 17, 2021
@LollipopFt
Copy link
Author

LollipopFt commented Jun 18, 2021

hi, may i ask how to check which version i am running if i use windows={git="https://github.com/microsoft/windows-rs.git"}?
thank you!

edit: got HINSTANCE to run, now bindings::Windows::Win32::UI::WindowsAndMessaging::CS_OWNDC is the problem.

C:\Users\lollipopft\rust\projects\winapi\window>cargo run --verbose
       Fresh unicode-xid v0.2.2
       Fresh windows_gen v0.11.0 (https://github.com/microsoft/windows-rs.git#05b8e30c)
       Fresh const-sha1 v0.2.0
       Fresh proc-macro2 v1.0.27
       Fresh quote v1.0.9
       Fresh syn v1.0.73
       Fresh windows_macros v0.11.0 (https://github.com/microsoft/windows-rs.git#05b8e30c)
       Fresh windows v0.11.0 (https://github.com/microsoft/windows-rs.git#05b8e30c)
   Compiling bindings v0.1.0 (C:\Users\lollipopft\rust\projects\winapi\window\bindings)
     Running `rustc --crate-name build_script_build --edition=2018 bindings\build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=ad86fbf71858be3f -C extra-filename=-ad86fbf71858be3f --out-dir C:\Users\lollipopft\rust\projects\winapi\window\target\debug\build\bindings-ad86fbf71858be3f -C incremental=C:\Users\lollipopft\rust\projects\winapi\window\target\debug\incremental -L dependency=C:\Users\lollipopft\rust\projects\winapi\window\target\debug\deps --extern windows=C:\Users\lollipopft\rust\projects\winapi\window\target\debug\deps\libwindows-e9c9cd4eae3589d1.rlib`
error: `Windows.Win32.UI.WindowsAndMessaging.CS_OWNDC` not found in metadata
 --> bindings\build.rs:5:67
  |
5 |             UI::WindowsAndMessaging::{WNDCLASSW, WNDCLASS_STYLES, CS_OWNDC, CS_HREDRAW, CS_VREDRAW, DefWindowProcW}
  |                                                                   ^^^^^^^^

error: aborting due to previous error

error: could not compile `bindings`

@kennykerr
Copy link
Collaborator

It depends on what you've asked for in your cargo.toml file. This is documented here:

https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html

If you point to GitHub then you get the latest development version, which isn't necessarily stable. If you ask for the latest version as illustrated here - https://crates.io/crates/windows - then you get the latest stable version, which is currently 0.11.0.

You should just remove CS_OWNDC, CS_HREDRAW, CS_VREDRAW from your build script. They should be included as necessary.

@LollipopFt
Copy link
Author

i see, thank you!

@LollipopFt
Copy link
Author

well turns out i do need CS_OWNDC, ran with proper crate:

C:\Users\lollipopft\rust\projects\winapi\window>cargo run
   Compiling proc-macro2 v1.0.27
   Compiling unicode-xid v0.2.2
   Compiling syn v1.0.73
   Compiling windows_gen v0.11.0
   Compiling const-sha1 v0.2.0
   Compiling quote v1.0.9
   Compiling windows_macros v0.11.0
   Compiling windows v0.11.0
   Compiling bindings v0.1.0 (C:\Users\lollipopft\rust\projects\winapi\window\bindings)
error: `Windows.Win32.UI.WindowsAndMessaging.CS_OWNDC` not found in metadata
 --> bindings\build.rs:5:67
  |
5 |             UI::WindowsAndMessaging::{WNDCLASSW, WNDCLASS_STYLES, CS_OWNDC, CS_HREDRAW, CS_VREDRAW, DefWindowProcW}
  |                                                                   ^^^^^^^^

error: aborting due to previous error

error: could not compile `bindings`

my cargo.toml:

[dependencies]
windows="0.11.0"

[build-dependencies]
windows="0.11.0"

rip

@LollipopFt LollipopFt reopened this Jun 18, 2021
@tim-weis
Copy link
Contributor

Adding WNDCLASS_STYLES to build.rs should be sufficient to have the code generator generate the constants of that type (such as CS_OWNDC). This was the result of #843.

In other words, you should replace

UI::WindowsAndMessaging::{WNDCLASSW, WNDCLASS_STYLES, CS_OWNDC, CS_HREDRAW, CS_VREDRAW, DefWindowProcW}

with

UI::WindowsAndMessaging::{WNDCLASSW, WNDCLASS_STYLES, DefWindowProcW}

The individual style constants (e.g. CS_OWNDC) are then generated into bindings::Windows::Win32::UI::WindowsAndMessaging, allowing you to import them like this:

use bindings::Windows::Win32::UI::WindowsAndMessaging::CS_OWNDC;

@LollipopFt
Copy link
Author

oh it works thanks!

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

3 participants