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