msvcrt: Fix strtof() error reporting for values out of float range.
[wine.git] / dlls / avifil32 / factory.c
blob820c882eaac8dd97830ca1105f7a0c1b5f87bce2
1 /*
2 * Copyright 2002 Michael Günnewig
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 <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "winerror.h"
28 #include "ole2.h"
29 #include "rpcproxy.h"
31 #include "initguid.h"
32 #include "vfw.h"
33 #include "avifile_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(avifile);
39 HMODULE AVIFILE_hModule = NULL;
41 typedef struct
43 IClassFactory IClassFactory_iface;
44 LONG ref;
45 CLSID clsid;
46 } IClassFactoryImpl;
48 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
50 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
53 static HRESULT WINAPI IClassFactory_fnQueryInterface(IClassFactory *iface, REFIID riid,
54 void **ppobj)
56 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(riid), ppobj);
58 if ((IsEqualGUID(&IID_IUnknown, riid)) ||
59 (IsEqualGUID(&IID_IClassFactory, riid))) {
60 *ppobj = iface;
61 IClassFactory_AddRef(iface);
62 return S_OK;
65 return E_NOINTERFACE;
68 static ULONG WINAPI IClassFactory_fnAddRef(IClassFactory *iface)
70 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
71 ULONG ref = InterlockedIncrement(&This->ref);
73 TRACE("(%p) ref = %u\n", This, ref);
74 return ref;
77 static ULONG WINAPI IClassFactory_fnRelease(IClassFactory *iface)
79 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
80 ULONG ref = InterlockedDecrement(&This->ref);
82 TRACE("(%p) ref = %u\n", This, ref);
84 if(!ref)
85 HeapFree(GetProcessHeap(), 0, This);
87 return ref;
90 static HRESULT WINAPI IClassFactory_fnCreateInstance(IClassFactory *iface, IUnknown *pOuter,
91 REFIID riid, void **ppobj)
93 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
95 TRACE("(%p,%p,%s,%p)\n", iface, pOuter, debugstr_guid(riid),
96 ppobj);
98 if (!ppobj)
99 return E_INVALIDARG;
100 *ppobj = NULL;
102 if (pOuter && !IsEqualGUID(&IID_IUnknown, riid))
103 return E_INVALIDARG;
105 if (IsEqualGUID(&CLSID_AVIFile, &This->clsid))
106 return AVIFILE_CreateAVIFile(pOuter, riid, ppobj);
107 if (IsEqualGUID(&CLSID_WAVFile, &This->clsid))
108 return AVIFILE_CreateWAVFile(pOuter, riid, ppobj);
110 if (pOuter)
111 return CLASS_E_NOAGGREGATION;
113 if (IsEqualGUID(&CLSID_ICMStream, &This->clsid))
114 return AVIFILE_CreateICMStream(riid,ppobj);
115 if (IsEqualGUID(&CLSID_ACMStream, &This->clsid))
116 return AVIFILE_CreateACMStream(riid,ppobj);
118 return E_NOINTERFACE;
121 static HRESULT WINAPI IClassFactory_fnLockServer(IClassFactory *iface, BOOL dolock)
123 TRACE("(%p,%d)\n",iface,dolock);
125 return S_OK;
128 static const IClassFactoryVtbl iclassfact = {
129 IClassFactory_fnQueryInterface,
130 IClassFactory_fnAddRef,
131 IClassFactory_fnRelease,
132 IClassFactory_fnCreateInstance,
133 IClassFactory_fnLockServer
136 static HRESULT AVIFILE_CreateClassFactory(const CLSID *clsid, const IID *riid, void **ppv)
138 IClassFactoryImpl *cf;
139 HRESULT hr;
141 *ppv = NULL;
143 cf = HeapAlloc(GetProcessHeap(), 0, sizeof(*cf));
144 if (!cf)
145 return E_OUTOFMEMORY;
147 cf->IClassFactory_iface.lpVtbl = &iclassfact;
148 cf->ref = 1;
149 cf->clsid = *clsid;
151 hr = IClassFactory_QueryInterface(&cf->IClassFactory_iface, riid, ppv);
152 IClassFactory_Release(&cf->IClassFactory_iface);
154 return hr;
157 LPCWSTR AVIFILE_BasenameW(LPCWSTR szPath)
159 #define SLASH(w) ((w) == '/' || (w) == '\\')
161 LPCWSTR szCur;
163 for (szCur = szPath + lstrlenW(szPath);
164 szCur > szPath && !SLASH(*szCur) && *szCur != ':';)
165 szCur--;
167 if (szCur == szPath)
168 return szCur;
169 else
170 return szCur + 1;
172 #undef SLASH
175 /***********************************************************************
176 * DllGetClassObject (AVIFIL32.@)
178 HRESULT WINAPI DllGetClassObject(REFCLSID pclsid, REFIID piid, LPVOID *ppv)
180 HRESULT hr;
182 TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid), debugstr_guid(piid), ppv);
184 if (pclsid == NULL || piid == NULL || ppv == NULL)
185 return E_FAIL;
187 hr = AVIFILE_CreateClassFactory(pclsid,piid,ppv);
188 if (SUCCEEDED(hr))
189 return hr;
191 return avifil32_DllGetClassObject(pclsid,piid,ppv);
194 /*****************************************************************************
195 * DllMain [AVIFIL32.init]
197 BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
199 TRACE("(%p,%d,%p)\n", hInstDll, fdwReason, lpvReserved);
201 switch (fdwReason) {
202 case DLL_PROCESS_ATTACH:
203 DisableThreadLibraryCalls(hInstDll);
204 AVIFILE_hModule = hInstDll;
205 break;
208 return TRUE;