Skip to content

Commit

Permalink
Fix build break with new winapi version
Browse files Browse the repository at this point in the history
While we're at it, fix some new warnings.
  • Loading branch information
jmgao committed Feb 21, 2024
1 parent 17abaec commit 21ccd30
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
14 changes: 7 additions & 7 deletions dhc/src/input/hid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ impl HidPreparsedData {
}

fn get_caps(&self) -> Result<HIDP_CAPS, HidPError> {
let mut caps = unsafe { MaybeUninit::uninit().assume_init() };
let rc = unsafe { HidP_GetCaps(self.raw(), &mut caps) };
let mut caps = MaybeUninit::<HIDP_CAPS>::uninit();
let rc = unsafe { HidP_GetCaps(self.raw(), caps.as_mut_ptr()) };
let result = hidp_result(rc);
result.and(Ok(caps))
result.and(Ok(unsafe { caps.assume_init() }))
}

fn get_value_caps(&self) -> Result<Vec<HIDP_VALUE_CAPS>, HidPError> {
Expand Down Expand Up @@ -374,7 +374,7 @@ fn get_rawinput_device_info_impl(device_id: RawInputDeviceId, cmd: UINT) -> Vec<
};

let mut result = vec![0; size as usize];
let ptr = result.as_mut_ptr() as *mut std::ffi::c_void;
let ptr = result.as_mut_ptr() as *mut winapi::ctypes::c_void;
let mut dummy = size as u32;
let rc = unsafe { GetRawInputDeviceInfoA(device_id.as_handle(), cmd, ptr, &mut dummy) };
assert!(size >= rc as usize);
Expand Down Expand Up @@ -406,7 +406,7 @@ fn hid_get_product_string(handle: HANDLE) -> Option<String> {
let mut buf: Vec<u16> = vec![0; 512];
let buf_size = buf.len() * std::mem::size_of::<u16>();

let ptr = buf.as_mut_ptr() as *mut std::ffi::c_void;
let ptr = buf.as_mut_ptr() as *mut winapi::ctypes::c_void;
let result = unsafe { HidD_GetProductString(handle, ptr, buf_size as u32) };
if result == 0 {
error!("HidD_GetProductString failed");
Expand All @@ -425,7 +425,7 @@ fn hid_get_manufacturer_string(handle: HANDLE) -> Option<String> {
let mut buf: Vec<u16> = vec![0; 512];
let buf_size = buf.len() * std::mem::size_of::<u16>();

let ptr = buf.as_mut_ptr() as *mut std::ffi::c_void;
let ptr = buf.as_mut_ptr() as *mut winapi::ctypes::c_void;
let result = unsafe { HidD_GetManufacturerString(handle, ptr, buf_size as u32) };
if result == 0 {
error!("HidD_GetManufacturerString failed");
Expand All @@ -444,7 +444,7 @@ fn hid_get_serial_number(handle: HANDLE) -> Option<String> {
let mut buf: Vec<u8> = vec![0; 512];
let buf_size = buf.len() * std::mem::size_of::<u8>();

let ptr = buf.as_mut_ptr() as *mut std::ffi::c_void;
let ptr = buf.as_mut_ptr() as *mut winapi::ctypes::c_void;
let result = unsafe { HidD_GetSerialNumberString(handle, ptr, buf_size as u32) };
if result == 0 {
error!("HidD_GetSerialNumberString failed");
Expand Down
5 changes: 3 additions & 2 deletions dhc/src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ impl RawInputManager {

fn handle_device_input(&mut self, _hwnd: HWND, hrawinput: HRAWINPUT) {
// TODO: Switch to GetRawInputBuffer?
let mut buffer = unsafe { MaybeUninit::uninit().assume_init() };
let mut buffer = MaybeUninit::<AlignedBuffer>::uninit();
let mut size = std::mem::size_of_val(&buffer) as u32;
let result = unsafe {
GetRawInputData(
hrawinput,
RID_INPUT,
&mut buffer as *mut AlignedBuffer as *mut std::ffi::c_void,
buffer.as_mut_ptr() as *mut winapi::ctypes::c_void,
&mut size,
std::mem::size_of::<RAWINPUTHEADER>() as UINT,
)
Expand All @@ -260,6 +260,7 @@ impl RawInputManager {
return;
}

let buffer = unsafe { buffer.assume_init() };
let rawinput = unsafe { *(&buffer as *const AlignedBuffer as *const RAWINPUT) };
let device_id = RawInputDeviceId::from_handle(rawinput.header.hDevice);
let device = self.devices.get_mut(&device_id);
Expand Down
4 changes: 2 additions & 2 deletions dhc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ lazy_static! {
.expect("failed to open or create configuration file")
.clone()
};
static ref CONTEXT: Context = { Context::new(CONFIG.device_count, CONFIG.mode == config::EmulationMode::XInput) };
static ref CONTEXT: Context = Context::new(CONFIG.device_count, CONFIG.mode == config::EmulationMode::XInput);
}

fn get_executable_path() -> String {
Expand Down Expand Up @@ -198,7 +198,7 @@ impl State {
ref mut real_devices,
} = *self;

for mut vdev in virtual_devices.iter_mut() {
for vdev in virtual_devices.iter_mut() {
if let Some(rdev_id) = vdev.binding {
let real_device_idx = find_real_device(&real_devices, rdev_id).unwrap();
let rdev = &mut real_devices[real_device_idx];
Expand Down

0 comments on commit 21ccd30

Please sign in to comment.