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

Use new windows-bindgen #7

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ Cargo.lock
.metadata/bin
obj
bin
.vs
.vs
*.sln
21 changes: 21 additions & 0 deletions .metadata/idl/state.idl
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import "objidl.idl";
import "oaidl.idl";
import "propidl.idl";
// import "wtypes.idl";

typedef struct StateData
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this struct is removed, and getbool() returns BOOLEAN, bindgen can correctly reference windows crate BOOLEAN type.

{
BOOLEAN Ok;
BOOL Ok2;
LPCWSTR Name;
LPCSTR Name2;
ULONG Number;
LONG Number2;
DWORD Flags;
BYTE* Data;
void* Reserved;
} StateData;

[
object,
Expand All @@ -12,4 +26,11 @@ import "propidl.idl";
interface IState: IUnknown
{
HRESULT GetFlower([out, retval] BSTR* flower);

// If the above StateData struct is removed
// This works for bindgen. It correctly references to the windows crate.
// BOOLEAN GetBool();
DWORD GetBool();

StateData* GetData();
}
Binary file modified .windows/winmd/Microsoft.States.winmd
Binary file not shown.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ version = "0.58.0"

[build-dependencies.windows-bindgen]
version = "0.58.0"

[patch.crates-io]
windows-bindgen = { git = "https://github.com/microsoft/windows-rs.git", rev = "b7c2cd5031ba952bc6d072d6641a9a5444ac912d"}
windows = { git = "https://github.com/microsoft/windows-rs.git", rev = "b7c2cd5031ba952bc6d072d6641a9a5444ac912d"}
windows-core = { git = "https://github.com/microsoft/windows-rs.git", rev = "b7c2cd5031ba952bc6d072d6641a9a5444ac912d"}
9 changes: 5 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ fn main() {
windows_bindgen::bindgen([
"--in",
".windows/winmd/Microsoft.States.winmd",
"--in",
"default",
"--out",
"src/bindings.rs",
"--filter",
"Microsoft.States",
"--config",
"implement"
])
.unwrap();
"--reference",
"windows,skip-root,Windows",
]);
}
20 changes: 14 additions & 6 deletions crates/samples/impl/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use washington_rs::States::*;
use windows::core::*;
use washington_rs::Microsoft::States::*;
use windows_core::{implement, Result, BSTR};

#[derive(Debug)]
#[implement(IState)]
Expand All @@ -10,12 +10,20 @@ impl IState_Impl for Atlantis_Impl {
fn GetFlower(&self) -> Result<BSTR> {
Ok("Red algae".into())
}

fn GetBool(&self) -> u32 {
1
}

fn GetData(&self) -> *mut StateData {
std::ptr::null_mut()
}
}

fn main() -> windows::core::Result<()> {
unsafe {
let state: IState = Atlantis.into();
println!("{}", state.GetFlower()?);
}
let com: IState = Atlantis {}.into();
let s = unsafe { com.GetFlower() }?;
println!("GetFlower: {}", s);
println!("GetBool: {}", unsafe { com.GetBool() });
Ok(())
}
Loading