1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//! A helper crate for consuming and producing COM interfaces.
//!
//! # Example
//!
//! To work with a COM interface it must first be declared:
//!
//! ```rust,no_run
//! /// Define an IAnimal interface
//! com::interfaces! {
//!     #[uuid("EFF8970E-C50F-45E0-9284-291CE5A6F771")]
//!     pub unsafe interface IAnimal: com::interfaces::IUnknown {
//!         unsafe fn Eat(&self) -> com::sys::HRESULT;
//!     }
//! }
//! # fn main() {}
//! ```
//!
//! To define a COM implementation class:
//!
//! ```rust,no_run
//! # com::interfaces! {
//! #     #[uuid("EFF8970E-C50F-45E0-9284-291CE5A6F771")]
//! #     pub unsafe interface IAnimal: com::interfaces::IUnknown {
//! #         unsafe fn Eat(&self) -> com::sys::HRESULT;
//! #     }
//! # }
//! com::class! {
//!     pub class BritishShortHairCat: IAnimal {
//!         num_owners: u32,
//!     }
//!
//!     impl IAnimal for BritishShortHairCat {
//!         fn Eat(&self) -> com::sys::HRESULT {
//!             println!("Eating...");
//!             com::sys::NOERROR
//!         }
//!     }
//! }
//! # fn main() {}
//! ```
//!
//! See the examples directory in the repository for more examples.
//!

#![allow(clippy::transmute_ptr_to_ptr)]
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
#![deny(missing_docs)]

mod abi_transferable;
mod interface;
pub mod interfaces;
mod param;
#[doc(hidden)]
pub mod refcounting;
#[cfg(windows)]
pub mod runtime;
pub mod sys;

#[cfg(feature = "production")]
/// Functionality for producing COM classes
pub mod production;

#[doc(inline)]
pub use abi_transferable::AbiTransferable;
#[doc(inline)]
pub use interface::Interface;
#[doc(inline)]
pub use param::Param;
#[doc(inline)]
pub use sys::{CLSID, IID};

/// Declare COM interfaces
///
/// # Example
/// ```rust,no_run
/// /// Define an IAnimal interface
/// com::interfaces! {
///     #[uuid("EFF8970E-C50F-45E0-9284-291CE5A6F771")]
///     pub unsafe interface IAnimal: com::interfaces::IUnknown {
///         unsafe fn Eat(&self) -> com::sys::HRESULT;
///     }
/// }
/// # fn main() {}
/// ```
pub use com_macros::interfaces;

/// Declare COM implementation classes
///
/// # Example
/// ```rust,no_run
/// use com::sys::{HRESULT, NOERROR};
/// # com::interfaces! {
/// #     #[uuid("EFF8970E-C50F-45E0-9284-291CE5A6F771")]
/// #     pub unsafe interface IAnimal: com::interfaces::IUnknown {
/// #         unsafe fn Eat(&self) -> com::sys::HRESULT;
/// #     }
/// # }
///
/// com::class! {
///     pub class BritishShortHairCat: IAnimal {
///         num_owners: u32,
///     }
///
///     impl IAnimal for BritishShortHairCat {
///         fn Eat(&self) -> HRESULT {
///             println!("Eating...");
///             NOERROR
///         }
///     }
/// }
/// # fn main() {}
/// ```
#[cfg(feature = "production")]
pub use com_macros::class;

// this allows for the crate to refer to itself as `com` to keep macros consistent
// whether they are used by some other crate or internally
#[doc(hidden)]
extern crate self as com;

// We re-export `alloc` so that we can use `com::alloc::boxed::Box` in generated code,
// for code that uses `#![no_std]`.
#[doc(hidden)]
pub extern crate alloc;