Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenclsfactory.c
Go to the documentation of this file.
00001 /* 00002 * Copyright 2009 Vincent Povirk for CodeWeavers 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00017 */ 00018 00019 #include "config.h" 00020 00021 #include <stdarg.h> 00022 00023 #define COBJMACROS 00024 00025 #include "windef.h" 00026 #include "winbase.h" 00027 #include "winreg.h" 00028 #include "objbase.h" 00029 #include "ocidl.h" 00030 #include "initguid.h" 00031 #include "wincodec.h" 00032 00033 #include "wincodecs_private.h" 00034 00035 #include "wine/debug.h" 00036 00037 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs); 00038 00039 typedef struct { 00040 REFCLSID classid; 00041 HRESULT (*constructor)(IUnknown*,REFIID,void**); 00042 } classinfo; 00043 00044 static classinfo wic_classes[] = { 00045 {&CLSID_WICImagingFactory, ImagingFactory_CreateInstance}, 00046 {&CLSID_WICBmpDecoder, BmpDecoder_CreateInstance}, 00047 {&CLSID_WICPngDecoder, PngDecoder_CreateInstance}, 00048 {&CLSID_WICPngEncoder, PngEncoder_CreateInstance}, 00049 {&CLSID_WICBmpEncoder, BmpEncoder_CreateInstance}, 00050 {&CLSID_WICGifDecoder, GifDecoder_CreateInstance}, 00051 {&CLSID_WICIcoDecoder, IcoDecoder_CreateInstance}, 00052 {&CLSID_WICJpegDecoder, JpegDecoder_CreateInstance}, 00053 {&CLSID_WICTiffDecoder, TiffDecoder_CreateInstance}, 00054 {&CLSID_WICDefaultFormatConverter, FormatConverter_CreateInstance}, 00055 {0}}; 00056 00057 typedef struct { 00058 const IClassFactoryVtbl *lpIClassFactoryVtbl; 00059 LONG ref; 00060 classinfo *info; 00061 } ClassFactoryImpl; 00062 00063 static HRESULT WINAPI ClassFactoryImpl_QueryInterface(IClassFactory *iface, 00064 REFIID iid, void **ppv) 00065 { 00066 ClassFactoryImpl *This = (ClassFactoryImpl*)iface; 00067 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv); 00068 00069 if (!ppv) return E_INVALIDARG; 00070 00071 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IClassFactory, iid)) 00072 { 00073 *ppv = This; 00074 } 00075 else 00076 { 00077 *ppv = NULL; 00078 return E_NOINTERFACE; 00079 } 00080 00081 IUnknown_AddRef((IUnknown*)*ppv); 00082 return S_OK; 00083 } 00084 00085 static ULONG WINAPI ClassFactoryImpl_AddRef(IClassFactory *iface) 00086 { 00087 ClassFactoryImpl *This = (ClassFactoryImpl*)iface; 00088 ULONG ref = InterlockedIncrement(&This->ref); 00089 00090 TRACE("(%p) refcount=%u\n", iface, ref); 00091 00092 return ref; 00093 } 00094 00095 static ULONG WINAPI ClassFactoryImpl_Release(IClassFactory *iface) 00096 { 00097 ClassFactoryImpl *This = (ClassFactoryImpl*)iface; 00098 ULONG ref = InterlockedDecrement(&This->ref); 00099 00100 TRACE("(%p) refcount=%u\n", iface, ref); 00101 00102 if (ref == 0) 00103 HeapFree(GetProcessHeap(), 0, This); 00104 00105 return ref; 00106 } 00107 00108 static HRESULT WINAPI ClassFactoryImpl_CreateInstance(IClassFactory *iface, 00109 IUnknown *pUnkOuter, REFIID riid, void **ppv) 00110 { 00111 ClassFactoryImpl *This = (ClassFactoryImpl*)iface; 00112 00113 return This->info->constructor(pUnkOuter, riid, ppv); 00114 } 00115 00116 static HRESULT WINAPI ClassFactoryImpl_LockServer(IClassFactory *iface, BOOL lock) 00117 { 00118 TRACE("(%p, %i): stub\n", iface, lock); 00119 return E_NOTIMPL; 00120 } 00121 00122 static const IClassFactoryVtbl ClassFactoryImpl_Vtbl = { 00123 ClassFactoryImpl_QueryInterface, 00124 ClassFactoryImpl_AddRef, 00125 ClassFactoryImpl_Release, 00126 ClassFactoryImpl_CreateInstance, 00127 ClassFactoryImpl_LockServer 00128 }; 00129 00130 static HRESULT ClassFactoryImpl_Constructor(classinfo *info, REFIID riid, LPVOID *ppv) 00131 { 00132 ClassFactoryImpl *This; 00133 HRESULT ret; 00134 00135 *ppv = NULL; 00136 00137 This = HeapAlloc(GetProcessHeap(), 0, sizeof(ClassFactoryImpl)); 00138 if (!This) return E_OUTOFMEMORY; 00139 00140 This->lpIClassFactoryVtbl = &ClassFactoryImpl_Vtbl; 00141 This->ref = 1; 00142 This->info = info; 00143 00144 ret = IClassFactory_QueryInterface((IClassFactory*)This, riid, ppv); 00145 IClassFactory_Release((IClassFactory*)This); 00146 00147 return ret; 00148 } 00149 00150 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv) 00151 { 00152 HRESULT ret; 00153 classinfo *info=NULL; 00154 int i; 00155 00156 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv); 00157 00158 if (!rclsid || !iid || !ppv) 00159 return E_INVALIDARG; 00160 00161 *ppv = NULL; 00162 00163 for (i=0; wic_classes[i].classid; i++) 00164 { 00165 if (IsEqualCLSID(wic_classes[i].classid, rclsid)) 00166 { 00167 info = &wic_classes[i]; 00168 break; 00169 } 00170 } 00171 00172 if (info) 00173 ret = ClassFactoryImpl_Constructor(info, iid, ppv); 00174 else 00175 ret = CLASS_E_CLASSNOTAVAILABLE; 00176 00177 TRACE("<-- %08X\n", ret); 00178 return ret; 00179 } Generated on Sat May 26 2012 04:25:24 for ReactOS by
1.7.6.1
|