diff --git a/Cargo.toml b/Cargo.toml index 72e7364..8f722b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,5 @@ edition = "2018" members = [ "examples/basic/client", "examples/basic/server", + "examples/basic/interface", ] \ No newline at end of file diff --git a/examples/basic/client/Cargo.toml b/examples/basic/client/Cargo.toml index 8d1d03d..af08b6c 100644 --- a/examples/basic/client/Cargo.toml +++ b/examples/basic/client/Cargo.toml @@ -6,4 +6,4 @@ edition = "2018" [dependencies] com = { path = "../../.." } -server = { path = "../server" } +interface = { path = "../interface" } diff --git a/examples/basic/client/src/main.rs b/examples/basic/client/src/main.rs index b7b65c6..381cfc1 100644 --- a/examples/basic/client/src/main.rs +++ b/examples/basic/client/src/main.rs @@ -13,7 +13,7 @@ use com::{ ComPtr, IClassFactory, IUnknown, CLSCTX_INPROC_SERVER, COINIT_APARTMENTTHREADED, HRESULT, IID, IID_ICLASS_FACTORY, LPVOID, REFCLSID, REFIID, }; -use server::{ +use interface::{ IAnimal, ICat, IDomesticAnimal, IExample, IFileManager, ILocalFileManager, CLSID_CAT_CLASS, CLSID_LOCAL_FILE_MANAGER_CLASS, CLSID_WINDOWS_FILE_MANAGER_CLASS, }; diff --git a/examples/basic/interface/.gitignore b/examples/basic/interface/.gitignore new file mode 100644 index 0000000..6936990 --- /dev/null +++ b/examples/basic/interface/.gitignore @@ -0,0 +1,3 @@ +/target +**/*.rs.bk +Cargo.lock diff --git a/examples/basic/interface/Cargo.toml b/examples/basic/interface/Cargo.toml new file mode 100644 index 0000000..665ab74 --- /dev/null +++ b/examples/basic/interface/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "interface" +version = "0.1.0" +authors = ["Microsoft Corp"] +edition = "2018" + +[dependencies] +com = { path = "../../.." } + +[lib] +crate-type = ["rlib", "cdylib"] \ No newline at end of file diff --git a/examples/basic/server/src/interface/ianimal.rs b/examples/basic/interface/src/ianimal.rs similarity index 85% rename from examples/basic/server/src/interface/ianimal.rs rename to examples/basic/interface/src/ianimal.rs index 24329eb..b1a79b5 100644 --- a/examples/basic/server/src/interface/ianimal.rs +++ b/examples/basic/interface/src/ianimal.rs @@ -28,7 +28,7 @@ unsafe impl ComInterface for IAnimal { } #[repr(C)] -pub(crate) struct RawIAnimal { +pub struct RawIAnimal { vtable: *const IAnimalVTable, } @@ -37,7 +37,7 @@ impl RawIAnimal { let _ = unsafe { self.raw_eat() }; } - pub unsafe fn raw_eat(&mut self) -> HRESULT { + unsafe fn raw_eat(&mut self) -> HRESULT { ((*self.vtable).1.Eat)(self as *mut RawIAnimal) } } @@ -55,10 +55,10 @@ impl std::convert::AsMut for RawIAnimal { } #[repr(C)] -struct IAnimalVTable(IUnknownMethods, IAnimalMethods); +pub struct IAnimalVTable(IUnknownMethods, IAnimalMethods); #[allow(non_snake_case)] #[repr(C)] pub struct IAnimalMethods { - pub(crate) Eat: unsafe extern "stdcall" fn(*mut RawIAnimal) -> HRESULT, + pub Eat: unsafe extern "stdcall" fn(*mut RawIAnimal) -> HRESULT, } diff --git a/examples/basic/server/src/interface/icat.rs b/examples/basic/interface/src/icat.rs similarity index 87% rename from examples/basic/server/src/interface/icat.rs rename to examples/basic/interface/src/icat.rs index 71d45be..6c2b943 100644 --- a/examples/basic/server/src/interface/icat.rs +++ b/examples/basic/interface/src/icat.rs @@ -10,7 +10,7 @@ pub const IID_ICAT: IID = IID { #[repr(C)] pub struct ICat { - pub(crate) inner: RawICat, + pub inner: RawICat, } impl ICat { @@ -34,12 +34,12 @@ unsafe impl ComInterface for ICat { } #[repr(C)] -pub(crate) struct RawICat { - pub(crate) vtable: *const ICatVTable, +pub struct RawICat { + pub vtable: *const ICatVTable, } impl RawICat { - unsafe fn raw_ignore_humans(&mut self) -> HRESULT { + pub unsafe fn raw_ignore_humans(&mut self) -> HRESULT { ((*self.vtable).2.IgnoreHumans)(self as *mut RawICat) } } @@ -71,7 +71,8 @@ impl std::convert::AsMut for RawICat { #[allow(non_snake_case)] #[repr(C)] pub struct ICatMethods { - pub(crate) IgnoreHumans: unsafe extern "stdcall" fn(*mut RawICat) -> HRESULT, + pub IgnoreHumans: unsafe extern "stdcall" fn(*mut RawICat) -> HRESULT, } + #[repr(C)] pub struct ICatVTable(pub IUnknownMethods, pub IAnimalMethods, pub ICatMethods); diff --git a/examples/basic/server/src/interface/icat_class.rs b/examples/basic/interface/src/icat_class.rs similarity index 90% rename from examples/basic/server/src/interface/icat_class.rs rename to examples/basic/interface/src/icat_class.rs index 3d1bbb9..dad5483 100644 --- a/examples/basic/server/src/interface/icat_class.rs +++ b/examples/basic/interface/src/icat_class.rs @@ -9,7 +9,7 @@ pub const IID_ICAT_CLASS: IID = IID { #[repr(C)] pub struct ICatClass { - pub(crate) inner: RawICatClass, + pub inner: RawICatClass, } impl ICatClass { @@ -24,8 +24,8 @@ unsafe impl ComInterface for ICatClass { } #[repr(C)] -pub(crate) struct RawICatClass { - pub(crate) vtable: *const ICatClassVTable, +pub struct RawICatClass { + pub vtable: *const ICatClassVTable, } impl std::convert::AsRef for RawICatClass { @@ -43,6 +43,7 @@ impl std::convert::AsMut for RawICatClass { #[allow(non_snake_case)] #[repr(C)] pub struct ICatClassMethods {} + #[repr(C)] pub struct ICatClassVTable( pub IUnknownMethods, diff --git a/examples/basic/server/src/interface/idomesticanimal.rs b/examples/basic/interface/src/idomesticanimal.rs similarity index 89% rename from examples/basic/server/src/interface/idomesticanimal.rs rename to examples/basic/interface/src/idomesticanimal.rs index 1272494..3977a99 100644 --- a/examples/basic/server/src/interface/idomesticanimal.rs +++ b/examples/basic/interface/src/idomesticanimal.rs @@ -10,7 +10,7 @@ pub const IID_IDOMESTIC_ANIMAL: IID = IID { #[repr(C)] pub struct IDomesticAnimal { - pub(crate) inner: RawIDomesticAnimal, + pub inner: RawIDomesticAnimal, } impl IDomesticAnimal { @@ -34,8 +34,8 @@ unsafe impl ComInterface for IDomesticAnimal { } #[repr(C)] -pub(crate) struct RawIDomesticAnimal { - pub(crate) vtable: *const IDomesticAnimalVTable, +pub struct RawIDomesticAnimal { + pub vtable: *const IDomesticAnimalVTable, } impl RawIDomesticAnimal { @@ -71,8 +71,9 @@ impl std::convert::AsMut for RawIDomesticAnimal { #[allow(non_snake_case)] #[repr(C)] pub struct IDomesticAnimalMethods { - pub(crate) Train: unsafe extern "stdcall" fn(*mut RawIDomesticAnimal) -> HRESULT, + pub Train: unsafe extern "stdcall" fn(*mut RawIDomesticAnimal) -> HRESULT, } + #[repr(C)] pub struct IDomesticAnimalVTable( pub IUnknownMethods, diff --git a/examples/basic/server/src/interface/iexample.rs b/examples/basic/interface/src/iexample.rs similarity index 97% rename from examples/basic/server/src/interface/iexample.rs rename to examples/basic/interface/src/iexample.rs index 02e6105..c15572a 100644 --- a/examples/basic/server/src/interface/iexample.rs +++ b/examples/basic/interface/src/iexample.rs @@ -24,7 +24,7 @@ unsafe impl ComInterface for IExample { } #[repr(C)] -pub(crate) struct RawIExample { +pub struct RawIExample { vtable: *const IExampleVTable, } diff --git a/examples/basic/server/src/interface/ifilemanager.rs b/examples/basic/interface/src/ifilemanager.rs similarity index 86% rename from examples/basic/server/src/interface/ifilemanager.rs rename to examples/basic/interface/src/ifilemanager.rs index 24bad47..e0a83e2 100644 --- a/examples/basic/server/src/interface/ifilemanager.rs +++ b/examples/basic/interface/src/ifilemanager.rs @@ -9,7 +9,7 @@ pub const IID_IFILE_MANAGER: IID = IID { #[repr(C)] pub struct IFileManager { - pub(crate) inner: RawIFileManager, + pub inner: RawIFileManager, } impl IFileManager { @@ -28,8 +28,8 @@ unsafe impl ComInterface for IFileManager { } #[repr(C)] -pub(crate) struct RawIFileManager { - pub(crate) vtable: *const IFileManagerVTable, +pub struct RawIFileManager { + pub vtable: *const IFileManagerVTable, } impl RawIFileManager { @@ -53,7 +53,7 @@ impl std::convert::AsMut for RawIFileManager { #[allow(non_snake_case)] #[repr(C)] pub struct IFileManagerMethods { - pub(crate) DeleteAll: unsafe extern "stdcall" fn(*mut RawIFileManager) -> HRESULT, + pub DeleteAll: unsafe extern "stdcall" fn(*mut RawIFileManager) -> HRESULT, } #[repr(C)] pub struct IFileManagerVTable(pub IUnknownMethods, pub IFileManagerMethods); diff --git a/examples/basic/server/src/interface/ilocalfilemanager.rs b/examples/basic/interface/src/ilocalfilemanager.rs similarity index 86% rename from examples/basic/server/src/interface/ilocalfilemanager.rs rename to examples/basic/interface/src/ilocalfilemanager.rs index a4ca308..733e763 100644 --- a/examples/basic/server/src/interface/ilocalfilemanager.rs +++ b/examples/basic/interface/src/ilocalfilemanager.rs @@ -9,7 +9,7 @@ pub const IID_ILOCAL_FILE_MANAGER: IID = IID { #[repr(C)] pub struct ILocalFileManager { - pub(crate) inner: RawILocalFileManager, + pub inner: RawILocalFileManager, } impl ILocalFileManager { @@ -28,8 +28,8 @@ unsafe impl ComInterface for ILocalFileManager { } #[repr(C)] -pub(crate) struct RawILocalFileManager { - pub(crate) vtable: *const ILocalFileManagerVTable, +pub struct RawILocalFileManager { + pub vtable: *const ILocalFileManagerVTable, } impl RawILocalFileManager { @@ -53,7 +53,8 @@ impl std::convert::AsMut for RawILocalFileManager { #[allow(non_snake_case)] #[repr(C)] pub struct ILocalFileManagerMethods { - pub(crate) DeleteLocal: unsafe extern "stdcall" fn(*mut RawILocalFileManager) -> HRESULT, + pub DeleteLocal: unsafe extern "stdcall" fn(*mut RawILocalFileManager) -> HRESULT, } + #[repr(C)] pub struct ILocalFileManagerVTable(pub IUnknownMethods, pub ILocalFileManagerMethods); diff --git a/examples/basic/interface/src/lib.rs b/examples/basic/interface/src/lib.rs new file mode 100644 index 0000000..6b70f2a --- /dev/null +++ b/examples/basic/interface/src/lib.rs @@ -0,0 +1,38 @@ +pub mod ianimal; +pub mod icat; +pub mod icat_class; +pub mod idomesticanimal; +pub mod iexample; +pub mod ifilemanager; +pub mod ilocalfilemanager; + +pub use ianimal::IAnimal; +pub use icat::ICat; +pub use icat_class::ICatClass; +pub use idomesticanimal::IDomesticAnimal; +pub use iexample::IExample; +pub use ifilemanager::IFileManager; +pub use ilocalfilemanager::ILocalFileManager; + +use com::IID; + +pub const CLSID_CAT_CLASS: IID = IID { + data1: 0xC5F45CBC, + data2: 0x4439, + data3: 0x418C, + data4: [0xA9, 0xF9, 0x05, 0xAC, 0x67, 0x52, 0x5E, 0x43], +}; + +pub const CLSID_WINDOWS_FILE_MANAGER_CLASS: IID = IID { + data1: 0x5ffa71bd, + data2: 0x6d1d, + data3: 0x4727, + data4: [0xb4, 0xec, 0xda, 0x9d, 0x9d, 0x21, 0x15, 0xd1], +}; + +pub const CLSID_LOCAL_FILE_MANAGER_CLASS: IID = IID { + data1: 0xb5bbcb63, + data2: 0x9783, + data3: 0x4f96, + data4: [0xa0, 0x37, 0x6b, 0xb1, 0xf9, 0x8a, 0xd8, 0x44], +}; diff --git a/examples/basic/server/Cargo.toml b/examples/basic/server/Cargo.toml index ca49ac9..5b37e5a 100644 --- a/examples/basic/server/Cargo.toml +++ b/examples/basic/server/Cargo.toml @@ -6,6 +6,7 @@ edition = "2018" [dependencies] com = { path = "../../.." } +interface = { path = "../interface" } [lib] crate-type = ["rlib", "cdylib"] \ No newline at end of file diff --git a/examples/basic/server/src/implementation/british_short_hair_cat.rs b/examples/basic/server/src/british_short_hair_cat.rs similarity index 95% rename from examples/basic/server/src/implementation/british_short_hair_cat.rs rename to examples/basic/server/src/british_short_hair_cat.rs index 97e8a91..2844d80 100644 --- a/examples/basic/server/src/implementation/british_short_hair_cat.rs +++ b/examples/basic/server/src/british_short_hair_cat.rs @@ -1,6 +1,7 @@ use std::os::raw::c_void; -use crate::interface::{ +use com::{IUnknownMethods, RawIUnknown, E_NOINTERFACE, HRESULT, IID, IID_IUNKNOWN, NOERROR}; +use interface::{ ianimal::{IAnimalMethods, RawIAnimal, IID_IANIMAL}, icat::{ICat, ICatMethods, ICatVTable, RawICat, IID_ICAT}, idomesticanimal::{ @@ -8,7 +9,6 @@ use crate::interface::{ IID_IDOMESTIC_ANIMAL, }, }; -use com::{IID_IUnknown, IUnknownMethods, RawIUnknown, E_NOINTERFACE, HRESULT, IID, NOERROR}; /// The implementation class /// https://en.wikipedia.org/wiki/British_Shorthair @@ -32,10 +32,10 @@ unsafe extern "stdcall" fn icat_query_interface( ppv: *mut *mut c_void, ) -> HRESULT { println!("Querying interface through ICat's IUnknown..."); - let obj = this as *mut BritishShortHairCat; + let _obj = this as *mut BritishShortHairCat; match *riid { - IID_IUnknown | IID_ICAT | IID_IANIMAL => { + IID_IUNKNOWN | IID_ICAT | IID_IANIMAL => { println!("Returning this."); *ppv = this as *mut c_void; } diff --git a/examples/basic/server/src/implementation/british_short_hair_cat_class.rs b/examples/basic/server/src/british_short_hair_cat_class.rs similarity index 88% rename from examples/basic/server/src/implementation/british_short_hair_cat_class.rs rename to examples/basic/server/src/british_short_hair_cat_class.rs index 8e18e7f..6d2a737 100644 --- a/examples/basic/server/src/implementation/british_short_hair_cat_class.rs +++ b/examples/basic/server/src/british_short_hair_cat_class.rs @@ -1,12 +1,13 @@ use std::os::raw::c_void; -use crate::implementation::BritishShortHairCat; -use crate::interface::icat_class::{ - ICatClass, ICatClassMethods, ICatClassVTable, RawICatClass, IID_ICAT_CLASS, -}; +use crate::BritishShortHairCat; use com::{ - IClassFactoryMethods, IID_IUnknown, IUnknownMethods, RawIClassFactory, RawIUnknown, BOOL, - CLASS_E_NOAGGREGATION, E_NOINTERFACE, HRESULT, IID, IID_ICLASS_FACTORY, NOERROR, S_OK, + IClassFactoryMethods, IUnknownMethods, RawIClassFactory, RawIUnknown, BOOL, + CLASS_E_NOAGGREGATION, E_NOINTERFACE, HRESULT, IID, IID_ICLASS_FACTORY, IID_IUNKNOWN, NOERROR, + S_OK, +}; +use interface::icat_class::{ + ICatClass, ICatClassMethods, ICatClassVTable, RawICatClass, IID_ICAT_CLASS, }; #[repr(C)] @@ -27,7 +28,7 @@ unsafe extern "stdcall" fn query_interface( ppv: *mut *mut c_void, ) -> HRESULT { println!("Querying interface on CatClass..."); - if *riid == IID_IUnknown || *riid == IID_ICLASS_FACTORY || *riid == IID_ICAT_CLASS { + if *riid == IID_IUNKNOWN || *riid == IID_ICLASS_FACTORY || *riid == IID_ICAT_CLASS { *ppv = this as *mut c_void; (*this).raw_add_ref(); NOERROR @@ -59,7 +60,7 @@ unsafe extern "stdcall" fn release(this: *mut RawIUnknown) -> u32 { } unsafe extern "stdcall" fn create_instance( - this: *mut RawIClassFactory, + _this: *mut RawIClassFactory, aggregate: *mut RawIUnknown, riid: *const IID, ppv: *mut *mut c_void, @@ -76,7 +77,7 @@ unsafe extern "stdcall" fn create_instance( hr } -unsafe extern "stdcall" fn lock_server(increment: BOOL) -> HRESULT { +unsafe extern "stdcall" fn lock_server(_increment: BOOL) -> HRESULT { println!("LockServer called"); S_OK } diff --git a/examples/basic/server/src/interface/mod.rs b/examples/basic/server/src/interface/mod.rs deleted file mode 100644 index 4215c6d..0000000 --- a/examples/basic/server/src/interface/mod.rs +++ /dev/null @@ -1,15 +0,0 @@ -pub(crate) mod ianimal; -pub(crate) mod icat; -pub(crate) mod icat_class; -pub(crate) mod idomesticanimal; -pub(crate) mod iexample; -pub(crate) mod ifilemanager; -pub(crate) mod ilocalfilemanager; - -pub use ianimal::IAnimal; -pub use icat::ICat; -pub use icat_class::ICatClass; -pub use idomesticanimal::IDomesticAnimal; -pub use iexample::IExample; -pub use ifilemanager::IFileManager; -pub use ilocalfilemanager::ILocalFileManager; diff --git a/examples/basic/server/src/lib.rs b/examples/basic/server/src/lib.rs index da3fabc..0d7a040 100644 --- a/examples/basic/server/src/lib.rs +++ b/examples/basic/server/src/lib.rs @@ -1,30 +1,19 @@ -mod implementation; -mod interface; +use com::{RawIUnknown, CLASS_E_CLASSNOTAVAILABLE, HRESULT, LPVOID, REFCLSID, REFIID}; +use interface::{CLSID_CAT_CLASS, CLSID_LOCAL_FILE_MANAGER_CLASS, CLSID_WINDOWS_FILE_MANAGER_CLASS}; -use com::{RawIUnknown, CLASS_E_CLASSNOTAVAILABLE, HRESULT, IID, LPVOID, REFCLSID, REFIID}; +mod british_short_hair_cat; +mod british_short_hair_cat_class; +mod local_file_manager; +mod local_file_manager_class; +mod windows_file_manager; +mod windows_file_manager_class; -pub use interface::{IAnimal, ICat, IDomesticAnimal, IExample, IFileManager, ILocalFileManager}; - -pub const CLSID_CAT_CLASS: IID = IID { - data1: 0xC5F45CBC, - data2: 0x4439, - data3: 0x418C, - data4: [0xA9, 0xF9, 0x05, 0xAC, 0x67, 0x52, 0x5E, 0x43], -}; - -pub const CLSID_WINDOWS_FILE_MANAGER_CLASS: IID = IID { - data1: 0x5ffa71bd, - data2: 0x6d1d, - data3: 0x4727, - data4: [0xb4, 0xec, 0xda, 0x9d, 0x9d, 0x21, 0x15, 0xd1], -}; - -pub const CLSID_LOCAL_FILE_MANAGER_CLASS: IID = IID { - data1: 0xb5bbcb63, - data2: 0x9783, - data3: 0x4f96, - data4: [0xa0, 0x37, 0x6b, 0xb1, 0xf9, 0x8a, 0xd8, 0x44], -}; +use british_short_hair_cat::BritishShortHairCat; +use british_short_hair_cat_class::BritishShortHairCatClass; +use local_file_manager::LocalFileManager; +use local_file_manager_class::LocalFileManagerClass; +use windows_file_manager::WindowsFileManager; +use windows_file_manager_class::WindowsFileManagerClass; #[no_mangle] extern "stdcall" fn DllGetClassObject(rclsid: REFCLSID, riid: REFIID, ppv: *mut LPVOID) -> HRESULT { @@ -32,7 +21,7 @@ extern "stdcall" fn DllGetClassObject(rclsid: REFCLSID, riid: REFIID, ppv: *mut match *rclsid { CLSID_CAT_CLASS => { println!("Allocating new object CatClass..."); - let cat = Box::into_raw(Box::new(implementation::BritishShortHairCatClass::new())); + let cat = Box::into_raw(Box::new(BritishShortHairCatClass::new())); (*(cat as *mut RawIUnknown)).raw_add_ref(); let hr = (*(cat as *mut RawIUnknown)).raw_query_interface(riid, ppv); (*(cat as *mut RawIUnknown)).raw_release(); @@ -40,7 +29,7 @@ extern "stdcall" fn DllGetClassObject(rclsid: REFCLSID, riid: REFIID, ppv: *mut } CLSID_WINDOWS_FILE_MANAGER_CLASS => { println!("Allocating new object WindowsFileManagerClass..."); - let wfm = Box::into_raw(Box::new(implementation::WindowsFileManagerClass::new())); + let wfm = Box::into_raw(Box::new(WindowsFileManagerClass::new())); (*(wfm as *mut RawIUnknown)).raw_add_ref(); let hr = (*(wfm as *mut RawIUnknown)).raw_query_interface(riid, ppv); (*(wfm as *mut RawIUnknown)).raw_release(); @@ -48,7 +37,7 @@ extern "stdcall" fn DllGetClassObject(rclsid: REFCLSID, riid: REFIID, ppv: *mut } CLSID_LOCAL_FILE_MANAGER_CLASS => { println!("Allocating new object LocalFileManagerClass..."); - let lfm = Box::into_raw(Box::new(implementation::LocalFileManagerClass::new())); + let lfm = Box::into_raw(Box::new(LocalFileManagerClass::new())); (*(lfm as *mut RawIUnknown)).raw_add_ref(); let hr = (*(lfm as *mut RawIUnknown)).raw_query_interface(riid, ppv); (*(lfm as *mut RawIUnknown)).raw_release(); @@ -56,8 +45,5 @@ extern "stdcall" fn DllGetClassObject(rclsid: REFCLSID, riid: REFIID, ppv: *mut } _ => CLASS_E_CLASSNOTAVAILABLE, } - // if *rclsid != CLSID_CAT_CLASS { - // return CLASS_E_CLASSNOTAVAILABLE; - // } } } diff --git a/examples/basic/server/src/implementation/local_file_manager.rs b/examples/basic/server/src/local_file_manager.rs similarity index 95% rename from examples/basic/server/src/implementation/local_file_manager.rs rename to examples/basic/server/src/local_file_manager.rs index 939975d..dafe52c 100644 --- a/examples/basic/server/src/implementation/local_file_manager.rs +++ b/examples/basic/server/src/local_file_manager.rs @@ -1,13 +1,13 @@ use std::os::raw::c_void; -use crate::interface::ilocalfilemanager::{ +use com::{ + IUnknownMethods, IUnknownVTable, RawIUnknown, E_NOINTERFACE, HRESULT, IID, IID_IUNKNOWN, + NOERROR, +}; +use interface::ilocalfilemanager::{ ILocalFileManager, ILocalFileManagerMethods, ILocalFileManagerVTable, RawILocalFileManager, IID_ILOCAL_FILE_MANAGER, }; -use com::{ - IID_IUnknown, IUnknownMethods, IUnknownVTable, RawIUnknown, E_NOINTERFACE, HRESULT, IID, - LPUNKNOWN, NOERROR, -}; /// The implementation class #[repr(C)] @@ -54,7 +54,7 @@ unsafe extern "stdcall" fn non_delegating_ilocalfilemanager_query_interface( let obj = this.sub(1) as *mut LocalFileManager; match *riid { - IID_IUnknown => { + IID_IUNKNOWN => { // Returns the nondelegating IUnknown, as in COM specification. *ppv = this as *mut c_void; } diff --git a/examples/basic/server/src/implementation/local_file_manager_class.rs b/examples/basic/server/src/local_file_manager_class.rs similarity index 86% rename from examples/basic/server/src/implementation/local_file_manager_class.rs rename to examples/basic/server/src/local_file_manager_class.rs index 6cd0144..4352bbf 100644 --- a/examples/basic/server/src/implementation/local_file_manager_class.rs +++ b/examples/basic/server/src/local_file_manager_class.rs @@ -1,10 +1,10 @@ use std::os::raw::c_void; -use crate::implementation::LocalFileManager; +use crate::LocalFileManager; use com::{ - IClassFactory, IClassFactoryMethods, IClassFactoryVTable, IID_IUnknown, IUnknownMethods, - RawIClassFactory, RawIUnknown, BOOL, E_INVALIDARG, E_NOINTERFACE, HRESULT, IID, - IID_ICLASS_FACTORY, NOERROR, S_OK, + IClassFactory, IClassFactoryMethods, IClassFactoryVTable, IUnknownMethods, RawIClassFactory, + RawIUnknown, BOOL, E_INVALIDARG, E_NOINTERFACE, HRESULT, IID, IID_ICLASS_FACTORY, IID_IUNKNOWN, + NOERROR, S_OK, }; #[repr(C)] @@ -25,7 +25,7 @@ unsafe extern "stdcall" fn query_interface( ppv: *mut *mut c_void, ) -> HRESULT { println!("Querying interface on LocalFileManagerClass..."); - if *riid == IID_IUnknown || *riid == IID_ICLASS_FACTORY { + if *riid == IID_IUNKNOWN || *riid == IID_ICLASS_FACTORY { *ppv = this as *mut c_void; (*this).raw_add_ref(); NOERROR @@ -57,13 +57,13 @@ unsafe extern "stdcall" fn release(this: *mut RawIUnknown) -> u32 { } unsafe extern "stdcall" fn create_instance( - this: *mut RawIClassFactory, + _this: *mut RawIClassFactory, aggregate: *mut RawIUnknown, riid: *const IID, ppv: *mut *mut c_void, ) -> HRESULT { println!("Creating instance..."); - if !aggregate.is_null() && *riid != IID_IUnknown { + if !aggregate.is_null() && *riid != IID_IUNKNOWN { *ppv = std::ptr::null_mut::(); return E_INVALIDARG; } @@ -85,7 +85,7 @@ unsafe extern "stdcall" fn create_instance( hr } -unsafe extern "stdcall" fn lock_server(increment: BOOL) -> HRESULT { +unsafe extern "stdcall" fn lock_server(_increment: BOOL) -> HRESULT { println!("LockServer called"); S_OK } diff --git a/examples/basic/server/src/implementation/mod.rs b/examples/basic/server/src/mod.rs similarity index 100% rename from examples/basic/server/src/implementation/mod.rs rename to examples/basic/server/src/mod.rs diff --git a/examples/basic/server/src/implementation/windows_file_manager.rs b/examples/basic/server/src/windows_file_manager.rs similarity index 85% rename from examples/basic/server/src/implementation/windows_file_manager.rs rename to examples/basic/server/src/windows_file_manager.rs index 136af6d..b80ace5 100644 --- a/examples/basic/server/src/implementation/windows_file_manager.rs +++ b/examples/basic/server/src/windows_file_manager.rs @@ -1,28 +1,27 @@ use std::os::raw::c_void; -use crate::interface::{ +use com::{ + failed, IUnknownMethods, RawIUnknown, E_NOINTERFACE, HRESULT, IID, IID_IUNKNOWN, NOERROR, +}; +use interface::{ ifilemanager::{ IFileManager, IFileManagerMethods, IFileManagerVTable, RawIFileManager, IID_IFILE_MANAGER, }, ilocalfilemanager::IID_ILOCAL_FILE_MANAGER, }; -use com::{ - failed, IID_IUnknown, IUnknownMethods, RawIUnknown, E_NOINTERFACE, HRESULT, IID, LPUNKNOWN, - NOERROR, -}; /// The implementation class #[repr(C)] pub struct WindowsFileManager { inner_one: IFileManager, ref_count: u32, - pub pUnkLocalFileManager: *mut RawIUnknown, + pub p_unk_local_file_manager: *mut RawIUnknown, } impl Drop for WindowsFileManager { fn drop(&mut self) { unsafe { - (*self.pUnkLocalFileManager).raw_release(); + (*self.p_unk_local_file_manager).raw_release(); Box::from_raw(self.inner_one.inner.vtable as *mut IFileManagerVTable) }; } @@ -36,11 +35,11 @@ unsafe extern "stdcall" fn ifilemanager_query_interface( let obj = this as *mut WindowsFileManager; match *riid { - IID_IUnknown | IID_IFILE_MANAGER => { + IID_IUNKNOWN | IID_IFILE_MANAGER => { *ppv = this as *mut c_void; } IID_ILOCAL_FILE_MANAGER => { - let hr = (*((*obj).pUnkLocalFileManager)).raw_query_interface(riid, ppv); + let hr = (*((*obj).p_unk_local_file_manager)).raw_query_interface(riid, ppv); if failed(hr) { return E_NOINTERFACE; } @@ -48,7 +47,7 @@ unsafe extern "stdcall" fn ifilemanager_query_interface( // We release it as the previous call add_ref-ed the inner object. // The intention is to transfer reference counting logic to the // outer object. - (*((*obj).pUnkLocalFileManager)).raw_release(); + (*((*obj).p_unk_local_file_manager)).raw_release(); } _ => { return E_NOINTERFACE; @@ -113,7 +112,7 @@ impl WindowsFileManager { inner: ifilemanager_inner, }, ref_count: 0, - pUnkLocalFileManager: std::ptr::null_mut::(), + p_unk_local_file_manager: std::ptr::null_mut::(), }; out diff --git a/examples/basic/server/src/implementation/windows_file_manager_class.rs b/examples/basic/server/src/windows_file_manager_class.rs similarity index 83% rename from examples/basic/server/src/implementation/windows_file_manager_class.rs rename to examples/basic/server/src/windows_file_manager_class.rs index ab8c74f..e80374d 100644 --- a/examples/basic/server/src/implementation/windows_file_manager_class.rs +++ b/examples/basic/server/src/windows_file_manager_class.rs @@ -1,13 +1,13 @@ use std::os::raw::c_void; -use crate::implementation::WindowsFileManager; -use crate::CLSID_LOCAL_FILE_MANAGER_CLASS; +use crate::WindowsFileManager; use com::{ failed, CoCreateInstance, IClassFactory, IClassFactoryMethods, IClassFactoryVTable, - IID_IUnknown, IUnknownMethods, RawIClassFactory, RawIUnknown, BOOL, CLASS_E_NOAGGREGATION, - CLSCTX_INPROC_SERVER, E_NOINTERFACE, HRESULT, IID, IID_ICLASS_FACTORY, LPVOID, NOERROR, - REFCLSID, REFIID, S_OK, + IUnknownMethods, RawIClassFactory, RawIUnknown, BOOL, CLASS_E_NOAGGREGATION, + CLSCTX_INPROC_SERVER, E_NOINTERFACE, HRESULT, IID, IID_ICLASS_FACTORY, IID_IUNKNOWN, LPVOID, + NOERROR, REFCLSID, REFIID, S_OK, }; +use interface::CLSID_LOCAL_FILE_MANAGER_CLASS; #[repr(C)] pub struct WindowsFileManagerClass { @@ -27,7 +27,7 @@ unsafe extern "stdcall" fn query_interface( ppv: *mut *mut c_void, ) -> HRESULT { println!("Querying interface on CatClass..."); - if *riid == IID_IUnknown || *riid == IID_ICLASS_FACTORY { + if *riid == IID_IUNKNOWN || *riid == IID_ICLASS_FACTORY { *ppv = this as *mut c_void; (*this).raw_add_ref(); NOERROR @@ -59,7 +59,7 @@ unsafe extern "stdcall" fn release(this: *mut RawIUnknown) -> u32 { } unsafe extern "stdcall" fn create_instance( - this: *mut RawIClassFactory, + _this: *mut RawIClassFactory, aggregate: *mut RawIUnknown, riid: *const IID, ppv: *mut *mut c_void, @@ -72,19 +72,19 @@ unsafe extern "stdcall" fn create_instance( let wfm = Box::into_raw(Box::new(WindowsFileManager::new())); // Instantiate object to aggregate - let mut pUnkLocalFileManager = std::ptr::null_mut::(); + let mut unknown_file_manager = std::ptr::null_mut::(); let hr = CoCreateInstance( &CLSID_LOCAL_FILE_MANAGER_CLASS as REFCLSID, wfm as *mut RawIUnknown, CLSCTX_INPROC_SERVER, - &IID_IUnknown as REFIID, - &mut pUnkLocalFileManager as *mut LPVOID, + &IID_IUNKNOWN as REFIID, + &mut unknown_file_manager as *mut LPVOID, ); if failed(hr) { println!("Failed to instantiate aggregate! Error: {:x}", hr as u32); panic!(); } - (*wfm).pUnkLocalFileManager = pUnkLocalFileManager as *mut RawIUnknown; + (*wfm).p_unk_local_file_manager = unknown_file_manager as *mut RawIUnknown; // Start reference count only after aggregation (*(wfm as *mut RawIUnknown)).raw_add_ref(); @@ -93,7 +93,7 @@ unsafe extern "stdcall" fn create_instance( hr } -unsafe extern "stdcall" fn lock_server(increment: BOOL) -> HRESULT { +unsafe extern "stdcall" fn lock_server(_increment: BOOL) -> HRESULT { println!("LockServer called"); S_OK } diff --git a/src/iunknown.rs b/src/iunknown.rs index bdc8e05..a83a71a 100644 --- a/src/iunknown.rs +++ b/src/iunknown.rs @@ -1,7 +1,7 @@ use crate::{c_void, comptr::ComPtr, failed, ComInterface, E_NOINTERFACE, HRESULT, IID}; #[allow(non_upper_case_globals)] -pub const IID_IUnknown: IID = IID { +pub const IID_IUNKNOWN: IID = IID { data1: 0u32, data2: 0u16, data3: 0u16, @@ -61,5 +61,5 @@ impl IUnknown { } unsafe impl ComInterface for IUnknown { - const IID: IID = IID_IUnknown; + const IID: IID = IID_IUNKNOWN; } diff --git a/src/lib.rs b/src/lib.rs index 7eb08d1..376c6e9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ mod iunknown; pub use iclassfactory::{ IClassFactory, IClassFactoryMethods, IClassFactoryVTable, RawIClassFactory, IID_ICLASS_FACTORY, }; -pub use iunknown::{IID_IUnknown, IUnknown, IUnknownMethods, IUnknownVTable, RawIUnknown}; +pub use iunknown::{IID_IUNKNOWN, IUnknown, IUnknownMethods, IUnknownVTable, RawIUnknown}; pub use comptr::ComPtr; use std::os::raw::c_void;