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
;
44 static HRESULT WINAPI
IClassFactory_fnQueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
);
45 static ULONG WINAPI
IClassFactory_fnAddRef(LPCLASSFACTORY iface
);
46 static ULONG WINAPI
IClassFactory_fnRelease(LPCLASSFACTORY iface
);
47 static HRESULT WINAPI
IClassFactory_fnCreateInstance(LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
);
48 static HRESULT WINAPI
IClassFactory_fnLockServer(LPCLASSFACTORY iface
,BOOL dolock
);
50 static const IClassFactoryVtbl iclassfact
= {
51 IClassFactory_fnQueryInterface
,
52 IClassFactory_fnAddRef
,
53 IClassFactory_fnRelease
,
54 IClassFactory_fnCreateInstance
,
55 IClassFactory_fnLockServer
61 IClassFactory IClassFactory_iface
;
67 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
69 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
72 static HRESULT
AVIFILE_CreateClassFactory(const CLSID
*pclsid
, const IID
*riid
,
75 IClassFactoryImpl
*pClassFactory
= NULL
;
80 pClassFactory
= HeapAlloc(GetProcessHeap(), 0, sizeof(*pClassFactory
));
81 if (pClassFactory
== NULL
)
84 pClassFactory
->IClassFactory_iface
.lpVtbl
= &iclassfact
;
85 pClassFactory
->dwRef
= 0;
86 pClassFactory
->clsid
= *pclsid
;
88 hr
= IClassFactory_QueryInterface(&pClassFactory
->IClassFactory_iface
, riid
, ppv
);
90 HeapFree(GetProcessHeap(), 0, pClassFactory
);
97 static HRESULT WINAPI
IClassFactory_fnQueryInterface(LPCLASSFACTORY iface
,
98 REFIID riid
,LPVOID
*ppobj
)
100 TRACE("(%p,%p,%p)\n", iface
, riid
, ppobj
);
102 if ((IsEqualGUID(&IID_IUnknown
, riid
)) ||
103 (IsEqualGUID(&IID_IClassFactory
, riid
))) {
105 IClassFactory_AddRef(iface
);
109 return E_NOINTERFACE
;
112 static ULONG WINAPI
IClassFactory_fnAddRef(LPCLASSFACTORY iface
)
114 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
116 TRACE("(%p)\n", iface
);
118 return ++(This
->dwRef
);
121 static ULONG WINAPI
IClassFactory_fnRelease(LPCLASSFACTORY iface
)
123 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
125 TRACE("(%p)\n", iface
);
126 if ((--(This
->dwRef
)) > 0)
129 HeapFree(GetProcessHeap(), 0, This
);
134 static HRESULT WINAPI
IClassFactory_fnCreateInstance(LPCLASSFACTORY iface
,
136 REFIID riid
,LPVOID
*ppobj
)
138 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
140 TRACE("(%p,%p,%s,%p)\n", iface
, pOuter
, debugstr_guid(riid
),
143 if (ppobj
== NULL
|| pOuter
!= NULL
)
147 if (IsEqualGUID(&CLSID_AVIFile
, &This
->clsid
))
148 return AVIFILE_CreateAVIFile(riid
,ppobj
);
149 if (IsEqualGUID(&CLSID_ICMStream
, &This
->clsid
))
150 return AVIFILE_CreateICMStream(riid
,ppobj
);
151 if (IsEqualGUID(&CLSID_WAVFile
, &This
->clsid
))
152 return AVIFILE_CreateWAVFile(riid
,ppobj
);
153 if (IsEqualGUID(&CLSID_ACMStream
, &This
->clsid
))
154 return AVIFILE_CreateACMStream(riid
,ppobj
);
156 return E_NOINTERFACE
;
159 static HRESULT WINAPI
IClassFactory_fnLockServer(LPCLASSFACTORY iface
,BOOL dolock
)
161 TRACE("(%p,%d)\n",iface
,dolock
);
163 AVIFILE_bLocked
= dolock
;
168 LPCWSTR
AVIFILE_BasenameW(LPCWSTR szPath
)
170 #define SLASH(w) ((w) == '/' || (w) == '\\')
174 for (szCur
= szPath
+ lstrlenW(szPath
);
175 szCur
> szPath
&& !SLASH(*szCur
) && *szCur
!= ':';)
186 /***********************************************************************
187 * DllGetClassObject (AVIFIL32.@)
189 HRESULT WINAPI
DllGetClassObject(REFCLSID pclsid
, REFIID piid
, LPVOID
*ppv
)
191 TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid
), debugstr_guid(piid
), ppv
);
193 if (pclsid
== NULL
|| piid
== NULL
|| ppv
== NULL
)
196 return AVIFILE_CreateClassFactory(pclsid
,piid
,ppv
);
199 /*****************************************************************************
200 * DllCanUnloadNow (AVIFIL32.@)
202 HRESULT WINAPI
DllCanUnloadNow(void)
204 return ((AVIFILE_bLocked
|| AVIFILE_uUseCount
) ? S_FALSE
: S_OK
);
207 /*****************************************************************************
208 * DllMain [AVIFIL32.init]
210 BOOL WINAPI
DllMain(HINSTANCE hInstDll
, DWORD fdwReason
, LPVOID lpvReserved
)
212 TRACE("(%p,%d,%p)\n", hInstDll
, fdwReason
, lpvReserved
);
215 case DLL_PROCESS_ATTACH
:
216 DisableThreadLibraryCalls(hInstDll
);
217 AVIFILE_hModule
= hInstDll
;
219 case DLL_PROCESS_DETACH
:
226 /***********************************************************************
227 * DllRegisterServer (AVIFIL32.@)
229 HRESULT WINAPI
DllRegisterServer(void)
231 return __wine_register_resources( AVIFILE_hModule
);
234 /***********************************************************************
235 * DllUnregisterServer (AVIFIL32.@)
237 HRESULT WINAPI
DllUnregisterServer(void)
239 return __wine_unregister_resources( AVIFILE_hModule
);