push(f) 25359c458b329fe03f66bef506b8062c200b9eb4
[wine/hacks.git] / dlls / windowscodecs / clsfactory.c
blob37e30e590a8ccc09bc411800ef4fe65216a9ceb2
1 /*
2 * Copyright 2009 Vincent Povirk for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "config.h"
21 #include <stdarg.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winreg.h"
28 #include "objbase.h"
29 #include "ocidl.h"
30 #include "initguid.h"
31 #include "wincodec.h"
33 #include "wincodecs_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
39 typedef struct {
40 REFCLSID classid;
41 HRESULT (*constructor)(IUnknown*,REFIID,void**);
42 } classinfo;
44 static classinfo wic_classes[] = {
45 {&CLSID_WICImagingFactory, ImagingFactory_CreateInstance},
46 {&CLSID_WICBmpDecoder, BmpDecoder_CreateInstance},
47 {0}};
49 typedef struct {
50 const IClassFactoryVtbl *lpIClassFactoryVtbl;
51 LONG ref;
52 classinfo *info;
53 } ClassFactoryImpl;
55 static HRESULT WINAPI ClassFactoryImpl_QueryInterface(IClassFactory *iface,
56 REFIID iid, void **ppv)
58 ClassFactoryImpl *This = (ClassFactoryImpl*)iface;
59 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
61 if (!ppv) return E_INVALIDARG;
63 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IClassFactory, iid))
65 *ppv = This;
67 else
69 *ppv = NULL;
70 return E_NOINTERFACE;
73 IUnknown_AddRef((IUnknown*)*ppv);
74 return S_OK;
77 static ULONG WINAPI ClassFactoryImpl_AddRef(IClassFactory *iface)
79 ClassFactoryImpl *This = (ClassFactoryImpl*)iface;
80 ULONG ref = InterlockedIncrement(&This->ref);
82 TRACE("(%p) refcount=%u\n", iface, ref);
84 return ref;
87 static ULONG WINAPI ClassFactoryImpl_Release(IClassFactory *iface)
89 ClassFactoryImpl *This = (ClassFactoryImpl*)iface;
90 ULONG ref = InterlockedDecrement(&This->ref);
92 TRACE("(%p) refcount=%u\n", iface, ref);
94 if (ref == 0)
95 HeapFree(GetProcessHeap(), 0, This);
97 return ref;
100 static HRESULT WINAPI ClassFactoryImpl_CreateInstance(IClassFactory *iface,
101 IUnknown *pUnkOuter, REFIID riid, void **ppv)
103 ClassFactoryImpl *This = (ClassFactoryImpl*)iface;
105 return This->info->constructor(pUnkOuter, riid, ppv);
108 static HRESULT WINAPI ClassFactoryImpl_LockServer(IClassFactory *iface, BOOL lock)
110 TRACE("(%p, %i): stub\n", iface, lock);
111 return E_NOTIMPL;
114 static const IClassFactoryVtbl ClassFactoryImpl_Vtbl = {
115 ClassFactoryImpl_QueryInterface,
116 ClassFactoryImpl_AddRef,
117 ClassFactoryImpl_Release,
118 ClassFactoryImpl_CreateInstance,
119 ClassFactoryImpl_LockServer
122 static HRESULT ClassFactoryImpl_Constructor(classinfo *info, REFIID riid, LPVOID *ppv)
124 ClassFactoryImpl *This;
125 HRESULT ret;
127 *ppv = NULL;
129 This = HeapAlloc(GetProcessHeap(), 0, sizeof(ClassFactoryImpl));
130 if (!This) return E_OUTOFMEMORY;
132 This->lpIClassFactoryVtbl = &ClassFactoryImpl_Vtbl;
133 This->ref = 1;
134 This->info = info;
136 ret = IClassFactory_QueryInterface((IClassFactory*)This, riid, ppv);
137 IClassFactory_Release((IClassFactory*)This);
139 return ret;
142 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
144 HRESULT ret;
145 classinfo *info=NULL;
146 int i;
148 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
150 if (!rclsid || !iid || !ppv)
151 return E_INVALIDARG;
153 *ppv = NULL;
155 for (i=0; wic_classes[i].classid; i++)
157 if (IsEqualCLSID(wic_classes[i].classid, rclsid))
159 info = &wic_classes[i];
160 break;
164 if (info)
165 ret = ClassFactoryImpl_Constructor(info, iid, ppv);
166 else
167 ret = CLASS_E_CLASSNOTAVAILABLE;
169 TRACE("<-- %08X\n", ret);
170 return ret;