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
33 #include "avifile_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(avifile
);
39 HMODULE AVIFILE_hModule
= NULL
;
41 static BOOL AVIFILE_bLocked
;
42 static UINT AVIFILE_uUseCount
;
46 IClassFactory IClassFactory_iface
;
51 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
53 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
56 static HRESULT WINAPI
IClassFactory_fnQueryInterface(IClassFactory
*iface
, REFIID riid
,
59 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(riid
), ppobj
);
61 if ((IsEqualGUID(&IID_IUnknown
, riid
)) ||
62 (IsEqualGUID(&IID_IClassFactory
, riid
))) {
64 IClassFactory_AddRef(iface
);
71 static ULONG WINAPI
IClassFactory_fnAddRef(IClassFactory
*iface
)
73 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
74 ULONG ref
= InterlockedIncrement(&This
->ref
);
76 TRACE("(%p) ref = %u\n", This
, ref
);
80 static ULONG WINAPI
IClassFactory_fnRelease(IClassFactory
*iface
)
82 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
83 ULONG ref
= InterlockedDecrement(&This
->ref
);
85 TRACE("(%p) ref = %u\n", This
, ref
);
88 HeapFree(GetProcessHeap(), 0, This
);
93 static HRESULT WINAPI
IClassFactory_fnCreateInstance(IClassFactory
*iface
, IUnknown
*pOuter
,
94 REFIID riid
, void **ppobj
)
96 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
98 TRACE("(%p,%p,%s,%p)\n", iface
, pOuter
, debugstr_guid(riid
),
105 if (pOuter
&& !IsEqualGUID(&IID_IUnknown
, riid
))
108 if (IsEqualGUID(&CLSID_AVIFile
, &This
->clsid
))
109 return AVIFILE_CreateAVIFile(pOuter
, riid
, ppobj
);
110 if (IsEqualGUID(&CLSID_WAVFile
, &This
->clsid
))
111 return AVIFILE_CreateWAVFile(pOuter
, riid
, ppobj
);
114 return CLASS_E_NOAGGREGATION
;
116 if (IsEqualGUID(&CLSID_ICMStream
, &This
->clsid
))
117 return AVIFILE_CreateICMStream(riid
,ppobj
);
118 if (IsEqualGUID(&CLSID_ACMStream
, &This
->clsid
))
119 return AVIFILE_CreateACMStream(riid
,ppobj
);
121 return E_NOINTERFACE
;
124 static HRESULT WINAPI
IClassFactory_fnLockServer(IClassFactory
*iface
, BOOL dolock
)
126 TRACE("(%p,%d)\n",iface
,dolock
);
128 AVIFILE_bLocked
= dolock
;
133 static const IClassFactoryVtbl iclassfact
= {
134 IClassFactory_fnQueryInterface
,
135 IClassFactory_fnAddRef
,
136 IClassFactory_fnRelease
,
137 IClassFactory_fnCreateInstance
,
138 IClassFactory_fnLockServer
141 static HRESULT
AVIFILE_CreateClassFactory(const CLSID
*clsid
, const IID
*riid
, void **ppv
)
143 IClassFactoryImpl
*cf
;
148 cf
= HeapAlloc(GetProcessHeap(), 0, sizeof(*cf
));
150 return E_OUTOFMEMORY
;
152 cf
->IClassFactory_iface
.lpVtbl
= &iclassfact
;
156 hr
= IClassFactory_QueryInterface(&cf
->IClassFactory_iface
, riid
, ppv
);
157 IClassFactory_Release(&cf
->IClassFactory_iface
);
162 LPCWSTR
AVIFILE_BasenameW(LPCWSTR szPath
)
164 #define SLASH(w) ((w) == '/' || (w) == '\\')
168 for (szCur
= szPath
+ lstrlenW(szPath
);
169 szCur
> szPath
&& !SLASH(*szCur
) && *szCur
!= ':';)
180 /***********************************************************************
181 * DllGetClassObject (AVIFIL32.@)
183 HRESULT WINAPI
DllGetClassObject(REFCLSID pclsid
, REFIID piid
, LPVOID
*ppv
)
185 TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid
), debugstr_guid(piid
), ppv
);
187 if (pclsid
== NULL
|| piid
== NULL
|| ppv
== NULL
)
190 return AVIFILE_CreateClassFactory(pclsid
,piid
,ppv
);
193 /*****************************************************************************
194 * DllCanUnloadNow (AVIFIL32.@)
196 HRESULT WINAPI
DllCanUnloadNow(void)
198 return ((AVIFILE_bLocked
|| AVIFILE_uUseCount
) ? S_FALSE
: S_OK
);
201 /*****************************************************************************
202 * DllMain [AVIFIL32.init]
204 BOOL WINAPI
DllMain(HINSTANCE hInstDll
, DWORD fdwReason
, LPVOID lpvReserved
)
206 TRACE("(%p,%d,%p)\n", hInstDll
, fdwReason
, lpvReserved
);
209 case DLL_PROCESS_ATTACH
:
210 DisableThreadLibraryCalls(hInstDll
);
211 AVIFILE_hModule
= hInstDll
;
218 /***********************************************************************
219 * DllRegisterServer (AVIFIL32.@)
221 HRESULT WINAPI
DllRegisterServer(void)
223 return __wine_register_resources( AVIFILE_hModule
);
226 /***********************************************************************
227 * DllUnregisterServer (AVIFIL32.@)
229 HRESULT WINAPI
DllUnregisterServer(void)
231 return __wine_unregister_resources( AVIFILE_hModule
);