Cleanup mmdevice_common.c - use encoding/utf functions
This commit is contained in:
parent
46a65fb38c
commit
5fa4388a4c
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <encodings/utf.h>
|
||||||
#include <lists/string_list.h>
|
#include <lists/string_list.h>
|
||||||
|
|
||||||
#include "mmdevice_common.h"
|
#include "mmdevice_common.h"
|
||||||
|
@ -25,7 +26,6 @@ void *mmdevice_list_new(void *u)
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
UINT i;
|
UINT i;
|
||||||
PROPVARIANT prop_var;
|
PROPVARIANT prop_var;
|
||||||
int ir;
|
|
||||||
union string_list_elem_attr attr;
|
union string_list_elem_attr attr;
|
||||||
IMMDeviceEnumerator *enumerator = NULL;
|
IMMDeviceEnumerator *enumerator = NULL;
|
||||||
IMMDeviceCollection *collection = NULL;
|
IMMDeviceCollection *collection = NULL;
|
||||||
|
@ -33,7 +33,6 @@ void *mmdevice_list_new(void *u)
|
||||||
IMMDevice *device = NULL;
|
IMMDevice *device = NULL;
|
||||||
LPWSTR dev_id_wstr = NULL;
|
LPWSTR dev_id_wstr = NULL;
|
||||||
IPropertyStore *prop_store = NULL;
|
IPropertyStore *prop_store = NULL;
|
||||||
bool prop_var_init = false;
|
|
||||||
bool br = false;
|
bool br = false;
|
||||||
char *dev_id_str = NULL;
|
char *dev_id_str = NULL;
|
||||||
char *dev_name_str = NULL;
|
char *dev_name_str = NULL;
|
||||||
|
@ -72,18 +71,7 @@ void *mmdevice_list_new(void *u)
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
ir = WideCharToMultiByte(CP_ACP, 0, dev_id_wstr, -1,
|
if (!(dev_id_str = utf16_to_utf8_string_alloc(dev_id_wstr)))
|
||||||
NULL, 0, NULL, NULL);
|
|
||||||
if (!ir)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
dev_id_str = (char *)malloc(ir);
|
|
||||||
if (!dev_id_str)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
ir = WideCharToMultiByte(CP_ACP, 0, dev_id_wstr, -1,
|
|
||||||
dev_id_str, ir, NULL, NULL);
|
|
||||||
if (!ir)
|
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
hr = _IMMDevice_OpenPropertyStore(device, STGM_READ, &prop_store);
|
hr = _IMMDevice_OpenPropertyStore(device, STGM_READ, &prop_store);
|
||||||
|
@ -91,24 +79,12 @@ void *mmdevice_list_new(void *u)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
PropVariantInit(&prop_var);
|
PropVariantInit(&prop_var);
|
||||||
prop_var_init = true;
|
|
||||||
hr = _IPropertyStore_GetValue(prop_store, PKEY_Device_FriendlyName,
|
hr = _IPropertyStore_GetValue(prop_store, PKEY_Device_FriendlyName,
|
||||||
&prop_var);
|
&prop_var);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
ir = WideCharToMultiByte(CP_ACP, 0, prop_var.pwszVal, -1,
|
if (!(dev_name_str = utf16_to_utf8_string_alloc(prop_var.pwszVal)))
|
||||||
NULL, 0, NULL, NULL);
|
|
||||||
if (!ir)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
dev_name_str = (char *)malloc(ir);
|
|
||||||
if (!dev_name_str)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
ir = WideCharToMultiByte(CP_ACP, 0, prop_var.pwszVal, -1,
|
|
||||||
dev_name_str, ir, NULL, NULL);
|
|
||||||
if (!ir)
|
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
br = string_list_append(sl, dev_name_str, attr);
|
br = string_list_append(sl, dev_name_str, attr);
|
||||||
|
@ -116,7 +92,6 @@ void *mmdevice_list_new(void *u)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
PropVariantClear(&prop_var);
|
PropVariantClear(&prop_var);
|
||||||
prop_var_init = false;
|
|
||||||
if (dev_id_wstr)
|
if (dev_id_wstr)
|
||||||
CoTaskMemFree(dev_id_wstr);
|
CoTaskMemFree(dev_id_wstr);
|
||||||
if (dev_id_str)
|
if (dev_id_str)
|
||||||
|
|
Loading…
Reference in New Issue