[DllImport("SiUSBXp.dll", CharSet = CharSet.Auto, EntryPoint =
"SI_GetProductStringSafe")]
static extern SI_STATUS GetProductString(
int dwDeviceNum,
out IntPtr lvpDeviceString,
int deviceStringLenInBytes,
int dwFlags);
static void Main(string[] args)
{
uint test = GetProductString(0, out IntPtr desc, 100, 0);
Console.WriteLine($"Hello World! {Marshal.PtrToStringAuto(desc)}");
}
Gives me a System.AccessViolationException.
test
is 0, so the GetProductString call succeeded.
How do I get the string from lvpDeviceString
which is a void* in unmanaged code.?
Here is function declaration:
/// @brief Gets a Product String
/// @param dwDeviceNum TBD
/// @param lpvDeviceString points at a buffer into which the Product String will be copied and returned
/// @param DeviceStringLenInBytes the length in bytes of lpvDeviceString the buffer into which the Product String will be copied and returned
/// @param dwFlags is the indication of which Product String to return
/// @returns Returns SI_SUCCESS on success, another SI_STATUS if there is an error:
/// SI_DEVICE_IO_FAILED -- a driver-internal error occurred
_Check_return_
_Ret_range_(SI_SUCCESS, SI_DEVICE_NOT_FOUND)
_Success_(SI_SUCCESS)
SI_USB_XP_API
SI_STATUS WINAPI SI_GetProductStringSafe(
_In_ _Pre_defensive_ const DWORD dwDeviceNum,
_Out_writes_bytes_(DeviceStringLenInBytes) LPVOID lpvDeviceString,
_In_ _Pre_defensive_ const size_t DeviceStringLenInBytes,
_In_ _Pre_defensive_ const DWORD dwFlags
);
and here is some documentation: https://www.silabs.com/documents/public/application-notes/AN169.pdf