sap_scripting/
lib.rs

1//! SAP Scripting for Rust
2//!
3//! See the examples for how to use this library.
4
5use windows::Win32::System::Com::*;
6
7pub use com_shim::IsA;
8
9/// The types from this library.
10pub mod types;
11
12pub use types::*;
13
14/// A result of a call.
15pub type Result<T> = ::windows::core::Result<T>;
16
17/// An instance of a COM session. This should be kept whilst a connection to SAP is used.
18pub struct SAPComInstance;
19
20impl SAPComInstance {
21    /// Initialise the COM environment.
22    pub fn new() -> Result<Self> {
23        tracing::debug!("CoInitialize'ing.");
24        unsafe {
25            CoInitialize(None)?;
26        }
27        Ok(SAPComInstance)
28    }
29
30    /// Create an instance of the SAP wrapper
31    pub fn sap_wrapper(&self) -> Result<SAPWrapper> {
32        tracing::debug!("New CSapROTWrapper object generating.");
33        SAPWrapper::new()
34    }
35}
36
37impl Drop for SAPComInstance {
38    fn drop(&mut self) {
39        unsafe {
40            CoUninitialize();
41        }
42    }
43}