Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rylev committed Feb 16, 2022
1 parent bb57a8c commit 31a66e7
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 37 deletions.
33 changes: 31 additions & 2 deletions crates/libs/interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ impl Interface {
/// Generates the vtable for a COM interface
fn gen_vtable(&self, vtable_name: &syn::Ident) -> proc_macro2::TokenStream {
let name = &self.name;
// TODO
let parent_vtable = quote!(::windows::core::IUnknownVtbl);
let vtable_entries = self
.methods
.iter()
Expand All @@ -167,6 +169,32 @@ impl Interface {
})
.collect::<Vec<_>>();
let trait_name = quote::format_ident!("{}_Impl", name);
let functions = self
.methods
.iter()
.map(|m| {
let name = &m.name;
let args = m.gen_args();
quote! {

unsafe extern "system" fn #name<Identity: ::windows::core::IUnknownImpl, Impl: #trait_name, const OFFSET: isize>(this: *mut ::core::ffi::c_void, #(#args),*) -> ::windows::core::HRESULT {
let this = (this as *mut ::windows::core::RawPtr).offset(OFFSET) as *mut Identity;
let this = (*this).get_impl() as *mut Impl;
(*this).#name().into()
}
}
})
.collect::<Vec<_>>();
let entries = self
.methods
.iter()
.map(|m| {
let name = &m.name;
quote! {
#name: #name::<Identity, Impl, OFFSET>
}
})
.collect::<Vec<_>>();
quote! {
#[repr(C)]
#[doc(hidden)]
Expand All @@ -178,9 +206,10 @@ impl Interface {

impl #vtable_name {
pub const fn new<Identity: ::windows::core::IUnknownImpl, Impl: #trait_name, const OFFSET: isize>() -> Self {
loop {}
#(#functions)*
Self { base: #parent_vtable::new::<Identity, Impl, OFFSET>(), #(#entries),* }
}

pub fn matches(iid: &windows::core::GUID) -> bool {
iid == &<#name as ::windows::core::Interface>::IID
}
Expand Down
122 changes: 87 additions & 35 deletions crates/tests/interface/tests/com.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#![allow(non_snake_case)]
#![feature(const_fn_trait_bound)]

use windows::{
core::*,
Win32::Foundation::*,
Win32::System::Com::*,
};
use windows::{core::*, Win32::Foundation::*, Win32::System::Com::*};

#[interface("a39ee748-6a27-4817-a6f2-13914bef5890")]
pub unsafe trait ICustomUri : IUnknown {
pub unsafe trait ICustomUri: IUnknown {
unsafe fn GetPropertyBSTR(&self) -> HRESULT;
unsafe fn GetPropertyLength(&self) -> HRESULT;
unsafe fn GetPropertyDWORD(&self) -> HRESULT;
Expand All @@ -24,13 +20,27 @@ pub unsafe trait ICustomUri : IUnknown {
struct CustomUri;

impl ICustomUri_Impl for CustomUri {
unsafe fn GetPropertyBSTR(&self) -> HRESULT{ todo!() }
unsafe fn GetPropertyLength(&self) -> HRESULT{ todo!() }
unsafe fn GetPropertyDWORD(&self) -> HRESULT{ todo!() }
unsafe fn HasProperty(&self) -> HRESULT{ todo!() }
unsafe fn GetAbsoluteUri(&self) -> HRESULT{ todo!() }
unsafe fn GetAuthority(&self) -> HRESULT{ todo!() }
unsafe fn GetDisplayUri(&self) -> HRESULT{ todo!() }
unsafe fn GetPropertyBSTR(&self) -> HRESULT {
todo!()
}
unsafe fn GetPropertyLength(&self) -> HRESULT {
todo!()
}
unsafe fn GetPropertyDWORD(&self) -> HRESULT {
todo!()
}
unsafe fn HasProperty(&self) -> HRESULT {
todo!()
}
unsafe fn GetAbsoluteUri(&self) -> HRESULT {
todo!()
}
unsafe fn GetAuthority(&self) -> HRESULT {
todo!()
}
unsafe fn GetDisplayUri(&self) -> HRESULT {
todo!()
}
unsafe fn GetDomain(&self, value: *mut BSTR) -> HRESULT {
*value = "kennykerr.ca".into();
S_OK
Expand All @@ -47,30 +57,72 @@ impl IUri_Impl for CustomUri {
fn GetPropertyDWORD(&self, uriprop: Uri_PROPERTY, pdwproperty: *mut u32, dwflags: u32) -> ::windows::core::Result<()> {
todo!()
}
fn HasProperty(&self, uriprop: Uri_PROPERTY) -> ::windows::core::Result<BOOL> { todo!() }
fn GetAbsoluteUri(&self) -> ::windows::core::Result<BSTR> { todo!() }
fn GetAuthority(&self) -> ::windows::core::Result<BSTR> { todo!() }
fn GetDisplayUri(&self) -> ::windows::core::Result<BSTR> { todo!() }
fn HasProperty(&self, uriprop: Uri_PROPERTY) -> ::windows::core::Result<BOOL> {
todo!()
}
fn GetAbsoluteUri(&self) -> ::windows::core::Result<BSTR> {
todo!()
}
fn GetAuthority(&self) -> ::windows::core::Result<BSTR> {
todo!()
}
fn GetDisplayUri(&self) -> ::windows::core::Result<BSTR> {
todo!()
}
fn GetDomain(&self) -> ::windows::core::Result<BSTR> {
Ok("kennykerr.ca".into())
}
fn GetExtension(&self) -> ::windows::core::Result<BSTR> { todo!() }
fn GetFragment(&self) -> ::windows::core::Result<BSTR> { todo!() }
fn GetHost(&self) -> ::windows::core::Result<BSTR> { todo!() }
fn GetPassword(&self) -> ::windows::core::Result<BSTR> { todo!() }
fn GetPath(&self) -> ::windows::core::Result<BSTR> { todo!() }
fn GetPathAndQuery(&self) -> ::windows::core::Result<BSTR> { todo!() }
fn GetQuery(&self) -> ::windows::core::Result<BSTR> { todo!() }
fn GetRawUri(&self) -> ::windows::core::Result<BSTR> { todo!() }
fn GetSchemeName(&self) -> ::windows::core::Result<BSTR> { todo!() }
fn GetUserInfo(&self) -> ::windows::core::Result<BSTR> { todo!() }
fn GetUserName(&self) -> ::windows::core::Result<BSTR> { todo!() }
fn GetHostType(&self) -> ::windows::core::Result<u32> { todo!() }
fn GetPort(&self) -> ::windows::core::Result<u32> { todo!() }
fn GetScheme(&self) -> ::windows::core::Result<u32> { todo!() }
fn GetZone(&self) -> ::windows::core::Result<u32> { todo!() }
fn GetProperties(&self) -> ::windows::core::Result<u32> { todo!() }
fn IsEqual(&self, puri: &::core::option::Option<IUri>) -> ::windows::core::Result<BOOL> { todo!() }
fn GetExtension(&self) -> ::windows::core::Result<BSTR> {
todo!()
}
fn GetFragment(&self) -> ::windows::core::Result<BSTR> {
todo!()
}
fn GetHost(&self) -> ::windows::core::Result<BSTR> {
todo!()
}
fn GetPassword(&self) -> ::windows::core::Result<BSTR> {
todo!()
}
fn GetPath(&self) -> ::windows::core::Result<BSTR> {
todo!()
}
fn GetPathAndQuery(&self) -> ::windows::core::Result<BSTR> {
todo!()
}
fn GetQuery(&self) -> ::windows::core::Result<BSTR> {
todo!()
}
fn GetRawUri(&self) -> ::windows::core::Result<BSTR> {
todo!()
}
fn GetSchemeName(&self) -> ::windows::core::Result<BSTR> {
todo!()
}
fn GetUserInfo(&self) -> ::windows::core::Result<BSTR> {
todo!()
}
fn GetUserName(&self) -> ::windows::core::Result<BSTR> {
todo!()
}
fn GetHostType(&self) -> ::windows::core::Result<u32> {
todo!()
}
fn GetPort(&self) -> ::windows::core::Result<u32> {
todo!()
}
fn GetScheme(&self) -> ::windows::core::Result<u32> {
todo!()
}
fn GetZone(&self) -> ::windows::core::Result<u32> {
todo!()
}
fn GetProperties(&self) -> ::windows::core::Result<u32> {
todo!()
}
fn IsEqual(&self, puri: &::core::option::Option<IUri>) -> ::windows::core::Result<BOOL> {
todo!()
}
}

#[test]
Expand Down Expand Up @@ -100,4 +152,4 @@ fn test_custom_interface() -> windows::core::Result<()> {

Ok(())
}
}
}

0 comments on commit 31a66e7

Please sign in to comment.