How to display this cstring?

How to display a c string? I am trying to display this data but not sure how to do this. Any suggestions appreciated

This is a method to read a USB HID device and get the Product String, Serial String, Manufacturer string etc.

Create a method to call the method HIDUart_Getstring which returns an integer:

dim d as integer = HID2UART.GetString((0, 4292, 60032, m, 5)) // get the HID_UART_GET_MANUFACTURER_STR

[code]

'Description: This function returns a null-terminated vendor ID string, product ID string, serial string, device path
’ string, manufacturer string, or product string for the device specified by an index passed in
’ deviceNum. The index for the first device is 0 and the last device is the value returned by
’ HidUart_GetNumDevices() – 1.

'Prototype: STATUS HidUart_GetString (DWORD deviceNum, WORD vid, WORD pid, char* deviceString, DWORD options)

'Parameters: 1. deviceNum—Index of the device for which the string is desired.
’ 2. vid—Filter device results by vendor ID. If both vid and pid are set to 0x0000, then HID devices
’ will not be filtered by VID/PID.
’ 3. pid—Filter device results by product ID. If both vid and pid are set to 0x0000, then HID devices
’ will not be filtered by VID/PID.
’ 4. deviceString—Variable of type DEVICE_STRING which will contain a NULL
’ terminated ASCII device string on return. The string is 260 bytes on Windows and 512 bytes
’ on Mac OS X and Linux.
’ 5. OPTIONS—Determines if deviceString contains a vendor ID string, product ID string, serial
’ string, device path string, manufacturer string, or product string.
’ Definition Value Length Description
’ HID_UART_GET_VID_STR 0x01 5 Vendor ID
’ HID_UART_GET_PID_STR 0x02 5 Product ID
’ HID_UART_GET_PATH_STR 0x03 260/512 Device path
’ HID_UART_GET_SERIAL_STR 0x04 256 Serial string
’ HID_UART_GET_MANUFACTURER_STR 0x05 256 Manufacturer string
’ HID_UART_GET_PRODUCT_STR 0x06 256 Product string

'Return Value: HID_UART_STATUS = HID_UART_SUCCESS
’ HID_UART_DEVICE_NOT_FOUND
’ HID_UART_INVALID_PARAMETER
’ HID_UART_DEVICE_ACCESS_ERROR

dim m as new MemoryBlock(256) ’ mac = 512 pc= 256
Soft Declare Function HidUart_GetString Lib kLib (deviceNum as integer, vid as integer, pid as Integer, m as ptr, options as integer) as integer

dim result as integer = HidUart_GetString(deviceNum, vid, pid, m, options)
deviceString = m.CString(0)

////////////////////////////////////////////////////
window1.textfield1.text = cstr(m.CString(0)) /// <<<<<<<<<<<<<<<<<< trying to get the HID_UART_GET_MANUFACTURER_STR 0x05

return result[/code]

and does the code you posted NOT work?
since the LR specifically says

window1.textfield1.text = m.CString(0)

Ok Honestly am not sure it is not working. I am not getting any response from the string, it is empty. But I wanted to make sure I was using this correctly to view a valid response. Since it appears it should work, this leads me bigger issues of a error coming back from the method after reviewing the return value.

HID_UART_DEVICE_ACCESS_ERROR 0x15

Why would you assume that specific value is a CString? It looks like it’s probably an integer to me.

Have you inspected DeviceString in the debugger?

Is the first character perhaps 05?

I am getting an error returned so maybe that is why the string is empty. The return value is an integer that indicates status of success or error numbers. I am getting 0x15 Device error. If you get success then there should be a string returned (pointer) for my request of 5 which is to request the manufacturer string which by default is not empty. It ultimately will be written with my own value so that on connection to my app the app will confirm that it finds a certain product string else shut down “no device found”. This is an attempt at slowing down having someone take the app and try to build their own USB device.

dim d as integer = HID2UART.GetString((0, 4292, 60032, m, 5)) // get the HID_UART_GET_MANUFACTURER_STR

M is the pointer to the cstring that should contain data. 5 defines which string to return. D will contain the status value i.e. Success, error etc

Whats the prototype for this function (from vendor docs, C header files etc) ?
I’m assuming its something like
HID_UART_STATUS HidUart_GetString (DWORD deviceNum, WORD vid, WORD pid, char* deviceString, DWORD options)

You should not need to use CSTR()
But make sure the byte buffer is the right size so null terminators can be set into it (otherwise who knows)

And PID probably cant be hard coded

Does not match

WORD is an Int16, not an Integer.