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
;
43 IClassFactory IClassFactory_iface
;
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
,
56 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(riid
), ppobj
);
58 if ((IsEqualGUID(&IID_IUnknown
, riid
)) ||
59 (IsEqualGUID(&IID_IClassFactory
, riid
))) {
61 IClassFactory_AddRef(iface
);
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
);
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
);
85 HeapFree(GetProcessHeap(), 0, This
);
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
),
102 if (pOuter
&& !IsEqualGUID(&IID_IUnknown
, riid
))
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
);
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
);
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
;
143 cf
= HeapAlloc(GetProcessHeap(), 0, sizeof(*cf
));
145 return E_OUTOFMEMORY
;
147 cf
->IClassFactory_iface
.lpVtbl
= &iclassfact
;
151 hr
= IClassFactory_QueryInterface(&cf
->IClassFactory_iface
, riid
, ppv
);
152 IClassFactory_Release(&cf
->IClassFactory_iface
);
157 LPCWSTR
AVIFILE_BasenameW(LPCWSTR szPath
)
159 #define SLASH(w) ((w) == '/' || (w) == '\\')
163 for (szCur
= szPath
+ lstrlenW(szPath
);
164 szCur
> szPath
&& !SLASH(*szCur
) && *szCur
!= ':';)
175 /***********************************************************************
176 * DllGetClassObject (AVIFIL32.@)
178 HRESULT WINAPI
DllGetClassObject(REFCLSID pclsid
, REFIID piid
, LPVOID
*ppv
)
182 TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid
), debugstr_guid(piid
), ppv
);
184 if (pclsid
== NULL
|| piid
== NULL
|| ppv
== NULL
)
187 hr
= AVIFILE_CreateClassFactory(pclsid
,piid
,ppv
);
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
);
202 case DLL_PROCESS_ATTACH
:
203 DisableThreadLibraryCalls(hInstDll
);
204 AVIFILE_hModule
= hInstDll
;