icube_sdk_sys/
lib.rs

1#![doc = include_str!("../README.md")]
2#![cfg(target_os = "windows")]
3
4pub mod ffi {
5    #![allow(non_upper_case_globals)]
6    #![allow(non_camel_case_types)]
7    #![allow(non_snake_case)]
8
9    include!(concat!(env!("OUT_DIR"), "/NET_ICube_API.h.rs"));
10}
11
12/// Convert a string literal to a C string.
13///
14/// # Examples
15/// ```
16/// # use icube_sdk_sys::to_c_str;
17/// to_c_str!(name = "ICubeSDK64");
18///
19/// let name: String = "Hello".into();
20/// to_c_str!(name);
21///
22/// let name: String = "Hello".into();
23/// to_c_str!(renamed_name = name);
24#[macro_export]
25macro_rules! to_c_str {
26    ($name:ident = $e:expr) => {
27        let tmp = std::ffi::CString::new($e).unwrap();
28        let $name = tmp.as_ptr();
29    };
30    ($name:ident) => {
31        $crate::to_c_str!($name = $name);
32    };
33    ($($name:ident $(= $e:expr)?),*) => {
34        $($crate::to_c_str!( $name $(= $e)? );)*
35    };
36}
37
38pub unsafe fn load() -> i32 {
39    #[cfg(target_arch = "x86_64")]
40    {
41        to_c_str!(name = "ICubeSDK64");
42        ffi::LoadICubeApi(name)
43    }
44    #[cfg(target_arch = "x86")]
45    {
46        to_c_str!(name = "ICubeSDK");
47        ffi::LoadICubeApi(name)
48    }
49}
50
51pub unsafe fn unload() {
52    ffi::UnloadICubeApi();
53}