this post was submitted on 09 Oct 2023
6 points (100.0% liked)

Rust

111 readers
1 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
 

Hi there,

I'm trying to do some native windows rust programming. I'm using native-windows-gui and native-windows-derive to do it, but if I try to mix that with tokio, I get the following:

No entry point found error for GetWindowSubclass. On console, I get:

error: process didn't exit successfully: `C:\source\myprojectanem\target\debug\myprojectname.exe` (exit code: 0xc0000139, STATUS_ENTRYPOINT_NOT_FOUND)

If I change

#[tokio::main]
async fn main() {

to:

fn main() {

The problem goes away, but obviously I can't use tokio then.

Any clue what the problem is and how to fix it?

top 3 comments
sorted by: hot top controversial new old
[–] modulus@lemmy.ml 5 points 1 year ago (1 children)

Apparently the problem is due to an incompatibility between the use of certain libraries (winapi and windows-sys) which use different versions of COM. At least so I deduce from the documentation I've read.

There's a workaaround:

On Cargo.toml, use.

[build-dependencies]
embed-manifest = "1.3.1"

And on the root of the project (not the src dir) create a build.rs file with the following content:

use embed_manifest::{embed_manifest, new_manifest};

fn main() {
    if std::env::var_os("CARGO_CFG_WINDOWS").is_some() {
        embed_manifest(new_manifest("Contoso.Sample")).expect("unable to embed manifest file");
    }
    println!("cargo:rerun-if-changed=build.rs");
}

This embeds a manifest together with the executable, solving the issue.

[–] snaggen@programming.dev 1 points 1 year ago* (last edited 1 year ago) (1 children)

wouldn't it be better to use #[cfg(target_os = "windows")] instead of checking an env variable?

Reference: https://doc.rust-lang.org/rust-by-example/attribute/cfg.html

[–] modulus@lemmy.ml 1 points 1 year ago

Possibly yes. I'll check if the results are equivalent.