зеркало из https://github.com/microsoft/com-rs.git
Breakout interface
This commit is contained in:
Родитель
a6f240b153
Коммит
c5dae5ebf3
|
@ -10,4 +10,5 @@ edition = "2018"
|
|||
members = [
|
||||
"examples/basic/client",
|
||||
"examples/basic/server",
|
||||
"examples/basic/interface",
|
||||
]
|
|
@ -6,4 +6,4 @@ edition = "2018"
|
|||
|
||||
[dependencies]
|
||||
com = { path = "../../.." }
|
||||
server = { path = "../server" }
|
||||
interface = { path = "../interface" }
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
/target
|
||||
**/*.rs.bk
|
||||
Cargo.lock
|
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "interface"
|
||||
version = "0.1.0"
|
||||
authors = ["Microsoft Corp"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
com = { path = "../../.." }
|
||||
|
||||
[lib]
|
||||
crate-type = ["rlib", "cdylib"]
|
|
@ -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<RawIUnknown> 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,
|
||||
}
|
|
@ -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<RawIAnimal> 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);
|
|
@ -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<RawIUnknown> for RawICatClass {
|
||||
|
@ -43,6 +43,7 @@ impl std::convert::AsMut<RawIUnknown> for RawICatClass {
|
|||
#[allow(non_snake_case)]
|
||||
#[repr(C)]
|
||||
pub struct ICatClassMethods {}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct ICatClassVTable(
|
||||
pub IUnknownMethods,
|
|
@ -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<RawIAnimal> 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,
|
|
@ -24,7 +24,7 @@ unsafe impl ComInterface for IExample {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub(crate) struct RawIExample {
|
||||
pub struct RawIExample {
|
||||
vtable: *const IExampleVTable,
|
||||
}
|
||||
|
|
@ -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<RawIUnknown> 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);
|
|
@ -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<RawIUnknown> 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);
|
|
@ -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],
|
||||
};
|
|
@ -6,6 +6,7 @@ edition = "2018"
|
|||
|
||||
[dependencies]
|
||||
com = { path = "../../.." }
|
||||
interface = { path = "../interface" }
|
||||
|
||||
[lib]
|
||||
crate-type = ["rlib", "cdylib"]
|
|
@ -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;
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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;
|
|
@ -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;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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::<c_void>();
|
||||
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
|
||||
}
|
|
@ -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::<RawIUnknown>(),
|
||||
p_unk_local_file_manager: std::ptr::null_mut::<RawIUnknown>(),
|
||||
};
|
||||
|
||||
out
|
|
@ -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::<c_void>();
|
||||
let mut unknown_file_manager = std::ptr::null_mut::<c_void>();
|
||||
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
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче