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 "avifile_private.h"
23 HMODULE AVIFILE_hModule
= NULL
;
25 static BOOL AVIFILE_bLocked
;
26 static UINT AVIFILE_uUseCount
;
28 static HRESULT WINAPI
IClassFactory_fnQueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
);
29 static ULONG WINAPI
IClassFactory_fnAddRef(LPCLASSFACTORY iface
);
30 static ULONG WINAPI
IClassFactory_fnRelease(LPCLASSFACTORY iface
);
31 static HRESULT WINAPI
IClassFactory_fnCreateInstance(LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
);
32 static HRESULT WINAPI
IClassFactory_fnLockServer(LPCLASSFACTORY iface
,BOOL dolock
);
34 static const IClassFactoryVtbl iclassfact
= {
35 IClassFactory_fnQueryInterface
,
36 IClassFactory_fnAddRef
,
37 IClassFactory_fnRelease
,
38 IClassFactory_fnCreateInstance
,
39 IClassFactory_fnLockServer
45 IClassFactory IClassFactory_iface
;
51 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
53 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
56 static HRESULT
AVIFILE_CreateClassFactory(const CLSID
*pclsid
, const IID
*riid
,
59 IClassFactoryImpl
*pClassFactory
= NULL
;
64 pClassFactory
= HeapAlloc(GetProcessHeap(), 0, sizeof(*pClassFactory
));
65 if (pClassFactory
== NULL
)
68 pClassFactory
->IClassFactory_iface
.lpVtbl
= &iclassfact
;
69 pClassFactory
->dwRef
= 0;
70 pClassFactory
->clsid
= *pclsid
;
72 hr
= IClassFactory_QueryInterface(&pClassFactory
->IClassFactory_iface
, riid
, ppv
);
74 HeapFree(GetProcessHeap(), 0, pClassFactory
);
81 static HRESULT WINAPI
IClassFactory_fnQueryInterface(LPCLASSFACTORY iface
,
82 REFIID riid
,LPVOID
*ppobj
)
84 TRACE("(%p,%p,%p)\n", iface
, riid
, ppobj
);
86 if ((IsEqualGUID(&IID_IUnknown
, riid
)) ||
87 (IsEqualGUID(&IID_IClassFactory
, riid
))) {
89 IClassFactory_AddRef(iface
);
96 static ULONG WINAPI
IClassFactory_fnAddRef(LPCLASSFACTORY iface
)
98 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
100 TRACE("(%p)\n", iface
);
102 return ++(This
->dwRef
);
105 static ULONG WINAPI
IClassFactory_fnRelease(LPCLASSFACTORY iface
)
107 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
109 TRACE("(%p)\n", iface
);
110 if ((--(This
->dwRef
)) > 0)
113 HeapFree(GetProcessHeap(), 0, This
);
118 static HRESULT WINAPI
IClassFactory_fnCreateInstance(LPCLASSFACTORY iface
,
120 REFIID riid
,LPVOID
*ppobj
)
122 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
124 TRACE("(%p,%p,%s,%p)\n", iface
, pOuter
, debugstr_guid(riid
),
131 if (pOuter
&& !IsEqualGUID(&IID_IUnknown
, riid
))
134 if (IsEqualGUID(&CLSID_AVIFile
, &This
->clsid
))
135 return AVIFILE_CreateAVIFile(pOuter
, riid
, ppobj
);
136 if (IsEqualGUID(&CLSID_WAVFile
, &This
->clsid
))
137 return AVIFILE_CreateWAVFile(pOuter
, riid
, ppobj
);
140 return CLASS_E_NOAGGREGATION
;
142 if (IsEqualGUID(&CLSID_ICMStream
, &This
->clsid
))
143 return AVIFILE_CreateICMStream(riid
,ppobj
);
144 if (IsEqualGUID(&CLSID_ACMStream
, &This
->clsid
))
145 return AVIFILE_CreateACMStream(riid
,ppobj
);
147 return E_NOINTERFACE
;
150 static HRESULT WINAPI
IClassFactory_fnLockServer(LPCLASSFACTORY iface
,BOOL dolock
)
152 TRACE("(%p,%d)\n",iface
,dolock
);
154 AVIFILE_bLocked
= dolock
;
159 LPCWSTR
AVIFILE_BasenameW(LPCWSTR szPath
)
161 #define SLASH(w) ((w) == '/' || (w) == '\\')
165 for (szCur
= szPath
+ lstrlenW(szPath
);
166 szCur
> szPath
&& !SLASH(*szCur
) && *szCur
!= ':';)
177 /***********************************************************************
178 * DllGetClassObject (AVIFIL32.@)
180 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 return AVIFILE_CreateClassFactory(pclsid
,piid
,ppv
);
190 /*****************************************************************************
191 * DllCanUnloadNow (AVIFIL32.@)
193 HRESULT WINAPI
DllCanUnloadNow(void)
195 return ((AVIFILE_bLocked
|| AVIFILE_uUseCount
) ? S_FALSE
: S_OK
);
198 /*****************************************************************************
199 * DllMain [AVIFIL32.init]
201 BOOL WINAPI
DllMain(HINSTANCE hInstDll
, DWORD fdwReason
, LPVOID lpvReserved
)
203 TRACE("(%p,%d,%p)\n", hInstDll
, fdwReason
, lpvReserved
);
206 case DLL_PROCESS_ATTACH
:
207 DisableThreadLibraryCalls(hInstDll
);
208 AVIFILE_hModule
= hInstDll
;
215 /***********************************************************************
216 * DllRegisterServer (AVIFIL32.@)
218 HRESULT WINAPI
DllRegisterServer(void)
220 return __wine_register_resources( AVIFILE_hModule
);
223 /***********************************************************************
224 * DllUnregisterServer (AVIFIL32.@)
226 HRESULT WINAPI
DllUnregisterServer(void)
228 return __wine_unregister_resources( AVIFILE_hModule
);