mirror of
git://sigrok.org/libserialport
synced 2023-08-10 21:13:24 +03:00
Handle conversion of unicode names to char * on Windows.
This commit is contained in:
parent
d54e90047b
commit
8b532d9c1e
17
serialport.c
17
serialport.c
@ -100,6 +100,8 @@ struct sp_port **sp_list_ports(void)
|
|||||||
DWORD max_value_len, max_data_size, max_data_len;
|
DWORD max_value_len, max_data_size, max_data_len;
|
||||||
DWORD value_len, data_size, data_len;
|
DWORD value_len, data_size, data_len;
|
||||||
DWORD type, index = 0;
|
DWORD type, index = 0;
|
||||||
|
char *name;
|
||||||
|
int name_len;
|
||||||
|
|
||||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("HARDWARE\\DEVICEMAP\\SERIALCOMM"),
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("HARDWARE\\DEVICEMAP\\SERIALCOMM"),
|
||||||
0, KEY_QUERY_VALUE, &key) != ERROR_SUCCESS)
|
0, KEY_QUERY_VALUE, &key) != ERROR_SUCCESS)
|
||||||
@ -120,9 +122,20 @@ struct sp_port **sp_list_ports(void)
|
|||||||
{
|
{
|
||||||
data_len = data_size / sizeof(TCHAR);
|
data_len = data_size / sizeof(TCHAR);
|
||||||
data[data_len] = '\0';
|
data[data_len] = '\0';
|
||||||
|
#ifdef UNICODE
|
||||||
|
name_len = WideCharToMultiByte(CP_ACP, 0, data, -1, NULL, 0, NULL, NULL)
|
||||||
|
#else
|
||||||
|
name_len = data_len + 1;
|
||||||
|
#endif
|
||||||
|
if (!(name = malloc(name_len)))
|
||||||
|
goto out;
|
||||||
|
#ifdef UNICODE
|
||||||
|
WideCharToMultiByte(CP_ACP, 0, data, -1, name, name_len, NULL, NULL);
|
||||||
|
#else
|
||||||
|
strcpy(name, data);
|
||||||
|
#endif
|
||||||
if (type == REG_SZ)
|
if (type == REG_SZ)
|
||||||
if (!(list = sp_list_append(list,
|
if (!(list = sp_list_append(list, name, name_len)))
|
||||||
data, (data_len + 1) * sizeof(TCHAR))))
|
|
||||||
goto out;
|
goto out;
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user