This commit is contained in:
Ryan Levick 2019-09-17 16:46:07 +02:00
Родитель 476ffbaf27
Коммит 5dc08b1310
8 изменённых файлов: 28 добавлений и 35 удалений

Просмотреть файл

@ -1,8 +1,8 @@
use com::{interface, IUnknown};
use com::{com_interface, IUnknown};
use winapi::shared::winerror::HRESULT;
#[interface(25A41124-23D0-46BE-8351-044889D5E37E)]
#[com_interface(25A41124-23D0-46BE-8351-044889D5E37E)]
pub trait IFileManager: IUnknown {
fn delete_all(&mut self) -> HRESULT;
}

Просмотреть файл

@ -1,8 +1,8 @@
use com::{interface, IUnknown};
use com::{com_interface, IUnknown};
use winapi::shared::winerror::HRESULT;
#[interface(4FC333E3-C389-4C48-B108-7895B0AF21AD)]
#[com_interface(4FC333E3-C389-4C48-B108-7895B0AF21AD)]
pub trait ILocalFileManager: IUnknown {
fn delete_local(&mut self) -> HRESULT;
}

Просмотреть файл

@ -5,7 +5,7 @@ use winapi::shared::winerror::{HRESULT, NOERROR};
use com::co_class;
/// The implementation class
#[co_class(implements(ILocalFileManager, aggregatable))]
#[co_class(implements(ILocalFileManager), aggregatable)]
pub struct LocalFileManager {
user_field: u32,
}

Просмотреть файл

@ -6,7 +6,7 @@ use com::co_class;
/// The implementation class
/// https://en.wikipedia.org/wiki/British_Shorthair
#[co_class(com_implements(ICat, IDomesticAnimal))]
#[co_class(implements(ICat, IDomesticAnimal))]
pub struct BritishShortHairCat {
num_owners: u32,
}

Просмотреть файл

@ -3,4 +3,4 @@ mod british_short_hair_cat;
use british_short_hair_cat::BritishShortHairCat;
use interface::CLSID_CAT_CLASS;
com::com_inproc_dll_module![(CLSID_CAT_CLASS, BritishShortHairCat),];
com::inproc_dll_module![(CLSID_CAT_CLASS, BritishShortHairCat),];

Просмотреть файл

@ -1,7 +1,5 @@
use quote::{format_ident,};
use syn::{
Ident, Meta, NestedMeta, AttributeArgs,
};
use quote::format_ident;
use syn::{AttributeArgs, Ident, Meta, NestedMeta};
use std::collections::HashMap;
@ -42,13 +40,16 @@ pub fn base_interface_idents(attr_args: &AttributeArgs) -> Vec<Ident> {
for attr_arg in attr_args {
if let NestedMeta::Meta(Meta::List(ref attr)) = attr_arg {
if attr.path.segments.last().unwrap().ident != "com_implements" {
if attr.path.segments.last().unwrap().ident != "implements" {
continue;
}
for item in &attr.nested {
if let NestedMeta::Meta(Meta::Path(p)) = item {
assert!(p.segments.len() == 1, "Incapable of handling multiple path segments yet.");
assert!(
p.segments.len() == 1,
"Incapable of handling multiple path segments yet."
);
base_interface_idents.push(p.segments.last().unwrap().ident.clone());
}
}
@ -66,28 +67,30 @@ pub fn get_aggr_map(attr_args: &AttributeArgs) -> HashMap<Ident, Vec<Ident>> {
for attr_arg in attr_args {
if let NestedMeta::Meta(Meta::List(ref attr)) = attr_arg {
if attr.path.segments.last().unwrap().ident != "aggr" {
if attr.path.segments.last().unwrap().ident != "aggregates" {
continue;
}
let mut aggr_interfaces_idents = Vec::new();
assert!(attr.nested.len() > 0, "Need to expose at least one interface from aggregated COM object.");
assert!(
attr.nested.len() > 0,
"Need to expose at least one interface from aggregated COM object."
);
for item in &attr.nested {
if let NestedMeta::Meta(Meta::Path(p)) = item {
assert!(p.segments.len() == 1, "Incapable of handling multiple path segments yet.");
assert!(
p.segments.len() == 1,
"Incapable of handling multiple path segments yet."
);
aggr_interfaces_idents.push(p.segments.last().unwrap().ident.clone());
}
}
let ident = aggr_interfaces_idents.iter()
.map(|base| {
crate::camel_to_snake(&base.to_string())
})
.fold("aggr".to_owned(), |acc, base| {
format!("{}_{}", acc, base)
});
let ident = aggr_interfaces_idents
.iter()
.map(|base| crate::camel_to_snake(&base.to_string()))
.fold("aggr".to_owned(), |acc, base| format!("{}_{}", acc, base));
aggr_map.insert(format_ident!("{}", ident), aggr_interfaces_idents);
}
}

Просмотреть файл

@ -26,13 +26,3 @@ pub fn co_class(attr: TokenStream, item: TokenStream) -> TokenStream {
pub fn aggr_co_class(attr: TokenStream, item: TokenStream) -> TokenStream {
expand_aggr_co_class(attr, item)
}
#[proc_macro_attribute]
pub fn com_implements(_attr: TokenStream, item: TokenStream) -> TokenStream {
item
}
#[proc_macro_attribute]
pub fn aggr(_attr: TokenStream, item: TokenStream) -> TokenStream {
item
}

Просмотреть файл

@ -172,7 +172,7 @@ pub fn guid_to_string(guid: &GUID) -> String {
}
#[macro_export]
macro_rules! com_inproc_dll_module {
macro_rules! inproc_dll_module {
(($clsid_one:ident, $classtype_one:ty), $(($clsid:ident, $classtype:ty)),*) => {
#[no_mangle]
extern "stdcall" fn DllGetClassObject(rclsid: $crate::_winapi::shared::guiddef::REFCLSID, riid: $crate::_winapi::shared::guiddef::REFIID, ppv: *mut $crate::_winapi::shared::minwindef::LPVOID) -> $crate::_winapi::shared::winerror::HRESULT {