ReactOS  0.4.13-dev-99-g7e18b6d
clsfactory.c
Go to the documentation of this file.
1 /*
2  * Copyright 2009 Vincent Povirk for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18 
19 #include "config.h"
20 
21 #include <stdarg.h>
22 
23 #define COBJMACROS
24 
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 
32 #include "wincodecs_private.h"
33 
34 #include "wine/debug.h"
35 
37 
39 
40 typedef struct {
41  REFCLSID classid;
42  class_constructor constructor;
44 
45 static const classinfo wic_classes[] = {
46  {&CLSID_WICImagingFactory, ImagingFactory_CreateInstance},
47  {&CLSID_WICImagingFactory2, ImagingFactory_CreateInstance},
48  {&CLSID_WICBmpDecoder, BmpDecoder_CreateInstance},
49  {&CLSID_WICPngDecoder, PngDecoder_CreateInstance},
50  {&CLSID_WICPngEncoder, PngEncoder_CreateInstance},
51  {&CLSID_WICBmpEncoder, BmpEncoder_CreateInstance},
52  {&CLSID_WICGifDecoder, GifDecoder_CreateInstance},
53  {&CLSID_WICGifEncoder, GifEncoder_CreateInstance},
54  {&CLSID_WICIcoDecoder, IcoDecoder_CreateInstance},
55  {&CLSID_WICJpegDecoder, JpegDecoder_CreateInstance},
56  {&CLSID_WICJpegEncoder, JpegEncoder_CreateInstance},
57  {&CLSID_WICTiffDecoder, TiffDecoder_CreateInstance},
58  {&CLSID_WICTiffEncoder, TiffEncoder_CreateInstance},
59  {&CLSID_WICIcnsEncoder, IcnsEncoder_CreateInstance},
60  {&CLSID_WICDefaultFormatConverter, FormatConverter_CreateInstance},
61  {&CLSID_WineTgaDecoder, TgaDecoder_CreateInstance},
62  {&CLSID_WICUnknownMetadataReader, UnknownMetadataReader_CreateInstance},
63  {&CLSID_WICIfdMetadataReader, IfdMetadataReader_CreateInstance},
64  {&CLSID_WICPngChrmMetadataReader, PngChrmReader_CreateInstance},
65  {&CLSID_WICPngGamaMetadataReader, PngGamaReader_CreateInstance},
66  {&CLSID_WICPngTextMetadataReader, PngTextReader_CreateInstance},
67  {&CLSID_WICLSDMetadataReader, LSDReader_CreateInstance},
68  {&CLSID_WICIMDMetadataReader, IMDReader_CreateInstance},
69  {&CLSID_WICGCEMetadataReader, GCEReader_CreateInstance},
70  {&CLSID_WICAPEMetadataReader, APEReader_CreateInstance},
71  {&CLSID_WICGifCommentMetadataReader, GifCommentReader_CreateInstance},
72  {0}};
73 
74 typedef struct {
75  IClassFactory IClassFactory_iface;
76  LONG ref;
77  const classinfo *info;
79 
81 {
82  return CONTAINING_RECORD(iface, ClassFactoryImpl, IClassFactory_iface);
83 }
84 
86  REFIID iid, void **ppv)
87 {
89  TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
90 
91  if (!ppv) return E_INVALIDARG;
92 
93  if (IsEqualIID(&IID_IUnknown, iid) ||
95  {
96  *ppv = &This->IClassFactory_iface;
97  }
98  else
99  {
100  *ppv = NULL;
101  return E_NOINTERFACE;
102  }
103 
104  IUnknown_AddRef((IUnknown*)*ppv);
105  return S_OK;
106 }
107 
109 {
112 
113  TRACE("(%p) refcount=%u\n", iface, ref);
114 
115  return ref;
116 }
117 
119 {
122 
123  TRACE("(%p) refcount=%u\n", iface, ref);
124 
125  if (ref == 0)
127 
128  return ref;
129 }
130 
132  IUnknown *pUnkOuter, REFIID riid, void **ppv)
133 {
135 
136  *ppv = NULL;
137 
138  if (pUnkOuter) return CLASS_E_NOAGGREGATION;
139 
140  return This->info->constructor(riid, ppv);
141 }
142 
144 {
145  TRACE("(%p, %i): stub\n", iface, lock);
146  return E_NOTIMPL;
147 }
148 
149 static const IClassFactoryVtbl ClassFactoryImpl_Vtbl = {
155 };
156 
158 {
160  HRESULT ret;
161 
162  *ppv = NULL;
163 
165  if (!This) return E_OUTOFMEMORY;
166 
167  This->IClassFactory_iface.lpVtbl = &ClassFactoryImpl_Vtbl;
168  This->ref = 1;
169  This->info = info;
170 
171  ret = IClassFactory_QueryInterface(&This->IClassFactory_iface, riid, ppv);
172  IClassFactory_Release(&This->IClassFactory_iface);
173 
174  return ret;
175 }
176 
178 {
179  HRESULT ret;
180  const classinfo *info=NULL;
181  int i;
182 
183  TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
184 
185  if (!rclsid || !iid || !ppv)
186  return E_INVALIDARG;
187 
188  *ppv = NULL;
189 
190  for (i=0; wic_classes[i].classid; i++)
191  {
192  if (IsEqualCLSID(wic_classes[i].classid, rclsid))
193  {
194  info = &wic_classes[i];
195  break;
196  }
197  }
198 
199  if (info)
201  else
202  ret = WIC_DllGetClassObject(rclsid, iid, ppv);
203 
204  TRACE("<-- %08X\n", ret);
205  return ret;
206 }
207 
208 HRESULT create_instance(CLSID *clsid, const IID *iid, void **ppv)
209 {
210  int i;
211 
212  for (i=0; wic_classes[i].classid; i++)
213  if (IsEqualCLSID(wic_classes[i].classid, clsid))
214  return wic_classes[i].constructor(iid, ppv);
215 
216  return CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, iid, ppv);
217 }
HRESULT JpegEncoder_CreateInstance(REFIID iid, void **ppv)
Definition: jpegformat.c:1556
HRESULT GifDecoder_CreateInstance(REFIID iid, void **ppv)
Definition: gifformat.c:1434
static ULONG WINAPI ClassFactoryImpl_Release(IClassFactory *iface)
Definition: clsfactory.c:118
#define REFIID
Definition: guiddef.h:113
static ClassFactoryImpl * impl_from_IClassFactory(IClassFactory *iface)
Definition: clsfactory.c:80
#define E_NOINTERFACE
Definition: winerror.h:2364
HRESULT IMDReader_CreateInstance(REFIID iid, void **ppv)
Definition: gifformat.c:249
rwlock_t lock
Definition: tcpcore.h:1163
HRESULT TiffDecoder_CreateInstance(REFIID iid, void **ppv)
Definition: tiffformat.c:2360
HRESULT WINAPI WIC_DllGetClassObject(REFCLSID, REFIID, LPVOID *)
Definition: clsfactory.c:38
HRESULT IcoDecoder_CreateInstance(REFIID iid, void **ppv)
Definition: icoformat.c:759
REFIID riid
Definition: precomp.h:44
#define REFCLSID
Definition: guiddef.h:112
HRESULT PngTextReader_CreateInstance(REFIID iid, void **ppv)
Definition: pngformat.c:155
static ULONG WINAPI ClassFactoryImpl_AddRef(IClassFactory *iface)
Definition: clsfactory.c:108
HRESULT PngGamaReader_CreateInstance(REFIID iid, void **ppv)
Definition: pngformat.c:217
REFIID LPVOID * ppv
Definition: atlbase.h:39
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
Definition: clsfactory.c:177
classinfo
Definition: clsfactory.c:43
HRESULT BmpDecoder_CreateInstance(REFIID iid, void **ppv)
Definition: bmpdecode.c:1194
HRESULT PngChrmReader_CreateInstance(REFIID iid, void **ppv)
Definition: pngformat.c:295
HRESULT APEReader_CreateInstance(REFIID iid, void **ppv)
Definition: gifformat.c:434
Definition: send.c:47
struct _test_info info[]
Definition: SetCursorPos.c:19
static const IClassFactoryVtbl ClassFactoryImpl_Vtbl
Definition: clsfactory.c:149
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HRESULT GifEncoder_CreateInstance(REFIID iid, void **ppv)
Definition: gifformat.c:2375
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
WINE_DEFAULT_DEBUG_CHANNEL(wincodecs)
HRESULT FormatConverter_CreateInstance(REFIID iid, void **ppv)
Definition: converter.c:1762
GLenum GLint ref
Definition: glext.h:6028
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
HRESULT JpegDecoder_CreateInstance(REFIID iid, void **ppv)
Definition: jpegformat.c:1550
HRESULT GifCommentReader_CreateInstance(REFIID iid, void **ppv)
Definition: gifformat.c:528
HRESULT ImagingFactory_CreateInstance(REFIID iid, void **ppv)
Definition: imgfactory.c:1470
#define debugstr_guid
Definition: kernel32.h:35
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
HRESULT BmpEncoder_CreateInstance(REFIID iid, void **ppv)
Definition: bmpencode.c:642
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG HRESULT
Definition: typedefs.h:77
const GUID IID_IUnknown
#define WINAPI
Definition: msvc.h:8
static const classinfo wic_classes[]
Definition: clsfactory.c:45
static HRESULT WINAPI ClassFactoryImpl_LockServer(IClassFactory *iface, BOOL lock)
Definition: clsfactory.c:143
HRESULT IcnsEncoder_CreateInstance(REFIID iid, void **ppv)
Definition: icnsformat.c:738
int ret
REFCLSID clsid
Definition: msctf.c:84
#define InterlockedDecrement
Definition: armddk.h:52
HRESULT(* class_constructor)(REFIID, void **)
#define CLASS_E_NOAGGREGATION
Definition: winerror.h:2662
HRESULT PngDecoder_CreateInstance(REFIID iid, void **ppv)
Definition: pngformat.c:2177
HRESULT create_instance(CLSID *clsid, const IID *iid, void **ppv)
Definition: clsfactory.c:208
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3234
HRESULT PngEncoder_CreateInstance(REFIID iid, void **ppv)
Definition: pngformat.c:2183
HRESULT LSDReader_CreateInstance(REFIID iid, void **ppv)
Definition: gifformat.c:168
HRESULT UnknownMetadataReader_CreateInstance(REFIID iid, void **ppv)
HRESULT GCEReader_CreateInstance(REFIID iid, void **ppv)
Definition: gifformat.c:327
#define S_OK
Definition: intsafe.h:59
#define InterlockedIncrement
Definition: armddk.h:53
#define DECLSPEC_HIDDEN
Definition: precomp.h:8
static HRESULT ClassFactoryImpl_Constructor(const classinfo *info, REFIID riid, LPVOID *ppv)
Definition: clsfactory.c:157
static HRESULT WINAPI ClassFactoryImpl_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, void **ppv)
Definition: clsfactory.c:131
static HRESULT WINAPI ClassFactoryImpl_QueryInterface(IClassFactory *iface, REFIID iid, void **ppv)
Definition: clsfactory.c:85
#define E_NOTIMPL
Definition: ddrawi.h:99
HRESULT TiffEncoder_CreateInstance(REFIID iid, void **ppv)
Definition: tiffformat.c:2366
HRESULT TgaDecoder_CreateInstance(REFIID iid, void **ppv)
Definition: tgaformat.c:942
const classinfo * info
Definition: clsfactory.c:77
unsigned int ULONG
Definition: retypes.h:1
HRESULT IfdMetadataReader_CreateInstance(REFIID iid, void **ppv)
const GUID IID_IClassFactory
#define IsEqualCLSID(rclsid1, rclsid2)
Definition: guiddef.h:91
#define HeapFree(x, y, z)
Definition: compat.h:394
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:90
struct ClassFactoryImpl ClassFactoryImpl