Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Address PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
rylev committed Feb 17, 2020
1 parent 61d67dd commit 4ffbe21
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 24 deletions.
4 changes: 2 additions & 2 deletions examples/aggregation/server/src/local_file_manager.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use interface::ilocal_file_manager::ILocalFileManager;

use com::co_class;
use com::sys::HRESULT;
use com::sys::{HRESULT, NOERROR};

/// The implementation class
#[co_class(implements(ILocalFileManager), aggregatable)]
Expand All @@ -12,7 +12,7 @@ pub struct LocalFileManager {
impl ILocalFileManager for LocalFileManager {
unsafe fn delete_local(&self) -> HRESULT {
println!("Deleting Locally...");
0
NOERROR
}
}

Expand Down
4 changes: 2 additions & 2 deletions examples/aggregation/server/src/windows_file_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use interface::{
};

use com::co_class;
use com::sys::HRESULT;
use com::sys::{HRESULT, NOERROR};

/// The implementation class
#[co_class(implements(IFileManager), aggregates(ILocalFileManager))]
Expand All @@ -17,7 +17,7 @@ pub struct WindowsFileManager {
impl IFileManager for WindowsFileManager {
unsafe fn delete_all(&self) -> HRESULT {
println!("Deleting all by delegating to Local and Remote File Managers...");
0
NOERROR
}
}

Expand Down
8 changes: 4 additions & 4 deletions examples/basic/server/src/british_short_hair_cat.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use interface::{ianimal::IAnimal, icat::ICat, idomesticanimal::IDomesticAnimal};

use com::co_class;
use com::sys::HRESULT;
use com::sys::{HRESULT, NOERROR};

/// The implementation class
/// https://en.wikipedia.org/wiki/British_Shorthair
Expand All @@ -13,21 +13,21 @@ pub struct BritishShortHairCat {
impl IDomesticAnimal for BritishShortHairCat {
unsafe fn train(&self) -> HRESULT {
println!("Training...");
0
NOERROR
}
}

impl ICat for BritishShortHairCat {
unsafe fn ignore_humans(&self) -> HRESULT {
println!("Ignoring Humans...");
0
NOERROR
}
}

impl IAnimal for BritishShortHairCat {
unsafe fn eat(&self) -> HRESULT {
println!("Eating...");
0
NOERROR
}
}

Expand Down
2 changes: 1 addition & 1 deletion macros/support/src/aggr_co_class/iunknown_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use syn::ItemStruct;
pub fn generate(struct_item: &ItemStruct) -> HelperTokenStream {
let struct_ident = &struct_item.ident;
let iunknown_to_use_field_ident = crate::utils::iunknown_to_use_field_ident();
let ptr_casting = quote! { as *mut std::ffi::c_void };
let ptr_casting = quote! { as *mut _ };

quote!(
impl com::interfaces::iunknown::IUnknown for #struct_ident {
Expand Down
2 changes: 1 addition & 1 deletion macros/support/src/co_class/com_struct_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub fn gen_set_aggregate_fns(aggr_map: &HashMap<Ident, Vec<Ident>>) -> HelperTok
let set_aggregate_fn_ident = crate::utils::set_aggregate_fn_ident(&base);
fns.push(quote!(
fn #set_aggregate_fn_ident(&mut self, aggr: com::InterfacePtr<dyn com::interfaces::iunknown::IUnknown>) {
// TODO: What happens if we are overwriting an existing aggregate?
// FaTODO: What happens if we are overwriting an existing aggregate?
self.#aggr_field_ident = aggr.as_raw() as *mut *const <dyn com::interfaces::iunknown::IUnknown as com::ComInterface>::VTable;
}
));
Expand Down
4 changes: 2 additions & 2 deletions macros/support/src/co_class/iunknown_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn gen_aggregate_drops(aggr_map: &HashMap<Ident, Vec<Ident>>) -> HelperTokenStre
let aggregate_drops = aggr_map.iter().map(|(aggr_field_ident, _)| {
quote!(
if !self.#aggr_field_ident.is_null() {
let mut aggr_interface_ptr = com::InterfacePtr::<dyn com::interfaces::iunknown::IUnknown>::new(self.#aggr_field_ident as *mut std::ffi::c_void);
let mut aggr_interface_ptr = com::InterfacePtr::<dyn com::interfaces::iunknown::IUnknown>::new(self.#aggr_field_ident as *mut _);
aggr_interface_ptr.release();
}
)
Expand Down Expand Up @@ -208,7 +208,7 @@ pub fn gen_aggregate_match_arms(aggr_map: &HashMap<Ident, Vec<Ident>>) -> Helper
return com::sys::E_NOINTERFACE;
}

let mut aggr_interface_ptr = com::InterfacePtr::<dyn com::interfaces::iunknown::IUnknown>::new(self.#aggr_field_ident as *mut std::ffi::c_void);
let mut aggr_interface_ptr = com::InterfacePtr::<dyn com::interfaces::iunknown::IUnknown>::new(self.#aggr_field_ident as *mut _);
let hr = aggr_interface_ptr.query_interface(riid, ppv);
if com::sys::FAILED(hr) {
*ppv = std::ptr::null_mut::<std::ffi::c_void>();
Expand Down
13 changes: 8 additions & 5 deletions src/inproc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::interfaces::iunknown::IUnknown;
use crate::sys::{
GetModuleFileNameA, GetModuleHandleA, RegCloseKey, RegCreateKeyExA, RegDeleteKeyA,
RegSetValueExA, ERROR_SUCCESS, HRESULT, IID, SELFREG_E_CLASS, S_OK,
RegSetValueExA, ERROR_SUCCESS, HRESULT, IID, LSTATUS, SELFREG_E_CLASS, S_OK,
};

use std::convert::TryInto;
Expand Down Expand Up @@ -50,7 +50,7 @@ pub fn unregister_keys(registry_keys_to_remove: Vec<RegistryKeyInfo>) -> HRESULT
const HKEY_CLASSES_ROOT: *mut c_void = 0x8000_0000 as *mut c_void;
const KEY_ALL_ACCESS: u32 = 0x000F_003F;
const REG_OPTION_NON_VOLATILE: u32 = 0x00000000;
fn create_class_key(key_info: &RegistryKeyInfo) -> Result<*mut c_void, i32> {
fn create_class_key(key_info: &RegistryKeyInfo) -> Result<*mut c_void, LSTATUS> {
let hk_result = std::ptr::null_mut::<c_void>();
let lp_class = std::ptr::null_mut::<u8>();
let lp_security_attributes = std::ptr::null_mut::<c_void>();
Expand All @@ -76,7 +76,10 @@ fn create_class_key(key_info: &RegistryKeyInfo) -> Result<*mut c_void, i32> {
}

const REG_SZ: u32 = 1;
fn set_class_key(key_handle: *mut c_void, key_info: &RegistryKeyInfo) -> Result<*mut c_void, i32> {
fn set_class_key(
key_handle: *mut c_void,
key_info: &RegistryKeyInfo,
) -> Result<*mut c_void, LSTATUS> {
let result = unsafe {
RegSetValueExA(
key_handle,
Expand All @@ -99,7 +102,7 @@ fn set_class_key(key_handle: *mut c_void, key_info: &RegistryKeyInfo) -> Result<
Ok(key_handle)
}

fn add_class_key(key_info: &RegistryKeyInfo) -> i32 {
fn add_class_key(key_info: &RegistryKeyInfo) -> LSTATUS {
let key_handle = match create_class_key(key_info) {
Ok(key_handle) => key_handle,
Err(e) => {
Expand All @@ -117,7 +120,7 @@ fn add_class_key(key_info: &RegistryKeyInfo) -> i32 {
unsafe { RegCloseKey(key_handle) }
}

fn remove_class_key(key_info: &RegistryKeyInfo) -> i32 {
fn remove_class_key(key_info: &RegistryKeyInfo) -> LSTATUS {
unsafe { RegDeleteKeyA(HKEY_CLASSES_ROOT, key_info.key_path.as_ptr()) }
}

Expand Down
4 changes: 2 additions & 2 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ impl ApartmentThreadedRuntime {
clsid: &IID,
outer: &mut U,
) -> Result<InterfacePtr<T>, HRESULT> {
unsafe { self.create_raw_instance::<T>(clsid, outer as *mut U as *mut *const c_void) }
unsafe { self.create_raw_instance::<T>(clsid, outer as *mut U as *mut c_void) }
}

pub unsafe fn create_raw_instance<T: ComInterface + ?Sized>(
&self,
clsid: &IID,
outer: *mut *const c_void,
outer: *mut c_void,
) -> Result<InterfacePtr<T>, HRESULT> {
let mut instance = std::ptr::null_mut::<c_void>();
let hr = CoCreateInstance(
Expand Down
11 changes: 6 additions & 5 deletions src/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub fn FAILED(result: HRESULT) -> bool {
result < 0
}
pub type BOOL = i32;
pub type LSTATUS = i32;

pub const S_OK: HRESULT = 0;
pub const NOERROR: HRESULT = 0;
Expand Down Expand Up @@ -41,18 +42,18 @@ extern "system" {
lpSecurityAttributes: *mut c_void,
phkResult: *mut *mut c_void,
lpdwDisposition: *mut u32,
) -> i32;
) -> LSTATUS;
pub fn GetModuleFileNameA(hModule: *mut c_void, lpFilename: *mut i8, nSize: u32) -> u32;
pub fn RegCloseKey(hKey: *mut c_void) -> i32;
pub fn RegCloseKey(hKey: *mut c_void) -> LSTATUS;
pub fn RegSetValueExA(
hKey: *mut c_void,
lpValueName: *const i8,
Reserved: u32,
dwType: u32,
lpData: *const u8,
cbData: u32,
) -> i32;
pub fn RegDeleteKeyA(hKey: *mut c_void, lpSubKey: *const i8) -> i32;
) -> LSTATUS;
pub fn RegDeleteKeyA(hKey: *mut c_void, lpSubKey: *const i8) -> LSTATUS;
pub fn GetModuleHandleA(lpModuleName: *const i8) -> *mut c_void;
pub fn CoInitializeEx(pvReserved: *mut c_void, dwCoInit: u32) -> HRESULT;
pub fn CoGetClassObject(
Expand All @@ -64,7 +65,7 @@ extern "system" {
) -> HRESULT;
pub fn CoCreateInstance(
rclsid: *const IID,
pUnkOuter: *mut *const c_void,
pUnkOuter: *mut c_void,
dwClsContext: u32,
riid: *const IID,
ppv: *mut *mut c_void,
Expand Down

0 comments on commit 4ffbe21

Please sign in to comment.