From 591f06d85e155b6a6876d46cf828637084a01183 Mon Sep 17 00:00:00 2001 From: Michael Stefaniuc Date: Tue, 24 Nov 2020 23:29:16 +0100 Subject: [PATCH] mmdevapi: Use wide-char string literals. Signed-off-by: Michael Stefaniuc Signed-off-by: Andrew Eikum Signed-off-by: Alexandre Julliard --- dlls/mmdevapi/devenum.c | 95 +++++++++++---------------------- dlls/mmdevapi/main.c | 18 ++----- dlls/mmdevapi/tests/mmdevenum.c | 6 +-- dlls/mmdevapi/tests/propstore.c | 13 ++--- 4 files changed, 40 insertions(+), 92 deletions(-) diff --git a/dlls/mmdevapi/devenum.c b/dlls/mmdevapi/devenum.c index 999ec2b0e78..9e4a29816ce 100644 --- a/dlls/mmdevapi/devenum.c +++ b/dlls/mmdevapi/devenum.c @@ -41,27 +41,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi); -static const WCHAR software_mmdevapi[] = - { 'S','o','f','t','w','a','r','e','\\', - 'M','i','c','r','o','s','o','f','t','\\', - 'W','i','n','d','o','w','s','\\', - 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', - 'M','M','D','e','v','i','c','e','s','\\', - 'A','u','d','i','o',0}; -static const WCHAR reg_render[] = - { 'R','e','n','d','e','r',0 }; -static const WCHAR reg_capture[] = - { 'C','a','p','t','u','r','e',0 }; -static const WCHAR reg_devicestate[] = - { 'D','e','v','i','c','e','S','t','a','t','e',0 }; -static const WCHAR reg_properties[] = - { 'P','r','o','p','e','r','t','i','e','s',0 }; -static const WCHAR slashW[] = {'\\',0}; -static const WCHAR reg_out_nameW[] = {'D','e','f','a','u','l','t','O','u','t','p','u','t',0}; -static const WCHAR reg_vout_nameW[] = {'D','e','f','a','u','l','t','V','o','i','c','e','O','u','t','p','u','t',0}; -static const WCHAR reg_in_nameW[] = {'D','e','f','a','u','l','t','I','n','p','u','t',0}; -static const WCHAR reg_vin_nameW[] = {'D','e','f','a','u','l','t','V','o','i','c','e','I','n','p','u','t',0}; - static HKEY key_render; static HKEY key_capture; @@ -128,11 +107,7 @@ static inline IPropertyBagImpl *impl_from_IPropertyBag(IPropertyBag *iface) return CONTAINING_RECORD(iface, IPropertyBagImpl, IPropertyBag_iface); } -static const WCHAR propkey_formatW[] = { - '{','%','0','8','X','-','%','0','4','X','-', - '%','0','4','X','-','%','0','2','X','%','0','2','X','-', - '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X', - '%','0','2','X','%','0','2','X','}',',','%','d',0 }; +static const WCHAR propkey_formatW[] = L"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X},%d"; static HRESULT MMDevPropStore_OpenPropKey(const GUID *guid, DWORD flow, HKEY *propkey) { @@ -145,11 +120,11 @@ static HRESULT MMDevPropStore_OpenPropKey(const GUID *guid, DWORD flow, HKEY *pr WARN("Opening key %s failed with %u\n", debugstr_w(buffer), ret); return E_FAIL; } - ret = RegOpenKeyExW(key, reg_properties, 0, KEY_READ|KEY_WRITE|KEY_WOW64_64KEY, propkey); + ret = RegOpenKeyExW(key, L"Properties", 0, KEY_READ|KEY_WRITE|KEY_WOW64_64KEY, propkey); RegCloseKey(key); if (ret != ERROR_SUCCESS) { - WARN("Opening key %s failed with %u\n", debugstr_w(reg_properties), ret); + WARN("Opening key Properties failed with %u\n", ret); return E_FAIL; } return S_OK; @@ -345,8 +320,8 @@ static MMDevice *MMDevice_Create(WCHAR *name, GUID *id, EDataFlow flow, DWORD st if (RegCreateKeyExW(root, guidstr, 0, NULL, 0, KEY_WRITE|KEY_READ|KEY_WOW64_64KEY, NULL, &key, NULL) == ERROR_SUCCESS) { HKEY keyprop; - RegSetValueExW(key, reg_devicestate, 0, REG_DWORD, (const BYTE*)&state, sizeof(DWORD)); - if (!RegCreateKeyExW(key, reg_properties, 0, NULL, 0, KEY_WRITE|KEY_READ|KEY_WOW64_64KEY, NULL, &keyprop, NULL)) + RegSetValueExW(key, L"DeviceState", 0, REG_DWORD, (const BYTE*)&state, sizeof(DWORD)); + if (!RegCreateKeyExW(key, L"Properties", 0, NULL, 0, KEY_WRITE|KEY_READ|KEY_WOW64_64KEY, NULL, &keyprop, NULL)) { PROPVARIANT pv; @@ -404,11 +379,13 @@ static HRESULT load_devices_from_reg(void) LONG ret; DWORD curflow; - ret = RegCreateKeyExW(HKEY_LOCAL_MACHINE, software_mmdevapi, 0, NULL, 0, KEY_WRITE|KEY_READ|KEY_WOW64_64KEY, NULL, &root, NULL); + ret = RegCreateKeyExW(HKEY_LOCAL_MACHINE, + L"Software\\Microsoft\\Windows\\CurrentVersion\\MMDevices\\Audio", 0, NULL, 0, + KEY_WRITE|KEY_READ|KEY_WOW64_64KEY, NULL, &root, NULL); if (ret == ERROR_SUCCESS) - ret = RegCreateKeyExW(root, reg_capture, 0, NULL, 0, KEY_READ|KEY_WRITE|KEY_WOW64_64KEY, NULL, &key_capture, NULL); + ret = RegCreateKeyExW(root, L"Capture", 0, NULL, 0, KEY_READ|KEY_WRITE|KEY_WOW64_64KEY, NULL, &key_capture, NULL); if (ret == ERROR_SUCCESS) - ret = RegCreateKeyExW(root, reg_render, 0, NULL, 0, KEY_READ|KEY_WRITE|KEY_WOW64_64KEY, NULL, &key_render, NULL); + ret = RegCreateKeyExW(root, L"Render", 0, NULL, 0, KEY_READ|KEY_WRITE|KEY_WOW64_64KEY, NULL, &key_render, NULL); RegCloseKey(root); cur = key_capture; curflow = eCapture; @@ -683,11 +660,6 @@ static HRESULT WINAPI MMDevice_GetId(IMMDevice *iface, WCHAR **itemid) MMDevice *This = impl_from_IMMDevice(iface); WCHAR *str; GUID *id = &This->devguid; - static const WCHAR formatW[] = { '{','0','.','0','.','%','u','.','0','0','0','0','0','0','0','0','}','.', - '{','%','0','8','X','-','%','0','4','X','-', - '%','0','4','X','-','%','0','2','X','%','0','2','X','-', - '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X', - '%','0','2','X','%','0','2','X','}',0 }; TRACE("(%p)->(%p)\n", This, itemid); if (!itemid) @@ -695,9 +667,10 @@ static HRESULT WINAPI MMDevice_GetId(IMMDevice *iface, WCHAR **itemid) *itemid = str = CoTaskMemAlloc(56 * sizeof(WCHAR)); if (!str) return E_OUTOFMEMORY; - wsprintfW( str, formatW, This->flow, id->Data1, id->Data2, id->Data3, - id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3], - id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] ); + wsprintfW(str, L"{0.0.%u.00000000}.{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}", + This->flow, id->Data1, id->Data2, id->Data3, + id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3], + id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7]); TRACE("returning %s\n", wine_dbgstr_w(str)); return S_OK; } @@ -986,7 +959,7 @@ static HRESULT WINAPI MMDevEnum_GetDefaultAudioEndpoint(IMMDeviceEnumerator *ifa return E_NOTFOUND; lstrcpyW(reg_key, drv_keyW); - lstrcatW(reg_key, slashW); + lstrcatW(reg_key, L"\\"); lstrcatW(reg_key, drvs.module_name); if(RegOpenKeyW(HKEY_CURRENT_USER, reg_key, &key) == ERROR_SUCCESS){ @@ -995,11 +968,11 @@ static HRESULT WINAPI MMDevEnum_GetDefaultAudioEndpoint(IMMDeviceEnumerator *ifa DWORD size = sizeof(def_id), state; if(flow == eRender){ - reg_x_name = reg_out_nameW; - reg_vx_name = reg_vout_nameW; + reg_x_name = L"DefaultOutput"; + reg_vx_name = L"DefaultVoiceOutput"; }else{ - reg_x_name = reg_in_nameW; - reg_vx_name = reg_vin_nameW; + reg_x_name = L"DefaultInput"; + reg_vx_name = L"DefaultVoiceInput"; } if(role == eCommunications && @@ -1051,15 +1024,12 @@ static HRESULT WINAPI MMDevEnum_GetDevice(IMMDeviceEnumerator *iface, const WCHA DWORD i=0; IMMDevice *dev = NULL; - static const WCHAR wine_info_deviceW[] = {'W','i','n','e',' ', - 'i','n','f','o',' ','d','e','v','i','c','e',0}; - TRACE("(%p)->(%s,%p)\n", This, debugstr_w(name), device); if(!name || !device) return E_POINTER; - if(!lstrcmpW(name, wine_info_deviceW)){ + if(!lstrcmpW(name, L"Wine info device")){ *device = &info_device; return S_OK; } @@ -1188,7 +1158,7 @@ static DWORD WINAPI notif_thread_proc(void *user) DWORD size; lstrcpyW(reg_key, drv_keyW); - lstrcatW(reg_key, slashW); + lstrcatW(reg_key, L"\\"); lstrcatW(reg_key, drvs.module_name); if(RegCreateKeyExW(HKEY_CURRENT_USER, reg_key, 0, NULL, 0, @@ -1198,23 +1168,19 @@ static DWORD WINAPI notif_thread_proc(void *user) } size = sizeof(out_name); - if(RegQueryValueExW(key, reg_out_nameW, 0, NULL, - (BYTE*)out_name, &size) != ERROR_SUCCESS) + if(RegQueryValueExW(key, L"DefaultOutput", 0, NULL, (BYTE*)out_name, &size) != ERROR_SUCCESS) out_name[0] = 0; size = sizeof(vout_name); - if(RegQueryValueExW(key, reg_vout_nameW, 0, NULL, - (BYTE*)vout_name, &size) != ERROR_SUCCESS) + if(RegQueryValueExW(key, L"DefaultVoiceOutput", 0, NULL, (BYTE*)vout_name, &size) != ERROR_SUCCESS) vout_name[0] = 0; size = sizeof(in_name); - if(RegQueryValueExW(key, reg_in_nameW, 0, NULL, - (BYTE*)in_name, &size) != ERROR_SUCCESS) + if(RegQueryValueExW(key, L"DefaultInput", 0, NULL, (BYTE*)in_name, &size) != ERROR_SUCCESS) in_name[0] = 0; size = sizeof(vin_name); - if(RegQueryValueExW(key, reg_vin_nameW, 0, NULL, - (BYTE*)vin_name, &size) != ERROR_SUCCESS) + if(RegQueryValueExW(key, L"DefaultVoiceInput", 0, NULL, (BYTE*)vin_name, &size) != ERROR_SUCCESS) vin_name[0] = 0; while(1){ @@ -1228,13 +1194,13 @@ static DWORD WINAPI notif_thread_proc(void *user) EnterCriticalSection(&g_notif_lock); - notify_if_changed(eRender, eConsole, key, reg_out_nameW, + notify_if_changed(eRender, eConsole, key, L"DefaultOutput", out_name, &MMDevice_def_play->IMMDevice_iface); - notify_if_changed(eRender, eCommunications, key, reg_vout_nameW, + notify_if_changed(eRender, eCommunications, key, L"DefaultVoiceOutput", vout_name, &MMDevice_def_play->IMMDevice_iface); - notify_if_changed(eCapture, eConsole, key, reg_in_nameW, + notify_if_changed(eCapture, eConsole, key, L"DefaultInput", in_name, &MMDevice_def_rec->IMMDevice_iface); - notify_if_changed(eCapture, eCommunications, key, reg_vin_nameW, + notify_if_changed(eCapture, eCommunications, key, L"DefaultVoiceInput", vin_name, &MMDevice_def_rec->IMMDevice_iface); LeaveCriticalSection(&g_notif_lock); @@ -1523,10 +1489,9 @@ static ULONG WINAPI PB_Release(IPropertyBag *iface) static HRESULT WINAPI PB_Read(IPropertyBag *iface, LPCOLESTR name, VARIANT *var, IErrorLog *log) { - static const WCHAR dsguid[] = { 'D','S','G','u','i','d', 0 }; IPropertyBagImpl *This = impl_from_IPropertyBag(iface); TRACE("Trying to read %s, type %u\n", debugstr_w(name), var->n1.n2.vt); - if (!lstrcmpW(name, dsguid)) + if (!lstrcmpW(name, L"DSGuid")) { WCHAR guidstr[39]; StringFromGUID2(&This->devguid, guidstr,ARRAY_SIZE(guidstr)); diff --git a/dlls/mmdevapi/main.c b/dlls/mmdevapi/main.c index 8e9127a7507..247ebc3b001 100644 --- a/dlls/mmdevapi/main.c +++ b/dlls/mmdevapi/main.c @@ -47,8 +47,7 @@ static HINSTANCE instance; DriverFuncs drvs; -const WCHAR drv_keyW[] = {'S','o','f','t','w','a','r','e','\\', - 'W','i','n','e','\\','D','r','i','v','e','r','s',0}; +const WCHAR drv_keyW[] = L"Software\\Wine\\Drivers"; static const char *get_priority_string(int prio) { @@ -68,12 +67,10 @@ static const char *get_priority_string(int prio) static BOOL load_driver(const WCHAR *name, DriverFuncs *driver) { WCHAR driver_module[264]; - static const WCHAR wineW[] = {'w','i','n','e',0}; - static const WCHAR dotdrvW[] = {'.','d','r','v',0}; - lstrcpyW(driver_module, wineW); + lstrcpyW(driver_module, L"wine"); lstrcatW(driver_module, name); - lstrcatW(driver_module, dotdrvW); + lstrcatW(driver_module, L".drv"); TRACE("Attempting to load %s\n", wine_dbgstr_w(driver_module)); @@ -106,11 +103,7 @@ static BOOL load_driver(const WCHAR *name, DriverFuncs *driver) static BOOL WINAPI init_driver(INIT_ONCE *once, void *param, void **context) { - static const WCHAR drv_value[] = {'A','u','d','i','o',0}; - - static WCHAR default_list[] = {'p','u','l','s','e',',','a','l','s','a',',','o','s','s',',', - 'c','o','r','e','a','u','d','i','o',',','a','n','d','r','o','i','d',0}; - + static WCHAR default_list[] = L"pulse,alsa,oss,coreaudio,android"; DriverFuncs driver; HKEY key; WCHAR reg_list[256], *p, *next, *driver_list = default_list; @@ -118,8 +111,7 @@ static BOOL WINAPI init_driver(INIT_ONCE *once, void *param, void **context) if(RegOpenKeyW(HKEY_CURRENT_USER, drv_keyW, &key) == ERROR_SUCCESS){ DWORD size = sizeof(reg_list); - if(RegQueryValueExW(key, drv_value, 0, NULL, (BYTE*)reg_list, - &size) == ERROR_SUCCESS){ + if(RegQueryValueExW(key, L"Audio", 0, NULL, (BYTE*)reg_list, &size) == ERROR_SUCCESS){ if(reg_list[0] == '\0'){ TRACE("User explicitly chose no driver\n"); RegCloseKey(key); diff --git a/dlls/mmdevapi/tests/mmdevenum.c b/dlls/mmdevapi/tests/mmdevenum.c index 4708c2fef84..350d6474a46 100644 --- a/dlls/mmdevapi/tests/mmdevenum.c +++ b/dlls/mmdevapi/tests/mmdevenum.c @@ -384,8 +384,6 @@ static IMMNotificationClient notif = { ¬if_vtbl }; /* Only do parameter tests here, the actual MMDevice testing should be a separate test */ START_TEST(mmdevenum) { - static const WCHAR not_a_deviceW[] = {'n','o','t','a','d','e','v','i','c','e',0}; - HRESULT hr; IUnknown *unk = NULL; IMMDeviceEnumerator *mme, *mme2; @@ -426,13 +424,13 @@ START_TEST(mmdevenum) ok(!unk, "Unk not reset to null after invalid QI\n"); ok(hr == E_NOINTERFACE, "Invalid hr %08x returned on IID_NULL\n", hr); - hr = IMMDeviceEnumerator_GetDevice(mme, not_a_deviceW, NULL); + hr = IMMDeviceEnumerator_GetDevice(mme, L"notadevice", NULL); ok(hr == E_POINTER, "GetDevice gave wrong error: %08x\n", hr); hr = IMMDeviceEnumerator_GetDevice(mme, NULL, &dev); ok(hr == E_POINTER, "GetDevice gave wrong error: %08x\n", hr); - hr = IMMDeviceEnumerator_GetDevice(mme, not_a_deviceW, &dev); + hr = IMMDeviceEnumerator_GetDevice(mme, L"notadevice", &dev); ok(hr == E_INVALIDARG, "GetDevice gave wrong error: %08x\n", hr); col = (void*)(LONG_PTR)0x12345678; diff --git a/dlls/mmdevapi/tests/propstore.c b/dlls/mmdevapi/tests/propstore.c index bdba19d158c..e5071e67e52 100644 --- a/dlls/mmdevapi/tests/propstore.c +++ b/dlls/mmdevapi/tests/propstore.c @@ -33,14 +33,7 @@ static BOOL (WINAPI *pIsWow64Process)(HANDLE, BOOL *); static const WCHAR software_renderW[] = - { 'S','o','f','t','w','a','r','e','\\', - 'M','i','c','r','o','s','o','f','t','\\', - 'W','i','n','d','o','w','s','\\', - 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', - 'M','M','D','e','v','i','c','e','s','\\', - 'A','u','d','i','o','\\', - 'R','e','n','d','e','r',0 }; -static const WCHAR propertiesW[] = {'P','r','o','p','e','r','t','i','e','s',0}; + L"Software\\Microsoft\\Windows\\CurrentVersion\\MMDevices\\Audio\\Render"; static void test_propertystore(IPropertyStore *store) @@ -138,7 +131,7 @@ static void test_setvalue_on_wow64(IPropertyStore *store) static const PROPERTYKEY PKEY_Bogus = { {0x1da5d803, 0xd492, 0x4edd, {0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x00}}, 0x7f }; - static const WCHAR bogusW[] = {'{','1','D','A','5','D','8','0','3','-','D','4','9','2','-','4','E','D','D','-','8','C','2','3','-','E','0','C','0','F','F','E','E','7','F','0','0','}',',','1','2','7',0}; + static const WCHAR bogusW[] = L"{1DA5D803-D492-4EDD-8C23-E0C0FFEE7F00},127"; PropVariantInit(&pv); @@ -172,7 +165,7 @@ static void test_setvalue_on_wow64(IPropertyStore *store) ret = RegOpenKeyExW(root, guidW, 0, KEY_READ|KEY_WOW64_64KEY, &devkey); ok(ret == ERROR_SUCCESS, "Couldn't open mmdevice guid key: %u\n", ret); - ret = RegOpenKeyExW(devkey, propertiesW, 0, KEY_READ|KEY_WOW64_64KEY, &props); + ret = RegOpenKeyExW(devkey, L"Properties", 0, KEY_READ|KEY_WOW64_64KEY, &props); ok(ret == ERROR_SUCCESS, "Couldn't open mmdevice property key: %u\n", ret); /* Note: the registry key exists even without calling IPropStore::Commit */