diff --git a/src/bin/commonutilities.dll b/src/bin/commonutilities.dll deleted file mode 100644 index d612e21..0000000 Binary files a/src/bin/commonutilities.dll and /dev/null differ diff --git a/src/bin/open.dll b/src/bin/open.dll deleted file mode 100644 index 9151c50..0000000 Binary files a/src/bin/open.dll and /dev/null differ diff --git a/src/bin/simutilities.dll b/src/bin/simutilities.dll deleted file mode 100644 index 17f9d49..0000000 Binary files a/src/bin/simutilities.dll and /dev/null differ diff --git a/src/bin/svccoacommlib.dll b/src/bin/svccoacommlib.dll deleted file mode 100644 index e02085e..0000000 Binary files a/src/bin/svccoacommlib.dll and /dev/null differ diff --git a/src/bin/xerces-c_3_2.dll b/src/bin/xerces-c_3_2.dll deleted file mode 100644 index 3bb3434..0000000 Binary files a/src/bin/xerces-c_3_2.dll and /dev/null differ diff --git a/src/bin/zlib1.dll b/src/bin/zlib1.dll deleted file mode 100644 index 9d0ffea..0000000 Binary files a/src/bin/zlib1.dll and /dev/null differ diff --git a/src/lib.rs b/src/lib.rs index b8c68e1..946b69f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ #![allow(non_snake_case)] -use libloading::{Library, Symbol}; -use std::path::{Path, PathBuf}; +use libloading::{ Library, Symbol }; +use std::path::{ Path, PathBuf }; /// Pointer to a UTF-16 string (wide char) terminated with `0`. pub type PCWSTR = *const u16; @@ -256,15 +256,21 @@ type DisconnectFn = unsafe extern "C" fn() -> OpenReturnCodes; type OpenProjectFn = unsafe extern "C" fn(PCWSTR) -> OpenReturnCodes; type CreateProjectFn = unsafe extern "C" fn(PCWSTR, PCWSTR) -> OpenReturnCodes; type CreateProjectWithScalingFn = unsafe extern "C" fn(PCWSTR, PCWSTR, PCWSTR) -> OpenReturnCodes; -type CreateProjectWithScalingNcuNumberFn = - unsafe extern "C" fn(PCWSTR, PCWSTR, PCWSTR, u32) -> OpenReturnCodes; +type CreateProjectWithScalingNcuNumberFn = unsafe extern "C" fn( + PCWSTR, + PCWSTR, + PCWSTR, + u32 +) -> OpenReturnCodes; type SaveProjectFn = unsafe extern "C" fn() -> OpenReturnCodes; type CloseProjectFn = unsafe extern "C" fn() -> OpenReturnCodes; type BootControllerFn = unsafe extern "C" fn() -> OpenReturnCodes; type ShutdownControllerFn = unsafe extern "C" fn() -> OpenReturnCodes; type ResetControllerFn = unsafe extern "C" fn() -> OpenReturnCodes; -type RegisterForEventsFn = - unsafe extern "C" fn(u32, *const OpenEventMaskDefinition) -> OpenReturnCodes; +type RegisterForEventsFn = unsafe extern "C" fn( + u32, + *const OpenEventMaskDefinition +) -> OpenReturnCodes; type UnregisterEventsFn = unsafe extern "C" fn() -> OpenReturnCodes; type WaitForEventsFn = unsafe extern "C" fn() -> OpenReturnCodes; type ContinueSimulationFn = unsafe extern "C" fn() -> OpenReturnCodes; @@ -416,15 +422,7 @@ impl OpenApi { /// relative to the current working directory is used. pub unsafe fn load>(path: P) -> Result { // Load the DLL - let provided_path = path.as_ref(); - let fallback_path; - let dll_path = if provided_path.as_os_str().is_empty() { - fallback_path = PathBuf::from("bin").join("open.dll"); - fallback_path.as_path() - } else { - provided_path - }; - let lib = unsafe { Library::new(dll_path)? }; + let lib = unsafe { Library::new(path.as_ref())? }; // Extend the library's lifetime to 'static by leaking it. // (Alternatively: design OpenApi with lifetimes and avoid leaking.) let lib: &'static Library = Box::leak(Box::new(lib)); @@ -435,13 +433,15 @@ impl OpenApi { let disconnect = load_symbol::(lib, b"disconnect")?; let open_project = load_symbol::(lib, b"openProject")?; let create_project = load_symbol::(lib, b"createProject")?; - let create_project_with_scaling = - load_symbol::(lib, b"createProjectWithScaling")?; - let create_project_with_scaling_ncu_number = load_symbol::< - CreateProjectWithScalingNcuNumberFn, - >( - lib, b"createProjectWithScalingNCUNumber" + let create_project_with_scaling = load_symbol::( + lib, + b"createProjectWithScaling" )?; + let create_project_with_scaling_ncu_number = + load_symbol::( + lib, + b"createProjectWithScalingNCUNumber" + )?; let save_project = load_symbol::(lib, b"saveProject")?; let close_project = load_symbol::(lib, b"closeProject")?; let boot_controller = load_symbol::(lib, b"bootController")?; @@ -454,36 +454,62 @@ impl OpenApi { let get_dictionary_id = load_symbol::(lib, b"getDictionaryId")?; let register_watch = load_symbol::(lib, b"registerWatch")?; let unregister_watch = load_symbol::(lib, b"unregisterWatch")?; - let get_dictionary_element_type = - load_symbol::(lib, b"getDictionaryElementType")?; - let read_unsigned_integer_64_bit_array = - load_symbol::(lib, b"readUnsignedInteger64BitArray")?; - let read_signed_integer_32_bit_array = - load_symbol::(lib, b"readSignedInteger32BitArray")?; - let read_unsigned_integer_32_bit_array = - load_symbol::(lib, b"readUnsignedInteger32BitArray")?; - let read_unsigned_integer_16_bit_array = - load_symbol::(lib, b"readUnsignedInteger16BitArray")?; - let read_unsigned_integer_8_bit_array = - load_symbol::(lib, b"readUnsignedInteger8BitArray")?; + let get_dictionary_element_type = load_symbol::( + lib, + b"getDictionaryElementType" + )?; + let read_unsigned_integer_64_bit_array = load_symbol::( + lib, + b"readUnsignedInteger64BitArray" + )?; + let read_signed_integer_32_bit_array = load_symbol::( + lib, + b"readSignedInteger32BitArray" + )?; + let read_unsigned_integer_32_bit_array = load_symbol::( + lib, + b"readUnsignedInteger32BitArray" + )?; + let read_unsigned_integer_16_bit_array = load_symbol::( + lib, + b"readUnsignedInteger16BitArray" + )?; + let read_unsigned_integer_8_bit_array = load_symbol::( + lib, + b"readUnsignedInteger8BitArray" + )?; let read_bool_array = load_symbol::(lib, b"readBoolArray")?; let read_double_array = load_symbol::(lib, b"readDoubleArray")?; let read_string = load_symbol::(lib, b"readString")?; let read_string_array = load_symbol::(lib, b"readStringArray")?; - let read_unsigned_integer_16_bit = - load_symbol::(lib, b"readUnsignedInteger16Bit")?; - let read_signed_integer_16_bit = - load_symbol::(lib, b"readSignedInteger16Bit")?; - let read_unsigned_integer_32_bit = - load_symbol::(lib, b"readUnsignedInteger32Bit")?; - let read_signed_integer_32_bit = - load_symbol::(lib, b"readSignedInteger32Bit")?; - let read_unsigned_integer_64_bit = - load_symbol::(lib, b"readUnsignedInteger64Bit")?; - let read_signed_integer_64_bit = - load_symbol::(lib, b"readSignedInteger64Bit")?; - let get_num_array_elements = - load_symbol::(lib, b"getNumArrayElements")?; + let read_unsigned_integer_16_bit = load_symbol::( + lib, + b"readUnsignedInteger16Bit" + )?; + let read_signed_integer_16_bit = load_symbol::( + lib, + b"readSignedInteger16Bit" + )?; + let read_unsigned_integer_32_bit = load_symbol::( + lib, + b"readUnsignedInteger32Bit" + )?; + let read_signed_integer_32_bit = load_symbol::( + lib, + b"readSignedInteger32Bit" + )?; + let read_unsigned_integer_64_bit = load_symbol::( + lib, + b"readUnsignedInteger64Bit" + )?; + let read_signed_integer_64_bit = load_symbol::( + lib, + b"readSignedInteger64Bit" + )?; + let get_num_array_elements = load_symbol::( + lib, + b"getNumArrayElements" + )?; let read_bit = load_symbol::(lib, b"readBit")?; let read_bool = load_symbol::(lib, b"readBool")?; let read_byte = load_symbol::(lib, b"readByte")?; @@ -492,8 +518,10 @@ impl OpenApi { let read_double_word = load_symbol::(lib, b"readDoubleWord")?; let read_long_word = load_symbol::(lib, b"readLongWord")?; let read_next_event = load_symbol::(lib, b"readNextEvent")?; - let read_next_event_with_ncu_index = - load_symbol::(lib, b"readNextEventWithNcuIndex")?; + let read_next_event_with_ncu_index = load_symbol::( + lib, + b"readNextEventWithNcuIndex" + )?; let write_bit = load_symbol::(lib, b"writeBit")?; let write_bool = load_symbol::(lib, b"writeBool")?; let write_byte = load_symbol::(lib, b"writeByte")?; @@ -513,20 +541,34 @@ impl OpenApi { let delete_directory = load_symbol::(lib, b"deleteDirectory")?; let create_directory = load_symbol::(lib, b"createDirectory")?; let list_directory = load_symbol::(lib, b"listDirectory")?; - let get_version_information = - load_symbol::(lib, b"getVersionInformation")?; - let get_project_information = - load_symbol::(lib, b"getProjectInformation")?; - let get_current_project_information = - load_symbol::(lib, b"getCurrentProjectInformation")?; - let get_current_project_state = - load_symbol::(lib, b"getCurrentProjectState")?; - let import_project_settings = - load_symbol::(lib, b"importProjectSettings")?; - let export_project_settings = - load_symbol::(lib, b"exportProjectSettings")?; - let write_unsigned_integer_8_bit_array = - load_symbol::(lib, b"writeUnsignedInteger8BitArray")?; + let get_version_information = load_symbol::( + lib, + b"getVersionInformation" + )?; + let get_project_information = load_symbol::( + lib, + b"getProjectInformation" + )?; + let get_current_project_information = load_symbol::( + lib, + b"getCurrentProjectInformation" + )?; + let get_current_project_state = load_symbol::( + lib, + b"getCurrentProjectState" + )?; + let import_project_settings = load_symbol::( + lib, + b"importProjectSettings" + )?; + let export_project_settings = load_symbol::( + lib, + b"exportProjectSettings" + )?; + let write_unsigned_integer_8_bit_array = load_symbol::( + lib, + b"writeUnsignedInteger8BitArray" + )?; let get_number_of_ncus = load_symbol::(lib, b"getNumberOfNCUs")?; Ok(Self { @@ -635,7 +677,7 @@ impl OpenApi { pub unsafe fn create_project( &self, str_file_name: PCWSTR, - str_version: PCWSTR, + str_version: PCWSTR ) -> OpenReturnCodes { unsafe { (self.create_project)(str_file_name, str_version) } } @@ -645,7 +687,7 @@ impl OpenApi { &self, str_file_name: PCWSTR, str_version: PCWSTR, - str_nck_scaling: PCWSTR, + str_nck_scaling: PCWSTR ) -> OpenReturnCodes { unsafe { (self.create_project_with_scaling)(str_file_name, str_version, str_nck_scaling) } } @@ -656,14 +698,14 @@ impl OpenApi { str_file_name: PCWSTR, str_version: PCWSTR, str_nck_scaling: PCWSTR, - ncu_number: u32, + ncu_number: u32 ) -> OpenReturnCodes { unsafe { (self.create_project_with_scaling_ncu_number)( str_file_name, str_version, str_nck_scaling, - ncu_number, + ncu_number ) } } @@ -697,7 +739,7 @@ impl OpenApi { pub unsafe fn register_for_events( &self, event_list_length: u32, - event_list: *const OpenEventMaskDefinition, + event_list: *const OpenEventMaskDefinition ) -> OpenReturnCodes { unsafe { (self.register_for_events)(event_list_length, event_list) } } @@ -721,7 +763,7 @@ impl OpenApi { pub unsafe fn get_dictionary_id( &self, dictionary_element: PCWSTR, - dictionary_id: *mut u32, + dictionary_id: *mut u32 ) -> OpenReturnCodes { unsafe { (self.get_dictionary_id)(dictionary_element, dictionary_id) } } @@ -730,7 +772,7 @@ impl OpenApi { pub unsafe fn register_watch( &self, watch_list_length: u32, - dictionary_id_list: *const u32, + dictionary_id_list: *const u32 ) -> OpenReturnCodes { unsafe { (self.register_watch)(watch_list_length, dictionary_id_list) } } @@ -744,7 +786,7 @@ impl OpenApi { pub unsafe fn get_dictionary_element_type( &self, dictionary_id: u32, - value: *mut u8, + value: *mut u8 ) -> OpenReturnCodes { unsafe { (self.get_dictionary_element_type)(dictionary_id, value) } } @@ -754,13 +796,13 @@ impl OpenApi { &self, dictionary_id: u32, value_list_max_length: u32, - value_list: *mut u64, + value_list: *mut u64 ) -> OpenReturnCodes { unsafe { (self.read_unsigned_integer_64_bit_array)( dictionary_id, value_list_max_length, - value_list, + value_list ) } } @@ -770,13 +812,13 @@ impl OpenApi { &self, dictionary_id: u32, value_list_max_length: u32, - value_list: *mut i32, + value_list: *mut i32 ) -> OpenReturnCodes { unsafe { (self.read_signed_integer_32_bit_array)( dictionary_id, value_list_max_length, - value_list, + value_list ) } } @@ -786,13 +828,13 @@ impl OpenApi { &self, dictionary_id: u32, value_list_max_length: u32, - value_list: *mut u32, + value_list: *mut u32 ) -> OpenReturnCodes { unsafe { (self.read_unsigned_integer_32_bit_array)( dictionary_id, value_list_max_length, - value_list, + value_list ) } } @@ -802,13 +844,13 @@ impl OpenApi { &self, dictionary_id: u32, value_list_max_length: u32, - value_list: *mut u16, + value_list: *mut u16 ) -> OpenReturnCodes { unsafe { (self.read_unsigned_integer_16_bit_array)( dictionary_id, value_list_max_length, - value_list, + value_list ) } } @@ -818,13 +860,13 @@ impl OpenApi { &self, dictionary_id: u32, value_list_max_length: u32, - value_list: *mut u8, + value_list: *mut u8 ) -> OpenReturnCodes { unsafe { (self.read_unsigned_integer_8_bit_array)( dictionary_id, value_list_max_length, - value_list, + value_list ) } } @@ -834,7 +876,7 @@ impl OpenApi { &self, dictionary_id: u32, value_list_max_length: u32, - value_list: *mut bool, + value_list: *mut bool ) -> OpenReturnCodes { unsafe { (self.read_bool_array)(dictionary_id, value_list_max_length, value_list) } } @@ -844,7 +886,7 @@ impl OpenApi { &self, dictionary_id: u32, value_list_max_length: u32, - value_list: *mut f64, + value_list: *mut f64 ) -> OpenReturnCodes { unsafe { (self.read_double_array)(dictionary_id, value_list_max_length, value_list) } } @@ -854,7 +896,7 @@ impl OpenApi { &self, dictionary_id: u32, string_max_length: u32, - string_buffer: PWSTR, + string_buffer: PWSTR ) -> OpenReturnCodes { unsafe { (self.read_string)(dictionary_id, string_max_length, string_buffer) } } @@ -865,14 +907,14 @@ impl OpenApi { dictionary_id: u32, string_array_max_length: u32, string_max_length: u32, - string_array: PPWSTR, + string_array: PPWSTR ) -> OpenReturnCodes { unsafe { (self.read_string_array)( dictionary_id, string_array_max_length, string_max_length, - string_array, + string_array ) } } @@ -881,7 +923,7 @@ impl OpenApi { pub unsafe fn read_unsigned_integer_16_bit( &self, dictionary_id: u32, - value: *mut u16, + value: *mut u16 ) -> OpenReturnCodes { unsafe { (self.read_unsigned_integer_16_bit)(dictionary_id, value) } } @@ -890,7 +932,7 @@ impl OpenApi { pub unsafe fn read_signed_integer_16_bit( &self, dictionary_id: u32, - value: *mut i16, + value: *mut i16 ) -> OpenReturnCodes { unsafe { (self.read_signed_integer_16_bit)(dictionary_id, value) } } @@ -899,7 +941,7 @@ impl OpenApi { pub unsafe fn read_unsigned_integer_32_bit( &self, dictionary_id: u32, - value: *mut u32, + value: *mut u32 ) -> OpenReturnCodes { unsafe { (self.read_unsigned_integer_32_bit)(dictionary_id, value) } } @@ -908,7 +950,7 @@ impl OpenApi { pub unsafe fn read_signed_integer_32_bit( &self, dictionary_id: u32, - value: *mut i32, + value: *mut i32 ) -> OpenReturnCodes { unsafe { (self.read_signed_integer_32_bit)(dictionary_id, value) } } @@ -917,7 +959,7 @@ impl OpenApi { pub unsafe fn read_unsigned_integer_64_bit( &self, dictionary_id: u32, - value: *mut u64, + value: *mut u64 ) -> OpenReturnCodes { unsafe { (self.read_unsigned_integer_64_bit)(dictionary_id, value) } } @@ -926,7 +968,7 @@ impl OpenApi { pub unsafe fn read_signed_integer_64_bit( &self, dictionary_id: u32, - value: *mut i64, + value: *mut i64 ) -> OpenReturnCodes { unsafe { (self.read_signed_integer_64_bit)(dictionary_id, value) } } @@ -935,7 +977,7 @@ impl OpenApi { pub unsafe fn get_num_array_elements( &self, dictionary_id: u32, - num_array_elements: *mut u32, + num_array_elements: *mut u32 ) -> OpenReturnCodes { unsafe { (self.get_num_array_elements)(dictionary_id, num_array_elements) } } @@ -984,7 +1026,7 @@ impl OpenApi { pub unsafe fn read_next_event_with_ncu_index( &self, event: *mut u64, - ncu_index: *mut i32, + ncu_index: *mut i32 ) -> OpenReturnCodes { unsafe { (self.read_next_event_with_ncu_index)(event, ncu_index) } } @@ -1029,7 +1071,7 @@ impl OpenApi { &self, dictionary_id: u32, value_list_length: u32, - value_list: *const bool, + value_list: *const bool ) -> OpenReturnCodes { unsafe { (self.write_bool_array)(dictionary_id, value_list_length, value_list) } } @@ -1048,7 +1090,7 @@ impl OpenApi { pub unsafe fn get_card_path( &self, card_path_max_length: u32, - card_path: PWSTR, + card_path: PWSTR ) -> OpenReturnCodes { unsafe { (self.get_card_path)(card_path_max_length, card_path) } } @@ -1058,14 +1100,10 @@ impl OpenApi { &self, card_paths_array_max_length: u32, card_path_max_length: u32, - card_paths: PPWSTR, + card_paths: PPWSTR ) -> OpenReturnCodes { unsafe { - (self.get_card_paths)( - card_paths_array_max_length, - card_path_max_length, - card_paths, - ) + (self.get_card_paths)(card_paths_array_max_length, card_path_max_length, card_paths) } } @@ -1073,7 +1111,7 @@ impl OpenApi { pub unsafe fn get_file( &self, source_file_path: PCWSTR, - destination_file_path: PCWSTR, + destination_file_path: PCWSTR ) -> OpenReturnCodes { unsafe { (self.get_file)(source_file_path, destination_file_path) } } @@ -1082,7 +1120,7 @@ impl OpenApi { pub unsafe fn put_file( &self, source_file_path: PCWSTR, - destination_file_path: PCWSTR, + destination_file_path: PCWSTR ) -> OpenReturnCodes { unsafe { (self.put_file)(source_file_path, destination_file_path) } } @@ -1091,7 +1129,7 @@ impl OpenApi { pub unsafe fn select_file( &self, source_file_path: PCWSTR, - channel_name: PCWSTR, + channel_name: PCWSTR ) -> OpenReturnCodes { unsafe { (self.select_file)(source_file_path, channel_name) } } @@ -1115,7 +1153,7 @@ impl OpenApi { pub unsafe fn list_directory( &self, directory_path: PCWSTR, - result_file_path: PCWSTR, + result_file_path: PCWSTR ) -> OpenReturnCodes { unsafe { (self.list_directory)(directory_path, result_file_path) } } @@ -1129,7 +1167,7 @@ impl OpenApi { pub unsafe fn get_project_information( &self, vcp_file_path: PCWSTR, - destination_file_path: PCWSTR, + destination_file_path: PCWSTR ) -> OpenReturnCodes { unsafe { (self.get_project_information)(vcp_file_path, destination_file_path) } } @@ -1137,7 +1175,7 @@ impl OpenApi { #[inline] pub unsafe fn get_current_project_information( &self, - destination_file_path: PCWSTR, + destination_file_path: PCWSTR ) -> OpenReturnCodes { unsafe { (self.get_current_project_information)(destination_file_path) } } @@ -1145,7 +1183,7 @@ impl OpenApi { #[inline] pub unsafe fn get_current_project_state( &self, - project_state: *mut OpenProjectStates, + project_state: *mut OpenProjectStates ) -> OpenReturnCodes { unsafe { (self.get_current_project_state)(project_state) } } @@ -1154,7 +1192,7 @@ impl OpenApi { pub unsafe fn import_project_settings( &self, file_name: PCWSTR, - import_content_file_name: PCWSTR, + import_content_file_name: PCWSTR ) -> OpenReturnCodes { unsafe { (self.import_project_settings)(file_name, import_content_file_name) } } @@ -1169,13 +1207,13 @@ impl OpenApi { &self, dictionary_id: u32, value_list_max_length: u32, - value_list: *const u8, + value_list: *const u8 ) -> OpenReturnCodes { unsafe { (self.write_unsigned_integer_8_bit_array)( dictionary_id, value_list_max_length, - value_list, + value_list ) } }