wmphoto: Implement class factory for WmpDecoder.
[wine.git] / dlls / wmphoto / main.c
blob7659dcb2ca8b01a82002f4a9971b145b1e50d94b
1 /*
2 * Copyright 2017 Vincent Povirk for CodeWeavers
3 * Copyright 2020 RĂ©mi Bernon for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <stdarg.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "objbase.h"
27 #include "rpcproxy.h"
29 #include "wincodecs_private.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
34 HRESULT create_instance(const CLSID *clsid, const IID *iid, void **ppv)
36 return CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, iid, ppv);
39 HRESULT get_decoder_info(REFCLSID clsid, IWICBitmapDecoderInfo **info)
41 IWICImagingFactory* factory;
42 IWICComponentInfo *compinfo;
43 HRESULT hr;
45 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
46 &IID_IWICImagingFactory, (void **)&factory);
47 if (FAILED(hr))
48 return hr;
50 hr = IWICImagingFactory_CreateComponentInfo(factory, clsid, &compinfo);
51 if (FAILED(hr))
53 IWICImagingFactory_Release(factory);
54 return hr;
57 hr = IWICComponentInfo_QueryInterface(compinfo, &IID_IWICBitmapDecoderInfo,
58 (void **)info);
60 IWICComponentInfo_Release(compinfo);
61 IWICImagingFactory_Release(factory);
62 return hr;
65 struct class_factory
67 IClassFactory IClassFactory_iface;
70 static HRESULT WINAPI wmp_class_factory_QueryInterface(IClassFactory *iface, REFIID iid, void **out)
72 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
74 if (IsEqualGUID(iid, &IID_IUnknown) || IsEqualGUID(iid, &IID_IClassFactory))
76 *out = iface;
77 IClassFactory_AddRef(iface);
78 return S_OK;
81 *out = NULL;
82 FIXME("%s not implemented.\n", debugstr_guid(iid));
83 return E_NOINTERFACE;
86 static ULONG WINAPI wmp_class_factory_AddRef(IClassFactory *iface) { return 2; }
88 static ULONG WINAPI wmp_class_factory_Release(IClassFactory *iface) { return 1; }
90 static HRESULT WINAPI wmp_class_factory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID iid, void **out)
92 struct decoder_info decoder_info;
93 struct decoder *decoder;
94 HRESULT hr;
96 TRACE("iface %p, outer %p, iid %s, out %p.\n", iface, outer, debugstr_guid(iid), out);
98 *out = NULL;
99 if (outer) return CLASS_E_NOAGGREGATION;
101 hr = get_unix_decoder(&CLSID_WICWmpDecoder, &decoder_info, &decoder);
103 if (SUCCEEDED(hr))
104 hr = CommonDecoder_CreateInstance(decoder, &decoder_info, iid, out);
106 return hr;
109 static HRESULT WINAPI wmp_class_factory_LockServer(IClassFactory *iface, BOOL lock)
111 FIXME("iface %p, lock %d, stub!\n", iface, lock);
112 return S_OK;
115 static const IClassFactoryVtbl wmp_class_factory_vtbl =
117 wmp_class_factory_QueryInterface,
118 wmp_class_factory_AddRef,
119 wmp_class_factory_Release,
120 wmp_class_factory_CreateInstance,
121 wmp_class_factory_LockServer,
124 static struct class_factory wmp_class_factory = {{&wmp_class_factory_vtbl}};
126 HMODULE windowscodecs_module = 0;
128 BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
130 TRACE("instance %p, reason %d, reserved %p\n", instance, reason, reserved);
132 switch (reason)
134 case DLL_PROCESS_ATTACH:
135 windowscodecs_module = instance;
136 DisableThreadLibraryCalls(instance);
137 break;
138 case DLL_WINE_PREATTACH:
139 return FALSE; /* prefer native version */
142 return TRUE;
145 HRESULT WINAPI DllCanUnloadNow(void)
147 return S_FALSE;
150 HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID iid, LPVOID *out)
152 struct class_factory *factory;
154 TRACE("clsid %s, iid %s, out %p.\n", debugstr_guid(clsid), debugstr_guid(iid), out);
156 if (IsEqualGUID(clsid, &CLSID_WICWmpDecoder)) factory = &wmp_class_factory;
157 else
159 FIXME("%s not implemented.\n", debugstr_guid(clsid));
160 return CLASS_E_CLASSNOTAVAILABLE;
163 return IClassFactory_QueryInterface(&factory->IClassFactory_iface, iid, out);
166 HRESULT WINAPI DllRegisterServer(void)
168 return __wine_register_resources( windowscodecs_module );
171 HRESULT WINAPI DllUnregisterServer(void)
173 return __wine_unregister_resources( windowscodecs_module );