@@ -97,7 +97,7 @@ device spec. Writing data (`hid_write`) at random to your HID devices can break
97
97
98
98
``` c
99
99
#include < stdio.h> // printf
100
- #include < wchar.h> // wprintf
100
+ #include < wchar.h> // wchar_t
101
101
102
102
#include < hidapi.h>
103
103
@@ -117,22 +117,28 @@ int main(int argc, char* argv[])
117
117
// Open the device using the VID, PID,
118
118
// and optionally the Serial number.
119
119
handle = hid_open(0x4d8, 0x3f, NULL);
120
+ if (!handle) {
121
+ printf("Unable to open device\n");
122
+
123
+ hid_exit()
124
+ return 1;
125
+ }
120
126
121
127
// Read the Manufacturer String
122
128
res = hid_get_manufacturer_string(handle, wstr, MAX_STR);
123
- wprintf(L "Manufacturer String: %s \n", wstr);
129
+ printf( "Manufacturer String: %ls \n", wstr);
124
130
125
131
// Read the Product String
126
132
res = hid_get_product_string(handle, wstr, MAX_STR);
127
- wprintf(L "Product String: %s \n", wstr);
133
+ printf( "Product String: %ls \n", wstr);
128
134
129
135
// Read the Serial Number String
130
136
res = hid_get_serial_number_string(handle, wstr, MAX_STR);
131
- wprintf(L "Serial Number String: (%d) %s \n", wstr[0], wstr);
137
+ printf( "Serial Number String: (%d) %ls \n", wstr[0], wstr);
132
138
133
139
// Read Indexed String 1
134
140
res = hid_get_indexed_string(handle, 1, wstr, MAX_STR);
135
- wprintf(L "Indexed String 1: %s \n", wstr);
141
+ printf( "Indexed String 1: %ls \n", wstr);
136
142
137
143
// Toggle LED (cmd 0x80). The first byte is the report number (0x0).
138
144
buf[0] = 0x0;
0 commit comments