diff --git a/dlls/devenum/devenum_main.c b/dlls/devenum/devenum_main.c index 7bfc5936c4b..3499f99a62b 100644 --- a/dlls/devenum/devenum_main.c +++ b/dlls/devenum/devenum_main.c @@ -56,6 +56,17 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad) return TRUE; } +struct class_factory +{ + IClassFactory IClassFactory_iface; + IUnknown *obj; +}; + +static inline struct class_factory *impl_from_IClassFactory( IClassFactory *iface ) +{ + return CONTAINING_RECORD( iface, struct class_factory, IClassFactory_iface ); +} + static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID iid, void **obj) { TRACE("(%p, %s, %p)\n", iface, debugstr_guid(iid), obj); @@ -87,24 +98,15 @@ static ULONG WINAPI ClassFactory_Release(IClassFactory *iface) static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID iid, void **obj) { + struct class_factory *This = impl_from_IClassFactory( iface ); + TRACE("(%p, %s, %p)\n", outer, debugstr_guid(iid), obj); if (!obj) return E_POINTER; if (outer) return CLASS_E_NOAGGREGATION; - if (IsEqualGUID(&IID_ICreateDevEnum, iid)) - { - *obj = &DEVENUM_CreateDevEnum; - return S_OK; - } - if (IsEqualGUID(&IID_IParseDisplayName, iid)) - { - *obj = &DEVENUM_ParseDisplayName; - return S_OK; - } - - return CLASS_E_CLASSNOTAVAILABLE; + return IUnknown_QueryInterface(This->obj, iid, obj); } static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL lock) @@ -124,24 +126,24 @@ static const IClassFactoryVtbl ClassFactory_vtbl = { ClassFactory_LockServer }; -static IClassFactory devenum_cf = { &ClassFactory_vtbl }; +static struct class_factory create_devenum_cf = { { &ClassFactory_vtbl }, (IUnknown *)&DEVENUM_CreateDevEnum }; +static struct class_factory device_moniker_cf = { { &ClassFactory_vtbl }, (IUnknown *)&DEVENUM_ParseDisplayName }; /*********************************************************************** * DllGetClassObject (DEVENUM.@) */ -HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv) +HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID iid, void **obj) { - TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv); + TRACE("(%s, %s, %p)\n", debugstr_guid(clsid), debugstr_guid(iid), obj); - *ppv = NULL; + *obj = NULL; - /* FIXME: we should really have two class factories. - * Oh well - works just fine as it is */ - if (IsEqualGUID(rclsid, &CLSID_SystemDeviceEnum) || - IsEqualGUID(rclsid, &CLSID_CDeviceMoniker)) - return IClassFactory_QueryInterface(&devenum_cf, iid, ppv); + if (IsEqualGUID(clsid, &CLSID_SystemDeviceEnum)) + return IClassFactory_QueryInterface(&create_devenum_cf.IClassFactory_iface, iid, obj); + else if (IsEqualGUID(clsid, &CLSID_CDeviceMoniker)) + return IClassFactory_QueryInterface(&device_moniker_cf.IClassFactory_iface, iid, obj); - FIXME("CLSID: %s, IID: %s\n", debugstr_guid(rclsid), debugstr_guid(iid)); + FIXME("class %s not available\n", debugstr_guid(clsid)); return CLASS_E_CLASSNOTAVAILABLE; }