From fc4014454b299a203ee12f3e8d305c9d10ae2eff Mon Sep 17 00:00:00 2001 From: Francois Gouget Date: Sun, 10 Apr 2011 18:46:13 +0200 Subject: [PATCH] mmdevapi: Reorder a couple of functions to avoid forward declarations and make MMDevice_SetPropValue() static. --- dlls/mmdevapi/devenum.c | 266 +++++++++++++++++++-------------------- dlls/mmdevapi/mmdevapi.h | 1 - 2 files changed, 133 insertions(+), 134 deletions(-) diff --git a/dlls/mmdevapi/devenum.c b/dlls/mmdevapi/devenum.c index 35c6a785168..3a61baa4d0a 100644 --- a/dlls/mmdevapi/devenum.c +++ b/dlls/mmdevapi/devenum.c @@ -130,6 +130,139 @@ 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 HRESULT MMDevPropStore_OpenPropKey(const GUID *guid, DWORD flow, HKEY *propkey) +{ + WCHAR buffer[39]; + LONG ret; + HKEY key; + StringFromGUID2(guid, buffer, 39); + if ((ret = RegOpenKeyExW(flow == eRender ? key_render : key_capture, buffer, 0, KEY_READ|KEY_WRITE, &key)) != ERROR_SUCCESS) + { + 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, propkey); + RegCloseKey(key); + if (ret != ERROR_SUCCESS) + { + WARN("Opening key %s failed with %u\n", debugstr_w(reg_properties), ret); + return E_FAIL; + } + return S_OK; +} + +HRESULT MMDevice_GetPropValue(const GUID *devguid, DWORD flow, REFPROPERTYKEY key, PROPVARIANT *pv) +{ + WCHAR buffer[80]; + const GUID *id = &key->fmtid; + DWORD type, size; + HRESULT hr = S_OK; + HKEY regkey; + LONG ret; + + hr = MMDevPropStore_OpenPropKey(devguid, flow, ®key); + if (FAILED(hr)) + return hr; + wsprintfW( buffer, propkey_formatW, 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], key->pid ); + ret = RegGetValueW(regkey, NULL, buffer, RRF_RT_ANY, &type, NULL, &size); + if (ret != ERROR_SUCCESS) + { + WARN("Reading %s returned %d\n", debugstr_w(buffer), ret); + RegCloseKey(regkey); + PropVariantClear(pv); + return S_OK; + } + + switch (type) + { + case REG_SZ: + { + pv->vt = VT_LPWSTR; + pv->u.pwszVal = CoTaskMemAlloc(size); + if (!pv->u.pwszVal) + hr = E_OUTOFMEMORY; + else + RegGetValueW(regkey, NULL, buffer, RRF_RT_REG_SZ, NULL, (BYTE*)pv->u.pwszVal, &size); + break; + } + case REG_DWORD: + { + pv->vt = VT_UI4; + RegGetValueW(regkey, NULL, buffer, RRF_RT_REG_DWORD, NULL, (BYTE*)&pv->u.ulVal, &size); + break; + } + case REG_BINARY: + { + pv->vt = VT_BLOB; + pv->u.blob.cbSize = size; + pv->u.blob.pBlobData = CoTaskMemAlloc(size); + if (!pv->u.blob.pBlobData) + hr = E_OUTOFMEMORY; + else + RegGetValueW(regkey, NULL, buffer, RRF_RT_REG_BINARY, NULL, (BYTE*)pv->u.blob.pBlobData, &size); + break; + } + default: + ERR("Unknown/unhandled type: %u\n", type); + PropVariantClear(pv); + break; + } + RegCloseKey(regkey); + return hr; +} + +static HRESULT MMDevice_SetPropValue(const GUID *devguid, DWORD flow, REFPROPERTYKEY key, REFPROPVARIANT pv) +{ + WCHAR buffer[80]; + const GUID *id = &key->fmtid; + HRESULT hr; + HKEY regkey; + LONG ret; + + hr = MMDevPropStore_OpenPropKey(devguid, flow, ®key); + if (FAILED(hr)) + return hr; + wsprintfW( buffer, propkey_formatW, 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], key->pid ); + switch (pv->vt) + { + case VT_UI4: + { + ret = RegSetValueExW(regkey, buffer, 0, REG_DWORD, (const BYTE*)&pv->u.ulVal, sizeof(DWORD)); + break; + } + case VT_BLOB: + { + ret = RegSetValueExW(regkey, buffer, 0, REG_BINARY, pv->u.blob.pBlobData, pv->u.blob.cbSize); + TRACE("Blob %p %u\n", pv->u.blob.pBlobData, pv->u.blob.cbSize); + + break; + } + case VT_LPWSTR: + { + ret = RegSetValueExW(regkey, buffer, 0, REG_SZ, (const BYTE*)pv->u.pwszVal, sizeof(WCHAR)*(1+lstrlenW(pv->u.pwszVal))); + break; + } + default: + ret = 0; + FIXME("Unhandled type %u\n", pv->vt); + hr = E_INVALIDARG; + break; + } + RegCloseKey(regkey); + TRACE("Writing %s returned %u\n", debugstr_w(buffer), ret); + return hr; +} + /* Creates or updates the state of a device * If GUID is null, a random guid will be assigned * and the device will be created @@ -594,139 +727,6 @@ static const IMMDeviceCollectionVtbl MMDevColVtbl = MMDevCol_Item }; -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 HRESULT MMDevPropStore_OpenPropKey(const GUID *guid, DWORD flow, HKEY *propkey) -{ - WCHAR buffer[39]; - LONG ret; - HKEY key; - StringFromGUID2(guid, buffer, 39); - if ((ret = RegOpenKeyExW(flow == eRender ? key_render : key_capture, buffer, 0, KEY_READ|KEY_WRITE, &key)) != ERROR_SUCCESS) - { - 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, propkey); - RegCloseKey(key); - if (ret != ERROR_SUCCESS) - { - WARN("Opening key %s failed with %u\n", debugstr_w(reg_properties), ret); - return E_FAIL; - } - return S_OK; -} - -HRESULT MMDevice_GetPropValue(const GUID *devguid, DWORD flow, REFPROPERTYKEY key, PROPVARIANT *pv) -{ - WCHAR buffer[80]; - const GUID *id = &key->fmtid; - DWORD type, size; - HRESULT hr = S_OK; - HKEY regkey; - LONG ret; - - hr = MMDevPropStore_OpenPropKey(devguid, flow, ®key); - if (FAILED(hr)) - return hr; - wsprintfW( buffer, propkey_formatW, 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], key->pid ); - ret = RegGetValueW(regkey, NULL, buffer, RRF_RT_ANY, &type, NULL, &size); - if (ret != ERROR_SUCCESS) - { - WARN("Reading %s returned %d\n", debugstr_w(buffer), ret); - RegCloseKey(regkey); - PropVariantClear(pv); - return S_OK; - } - - switch (type) - { - case REG_SZ: - { - pv->vt = VT_LPWSTR; - pv->u.pwszVal = CoTaskMemAlloc(size); - if (!pv->u.pwszVal) - hr = E_OUTOFMEMORY; - else - RegGetValueW(regkey, NULL, buffer, RRF_RT_REG_SZ, NULL, (BYTE*)pv->u.pwszVal, &size); - break; - } - case REG_DWORD: - { - pv->vt = VT_UI4; - RegGetValueW(regkey, NULL, buffer, RRF_RT_REG_DWORD, NULL, (BYTE*)&pv->u.ulVal, &size); - break; - } - case REG_BINARY: - { - pv->vt = VT_BLOB; - pv->u.blob.cbSize = size; - pv->u.blob.pBlobData = CoTaskMemAlloc(size); - if (!pv->u.blob.pBlobData) - hr = E_OUTOFMEMORY; - else - RegGetValueW(regkey, NULL, buffer, RRF_RT_REG_BINARY, NULL, (BYTE*)pv->u.blob.pBlobData, &size); - break; - } - default: - ERR("Unknown/unhandled type: %u\n", type); - PropVariantClear(pv); - break; - } - RegCloseKey(regkey); - return hr; -} - -HRESULT MMDevice_SetPropValue(const GUID *devguid, DWORD flow, REFPROPERTYKEY key, REFPROPVARIANT pv) -{ - WCHAR buffer[80]; - const GUID *id = &key->fmtid; - HRESULT hr; - HKEY regkey; - LONG ret; - - hr = MMDevPropStore_OpenPropKey(devguid, flow, ®key); - if (FAILED(hr)) - return hr; - wsprintfW( buffer, propkey_formatW, 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], key->pid ); - switch (pv->vt) - { - case VT_UI4: - { - ret = RegSetValueExW(regkey, buffer, 0, REG_DWORD, (const BYTE*)&pv->u.ulVal, sizeof(DWORD)); - break; - } - case VT_BLOB: - { - ret = RegSetValueExW(regkey, buffer, 0, REG_BINARY, pv->u.blob.pBlobData, pv->u.blob.cbSize); - TRACE("Blob %p %u\n", pv->u.blob.pBlobData, pv->u.blob.cbSize); - - break; - } - case VT_LPWSTR: - { - ret = RegSetValueExW(regkey, buffer, 0, REG_SZ, (const BYTE*)pv->u.pwszVal, sizeof(WCHAR)*(1+lstrlenW(pv->u.pwszVal))); - break; - } - default: - ret = 0; - FIXME("Unhandled type %u\n", pv->vt); - hr = E_INVALIDARG; - break; - } - RegCloseKey(regkey); - TRACE("Writing %s returned %u\n", debugstr_w(buffer), ret); - return hr; -} - #ifdef HAVE_OPENAL static void openal_setformat(MMDevice *This, DWORD freq) diff --git a/dlls/mmdevapi/mmdevapi.h b/dlls/mmdevapi/mmdevapi.h index cf5520c496e..4cc7184d4dd 100644 --- a/dlls/mmdevapi/mmdevapi.h +++ b/dlls/mmdevapi/mmdevapi.h @@ -24,7 +24,6 @@ extern HRESULT MMDevEnum_Create(REFIID riid, void **ppv); extern void MMDevEnum_Free(void); extern HRESULT MMDevice_GetPropValue(const GUID *devguid, DWORD flow, REFPROPERTYKEY key, PROPVARIANT *pv); -extern HRESULT MMDevice_SetPropValue(const GUID *devguid, DWORD flow, REFPROPERTYKEY key, REFPROPVARIANT pv); typedef struct MMDevice { IMMDevice IMMDevice_iface;