com_rs/lib.rs
1// Copyright (c) 2016 com-rs developers
2//
3// Licensed under the Apache License, Version 2.0
4// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
5// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. All files in the project carrying such notice may not be copied,
7// modified, or distributed except according to those terms.
8
9/*!
10# com-rs 0.1.4
11Rust bindings for the Win32 [Component Object Model]
12(https://msdn.microsoft.com/en-us/library/ms680573.aspx).
13
14# Overview
15This crate is composed of three main components:
16
17* The [`com_interface!`] (macro.com_interface!.html) macro for
18 defining new interface types.
19* The [`ComPtr`](struct.ComPtr.html) type for making use of them.
20* Definition of [`IUnknown`](struct.IUnknown.html), the base COM interface.
21*/
22
23// TODO:
24// * Implement the rest of COM, this is just a tiny subset necessary to consume
25// IUnknown interfaces.
26// * Tests for IUnknown/ComPtr, hard to test with no way of acquiring
27// IUnknown objects directly.
28
29#![deny(dead_code)]
30#![deny(missing_debug_implementations)]
31#![deny(missing_docs)]
32
33use std::fmt;
34
35pub use comptr::{AsComPtr, ComInterface, ComPtr};
36pub use unknown::IUnknown;
37
38/// Interface identifier.
39#[derive(Clone, Copy, Debug, Eq, PartialEq)]
40#[repr(C)]
41pub struct IID {
42 /// First component, 32-bit value.
43 pub data1: u32,
44 /// Second component, 16-bit value.
45 pub data2: u16,
46 /// Third component, 16-bit value.
47 pub data3: u16,
48 /// Fourth component, array of 8-bit values.
49 pub data4: [u8; 8],
50}
51
52/// Print IID in Windows registry format {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}.
53impl fmt::Display for IID {
54 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
55 write!(f, "{{{:08X}-{:04X}-{:04X}-{:02X}{:02X}-\
56 {:02X}{:02X}{:02X}{:02X}{:02X}{:02X}}}",
57 self.data1, self.data2, self.data3,
58 self.data4[0], self.data4[1], self.data4[2], self.data4[3],
59 self.data4[4], self.data4[5], self.data4[6], self.data4[7])
60 }
61}
62
63#[test]
64fn iid_display() {
65 assert_eq!(IUnknown::iid().to_string(),
66 "{00000000-0000-0000-C000-000000000046}");
67}
68
69/// Result type.
70pub type HResult = i32;
71
72#[macro_use]
73mod macros;
74
75mod comptr;
76mod unknown;