I want to write a small library in another language (LabVIEW, LV) to work with HID USB devices because I can't find an existing LV library for it. I think rather than working with the low level Windows API function calls in LV I want to write a nice API in rust and create a DLL from it, then call the DLL functions in LV.
The functions I'll need are:
- List serial numbers of connected devices with a passed in VID (vendor ID), PID (product ID), and Manufacture string
- Connect by VID, PID, and serial number string
- Write
- Read
- Close
I plan to use the hidapi crate.
I've started following the Nomicon from https://doc.rust-lang.org/nomicon/ffi.html#calling-rust-code-from-c
I'm probably going to have several questions.
My first question is how do I take a string as input to rust function? I think I understand how strings in C end with a \0 NUL character and how arrays of other types are pointers with a separate length value. But what is the right way to pass in a string to a DLL and the syntax for rust? Note: I vaguly remember trying this before and LV may have not worked nicely with the C string way of using NUL.