mmdevapi: Standardize the COM usage in devenum.c.

Michael Stefaniuc mstefani at redhat.de
Tue Dec 14 05:02:32 CST 2010


---
 dlls/mmdevapi/devenum.c |   85 +++++++++++++++++++++++++++++-----------------
 1 files changed, 53 insertions(+), 32 deletions(-)

diff --git a/dlls/mmdevapi/devenum.c b/dlls/mmdevapi/devenum.c
index 79e004d..e53566a 100644
--- a/dlls/mmdevapi/devenum.c
+++ b/dlls/mmdevapi/devenum.c
@@ -71,7 +71,7 @@ static HKEY key_capture;
 
 typedef struct MMDevPropStoreImpl
 {
-    const IPropertyStoreVtbl *lpVtbl;
+    IPropertyStore IPropertyStore_iface;
     LONG ref;
     MMDevice *parent;
     DWORD access;
@@ -79,7 +79,7 @@ typedef struct MMDevPropStoreImpl
 
 typedef struct MMDevEnumImpl
 {
-    const IMMDeviceEnumeratorVtbl *lpVtbl;
+    IMMDeviceEnumerator IMMDeviceEnumerator_iface;
     LONG ref;
 } MMDevEnumImpl;
 
@@ -95,20 +95,41 @@ static const IMMEndpointVtbl MMEndpointVtbl;
 
 typedef struct MMDevColImpl
 {
-    const IMMDeviceCollectionVtbl *lpVtbl;
+    IMMDeviceCollection IMMDeviceCollection_iface;
     LONG ref;
     EDataFlow flow;
     DWORD state;
 } MMDevColImpl;
 
 typedef struct IPropertyBagImpl {
-    const IPropertyBagVtbl *lpVtbl;
+    IPropertyBag IPropertyBag_iface;
     GUID devguid;
 } IPropertyBagImpl;
+
 static const IPropertyBagVtbl PB_Vtbl;
 
 static HRESULT MMDevPropStore_Create(MMDevice *This, DWORD access, IPropertyStore **ppv);
 
+static inline MMDevPropStore *impl_from_IPropertyStore(IPropertyStore *iface)
+{
+    return CONTAINING_RECORD(iface, MMDevPropStore, IPropertyStore_iface);
+}
+
+static inline MMDevEnumImpl *impl_from_IMMDeviceEnumerator(IMMDeviceEnumerator *iface)
+{
+    return CONTAINING_RECORD(iface, MMDevEnumImpl, IMMDeviceEnumerator_iface);
+}
+
+static inline MMDevColImpl *impl_from_IMMDeviceCollection(IMMDeviceCollection *iface)
+{
+    return CONTAINING_RECORD(iface, MMDevColImpl, IMMDeviceCollection_iface);
+}
+
+static inline IPropertyBagImpl *impl_from_IPropertyBag(IPropertyBag *iface)
+{
+    return CONTAINING_RECORD(iface, IPropertyBagImpl, IPropertyBag_iface);
+}
+
 /* Creates or updates the state of a device
  * If GUID is null, a random guid will be assigned
  * and the device will be created
@@ -307,8 +328,8 @@ static HRESULT WINAPI MMDevice_Activate(IMMDevice *iface, REFIID riid, DWORD cls
             {
                 /* ::Load cannot assume the interface stays alive after the function returns,
                  * so just create the interface on the stack, saves a lot of complicated code */
-                IPropertyBagImpl bag = { &PB_Vtbl, This->devguid };
-                hr = IPersistPropertyBag_Load(ppb, (IPropertyBag*)&bag, NULL);
+                IPropertyBagImpl bag = { { &PB_Vtbl }, This->devguid };
+                hr = IPersistPropertyBag_Load(ppb, &bag.IPropertyBag_iface, NULL);
                 IPersistPropertyBag_Release(ppb);
                 if (FAILED(hr))
                     IBaseFilter_Release((IBaseFilter*)*ppv);
@@ -465,11 +486,11 @@ static HRESULT MMDevCol_Create(IMMDeviceCollection **ppv, EDataFlow flow, DWORD
     *ppv = NULL;
     if (!This)
         return E_OUTOFMEMORY;
-    This->lpVtbl = &MMDevColVtbl;
+    This->IMMDeviceCollection_iface.lpVtbl = &MMDevColVtbl;
     This->ref = 1;
     This->flow = flow;
     This->state = state;
-    *ppv = (IMMDeviceCollection*)This;
+    *ppv = &This->IMMDeviceCollection_iface;
     return S_OK;
 }
 
@@ -480,7 +501,7 @@ static void MMDevCol_Destroy(MMDevColImpl *This)
 
 static HRESULT WINAPI MMDevCol_QueryInterface(IMMDeviceCollection *iface, REFIID riid, void **ppv)
 {
-    MMDevColImpl *This = (MMDevColImpl*)iface;
+    MMDevColImpl *This = impl_from_IMMDeviceCollection(iface);
 
     if (!ppv)
         return E_POINTER;
@@ -497,7 +518,7 @@ static HRESULT WINAPI MMDevCol_QueryInterface(IMMDeviceCollection *iface, REFIID
 
 static ULONG WINAPI MMDevCol_AddRef(IMMDeviceCollection *iface)
 {
-    MMDevColImpl *This = (MMDevColImpl*)iface;
+    MMDevColImpl *This = impl_from_IMMDeviceCollection(iface);
     LONG ref = InterlockedIncrement(&This->ref);
     TRACE("Refcount now %i\n", ref);
     return ref;
@@ -505,7 +526,7 @@ static ULONG WINAPI MMDevCol_AddRef(IMMDeviceCollection *iface)
 
 static ULONG WINAPI MMDevCol_Release(IMMDeviceCollection *iface)
 {
-    MMDevColImpl *This = (MMDevColImpl*)iface;
+    MMDevColImpl *This = impl_from_IMMDeviceCollection(iface);
     LONG ref = InterlockedDecrement(&This->ref);
     TRACE("Refcount now %i\n", ref);
     if (!ref)
@@ -515,7 +536,7 @@ static ULONG WINAPI MMDevCol_Release(IMMDeviceCollection *iface)
 
 static HRESULT WINAPI MMDevCol_GetCount(IMMDeviceCollection *iface, UINT *numdevs)
 {
-    MMDevColImpl *This = (MMDevColImpl*)iface;
+    MMDevColImpl *This = impl_from_IMMDeviceCollection(iface);
     DWORD i;
 
     TRACE("(%p)->(%p)\n", This, numdevs);
@@ -535,7 +556,7 @@ static HRESULT WINAPI MMDevCol_GetCount(IMMDeviceCollection *iface, UINT *numdev
 
 static HRESULT WINAPI MMDevCol_Item(IMMDeviceCollection *iface, UINT n, IMMDevice **dev)
 {
-    MMDevColImpl *This = (MMDevColImpl*)iface;
+    MMDevColImpl *This = impl_from_IMMDeviceCollection(iface);
     DWORD i = 0, j = 0;
 
     TRACE("(%p)->(%u, %p)\n", This, n, dev);
@@ -905,7 +926,7 @@ HRESULT MMDevEnum_Create(REFIID riid, void **ppv)
         if (!This)
             return E_OUTOFMEMORY;
         This->ref = 1;
-        This->lpVtbl = &MMDevEnumVtbl;
+        This->IMMDeviceEnumerator_iface.lpVtbl = &MMDevEnumVtbl;
         MMDevEnumerator = This;
 
         ret = RegCreateKeyExW(HKEY_LOCAL_MACHINE, software_mmdevapi, 0, NULL, 0, KEY_WRITE|KEY_READ, NULL, &root, NULL);
@@ -981,7 +1002,7 @@ void MMDevEnum_Free(void)
 
 static HRESULT WINAPI MMDevEnum_QueryInterface(IMMDeviceEnumerator *iface, REFIID riid, void **ppv)
 {
-    MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
+    MMDevEnumImpl *This = impl_from_IMMDeviceEnumerator(iface);
 
     if (!ppv)
         return E_POINTER;
@@ -998,7 +1019,7 @@ static HRESULT WINAPI MMDevEnum_QueryInterface(IMMDeviceEnumerator *iface, REFII
 
 static ULONG WINAPI MMDevEnum_AddRef(IMMDeviceEnumerator *iface)
 {
-    MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
+    MMDevEnumImpl *This = impl_from_IMMDeviceEnumerator(iface);
     LONG ref = InterlockedIncrement(&This->ref);
     TRACE("Refcount now %i\n", ref);
     return ref;
@@ -1006,7 +1027,7 @@ static ULONG WINAPI MMDevEnum_AddRef(IMMDeviceEnumerator *iface)
 
 static ULONG WINAPI MMDevEnum_Release(IMMDeviceEnumerator *iface)
 {
-    MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
+    MMDevEnumImpl *This = impl_from_IMMDeviceEnumerator(iface);
     LONG ref = InterlockedDecrement(&This->ref);
     if (!ref)
         MMDevEnum_Free();
@@ -1016,7 +1037,7 @@ static ULONG WINAPI MMDevEnum_Release(IMMDeviceEnumerator *iface)
 
 static HRESULT WINAPI MMDevEnum_EnumAudioEndpoints(IMMDeviceEnumerator *iface, EDataFlow flow, DWORD mask, IMMDeviceCollection **devices)
 {
-    MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
+    MMDevEnumImpl *This = impl_from_IMMDeviceEnumerator(iface);
     TRACE("(%p)->(%u,%u,%p)\n", This, flow, mask, devices);
     if (!devices)
         return E_POINTER;
@@ -1030,7 +1051,7 @@ static HRESULT WINAPI MMDevEnum_EnumAudioEndpoints(IMMDeviceEnumerator *iface, E
 
 static HRESULT WINAPI MMDevEnum_GetDefaultAudioEndpoint(IMMDeviceEnumerator *iface, EDataFlow flow, ERole role, IMMDevice **device)
 {
-    MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
+    MMDevEnumImpl *This = impl_from_IMMDeviceEnumerator(iface);
     TRACE("(%p)->(%u,%u,%p)\n", This, flow, role, device);
 
     if (!device)
@@ -1055,7 +1076,7 @@ static HRESULT WINAPI MMDevEnum_GetDefaultAudioEndpoint(IMMDeviceEnumerator *ifa
 
 static HRESULT WINAPI MMDevEnum_GetDevice(IMMDeviceEnumerator *iface, const WCHAR *name, IMMDevice **device)
 {
-    MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
+    MMDevEnumImpl *This = impl_from_IMMDeviceEnumerator(iface);
     DWORD i=0;
     IMMDevice *dev = NULL;
 
@@ -1085,7 +1106,7 @@ static HRESULT WINAPI MMDevEnum_GetDevice(IMMDeviceEnumerator *iface, const WCHA
 
 static HRESULT WINAPI MMDevEnum_RegisterEndpointNotificationCallback(IMMDeviceEnumerator *iface, IMMNotificationClient *client)
 {
-    MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
+    MMDevEnumImpl *This = impl_from_IMMDeviceEnumerator(iface);
     TRACE("(%p)->(%p)\n", This, client);
     FIXME("stub\n");
     return S_OK;
@@ -1093,7 +1114,7 @@ static HRESULT WINAPI MMDevEnum_RegisterEndpointNotificationCallback(IMMDeviceEn
 
 static HRESULT WINAPI MMDevEnum_UnregisterEndpointNotificationCallback(IMMDeviceEnumerator *iface, IMMNotificationClient *client)
 {
-    MMDevEnumImpl *This = (MMDevEnumImpl*)iface;
+    MMDevEnumImpl *This = impl_from_IMMDeviceEnumerator(iface);
     TRACE("(%p)->(%p)\n", This, client);
     FIXME("stub\n");
     return S_OK;
@@ -1122,10 +1143,10 @@ static HRESULT MMDevPropStore_Create(MMDevice *parent, DWORD access, IPropertySt
         return E_INVALIDARG;
     }
     This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
-    *ppv = (IPropertyStore*)This;
+    *ppv = &This->IPropertyStore_iface;
     if (!This)
         return E_OUTOFMEMORY;
-    This->lpVtbl = &MMDevPropVtbl;
+    This->IPropertyStore_iface.lpVtbl = &MMDevPropVtbl;
     This->ref = 1;
     This->parent = parent;
     This->access = access;
@@ -1139,7 +1160,7 @@ static void MMDevPropStore_Destroy(MMDevPropStore *This)
 
 static HRESULT WINAPI MMDevPropStore_QueryInterface(IPropertyStore *iface, REFIID riid, void **ppv)
 {
-    MMDevPropStore *This = (MMDevPropStore*)iface;
+    MMDevPropStore *This = impl_from_IPropertyStore(iface);
 
     if (!ppv)
         return E_POINTER;
@@ -1156,7 +1177,7 @@ static HRESULT WINAPI MMDevPropStore_QueryInterface(IPropertyStore *iface, REFII
 
 static ULONG WINAPI MMDevPropStore_AddRef(IPropertyStore *iface)
 {
-    MMDevPropStore *This = (MMDevPropStore*)iface;
+    MMDevPropStore *This = impl_from_IPropertyStore(iface);
     LONG ref = InterlockedIncrement(&This->ref);
     TRACE("Refcount now %i\n", ref);
     return ref;
@@ -1164,7 +1185,7 @@ static ULONG WINAPI MMDevPropStore_AddRef(IPropertyStore *iface)
 
 static ULONG WINAPI MMDevPropStore_Release(IPropertyStore *iface)
 {
-    MMDevPropStore *This = (MMDevPropStore*)iface;
+    MMDevPropStore *This = impl_from_IPropertyStore(iface);
     LONG ref = InterlockedDecrement(&This->ref);
     TRACE("Refcount now %i\n", ref);
     if (!ref)
@@ -1174,7 +1195,7 @@ static ULONG WINAPI MMDevPropStore_Release(IPropertyStore *iface)
 
 static HRESULT WINAPI MMDevPropStore_GetCount(IPropertyStore *iface, DWORD *nprops)
 {
-    MMDevPropStore *This = (MMDevPropStore*)iface;
+    MMDevPropStore *This = impl_from_IPropertyStore(iface);
     WCHAR buffer[50];
     DWORD i = 0;
     HKEY propkey;
@@ -1201,7 +1222,7 @@ static HRESULT WINAPI MMDevPropStore_GetCount(IPropertyStore *iface, DWORD *npro
 
 static HRESULT WINAPI MMDevPropStore_GetAt(IPropertyStore *iface, DWORD prop, PROPERTYKEY *key)
 {
-    MMDevPropStore *This = (MMDevPropStore*)iface;
+    MMDevPropStore *This = impl_from_IPropertyStore(iface);
     WCHAR buffer[50];
     DWORD len = sizeof(buffer)/sizeof(*buffer);
     HRESULT hr;
@@ -1230,7 +1251,7 @@ static HRESULT WINAPI MMDevPropStore_GetAt(IPropertyStore *iface, DWORD prop, PR
 
 static HRESULT WINAPI MMDevPropStore_GetValue(IPropertyStore *iface, REFPROPERTYKEY key, PROPVARIANT *pv)
 {
-    MMDevPropStore *This = (MMDevPropStore*)iface;
+    MMDevPropStore *This = impl_from_IPropertyStore(iface);
     TRACE("(%p)->(\"%s,%u\", %p\n", This, debugstr_guid(&key->fmtid), key ? key->pid : 0, pv);
 
     if (!key || !pv)
@@ -1255,7 +1276,7 @@ static HRESULT WINAPI MMDevPropStore_GetValue(IPropertyStore *iface, REFPROPERTY
 
 static HRESULT WINAPI MMDevPropStore_SetValue(IPropertyStore *iface, REFPROPERTYKEY key, REFPROPVARIANT pv)
 {
-    MMDevPropStore *This = (MMDevPropStore*)iface;
+    MMDevPropStore *This = impl_from_IPropertyStore(iface);
 
     if (!key || !pv)
         return E_POINTER;
@@ -1308,7 +1329,7 @@ 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 = (IPropertyBagImpl*)iface;
+    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))
     {
-- 
1.7.2.3



More information about the wine-patches mailing list