this kinda works
This commit is contained in:
@@ -32,6 +32,7 @@ fn main() {
|
||||
.allowlist_function("SimConnect_Open")
|
||||
.allowlist_function("SimConnect_RemoveClientEvent")
|
||||
.allowlist_function("SimConnect_RequestDataOnSimObject")
|
||||
.allowlist_function("SimConnect_SetDataOnSimObject")
|
||||
.allowlist_function("SimConnect_RequestFacilitiesList")
|
||||
.allowlist_function("SimConnect_SetNotificationGroupPriority")
|
||||
.allowlist_function("SimConnect_SubscribeToFacilities")
|
||||
|
@@ -109,4 +109,47 @@ impl SimConnect {
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_data_on_sim_object<T>(&self, obj: &mut T) -> Result<(), SimConnectError> {
|
||||
let type_name: String = std::any::type_name::<T>().into();
|
||||
|
||||
let request_id = self
|
||||
.registered_objects
|
||||
.get(&type_name)
|
||||
.ok_or_else(|| SimConnectError::ObjectNotRegistered(type_name.clone()))?;
|
||||
|
||||
success!(unsafe {
|
||||
bindings::SimConnect_SetDataOnSimObject(
|
||||
self.handle.as_ptr(),
|
||||
request_id.id,
|
||||
bindings::SIMCONNECT_OBJECT_ID_USER,
|
||||
Condition::None.into(),
|
||||
0,
|
||||
size_of::<T>().try_into().unwrap(),
|
||||
obj as *mut _ as *mut std::ffi::c_void,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_data_on_sim_object_with_id<T>(
|
||||
&self,
|
||||
request_id: u32,
|
||||
obj: &mut T,
|
||||
) -> Result<(), SimConnectError> {
|
||||
// Strings require to be something specific, so until we can figure out how to
|
||||
// convert the strings "on-the-fly"
|
||||
// we'll use the packed variant of the struct, but it'll need a custom request_id
|
||||
|
||||
success!(unsafe {
|
||||
bindings::SimConnect_SetDataOnSimObject(
|
||||
self.handle.as_ptr(),
|
||||
request_id,
|
||||
bindings::SIMCONNECT_OBJECT_ID_USER,
|
||||
Condition::None.into(),
|
||||
0,
|
||||
size_of::<T>().try_into().unwrap(),
|
||||
obj as *mut _ as *mut std::ffi::c_void,
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user