outlook_mapi_sys/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT license.
3
4//! This crate implements unsafe Rust bindings for the
5//! [Outlook MAPI](https://learn.microsoft.com/en-us/office/client-developer/outlook/mapi/outlook-mapi-reference)
6//! COM APIs using the [Windows](https://github.com/microsoft/windows-rs) crate.
7
8use windows::Win32::{Foundation::*, System::LibraryLoader::*};
9
10#[cfg(feature = "olmapi32")]
11mod load_mapi;
12
13fn get_mapi_module() -> HMODULE {
14    use std::sync::OnceLock;
15    use windows_core::*;
16
17    static MAPI_MODULE: OnceLock<usize> = OnceLock::new();
18    HMODULE(*MAPI_MODULE.get_or_init(|| unsafe {
19        #[cfg(feature = "olmapi32")]
20        if let Ok(module) = load_mapi::ensure_olmapi32() {
21            return module.0 as usize;
22        }
23
24        LoadLibraryW(w!("mapi32"))
25            .expect("mapi32 should be loaded on demand")
26            .0 as usize
27    }) as *mut _)
28}
29
30#[cfg(feature = "olmapi32")]
31pub use load_mapi::ensure_olmapi32;
32
33#[macro_use]
34extern crate outlook_mapi_stub;
35
36#[allow(
37    non_snake_case,
38    non_upper_case_globals,
39    non_camel_case_types,
40    dead_code,
41    clippy::all
42)]
43pub mod Microsoft {
44    pub mod Office {
45        pub mod Outlook {
46            pub mod MAPI {
47                pub mod Win32 {
48                    mod windows_link {
49                        macro_rules! link_mapi {
50                            ($library:literal $abi:literal fn $($function:tt)*) => (
51                                #[delay_load(name = $library)]
52                                extern $abi {
53                                    pub fn $($function)*;
54                                }
55                            )
56                        }
57
58                        pub(crate) use link_mapi as link;
59                    }
60
61                    include!("bindings.rs");
62                }
63            }
64        }
65    }
66}