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 #define WIN32_NO_STATUS
21 #define COM_NO_WINDOWS_H
30 //#include "winuser.h"
31 //#include "winerror.h"
37 #include "avifile_private.h"
39 #include <wine/debug.h>
41 WINE_DEFAULT_DEBUG_CHANNEL(avifile
);
43 HMODULE AVIFILE_hModule
= NULL
;
45 static BOOL AVIFILE_bLocked
;
46 static UINT AVIFILE_uUseCount
;
48 static HRESULT WINAPI
IClassFactory_fnQueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
);
49 static ULONG WINAPI
IClassFactory_fnAddRef(LPCLASSFACTORY iface
);
50 static ULONG WINAPI
IClassFactory_fnRelease(LPCLASSFACTORY iface
);
51 static HRESULT WINAPI
IClassFactory_fnCreateInstance(LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
);
52 static HRESULT WINAPI
IClassFactory_fnLockServer(LPCLASSFACTORY iface
,BOOL dolock
);
54 static const IClassFactoryVtbl iclassfact
= {
55 IClassFactory_fnQueryInterface
,
56 IClassFactory_fnAddRef
,
57 IClassFactory_fnRelease
,
58 IClassFactory_fnCreateInstance
,
59 IClassFactory_fnLockServer
65 IClassFactory IClassFactory_iface
;
71 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
73 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
76 static HRESULT
AVIFILE_CreateClassFactory(const CLSID
*pclsid
, const IID
*riid
,
79 IClassFactoryImpl
*pClassFactory
= NULL
;
84 pClassFactory
= HeapAlloc(GetProcessHeap(), 0, sizeof(*pClassFactory
));
85 if (pClassFactory
== NULL
)
88 pClassFactory
->IClassFactory_iface
.lpVtbl
= &iclassfact
;
89 pClassFactory
->dwRef
= 0;
90 pClassFactory
->clsid
= *pclsid
;
92 hr
= IClassFactory_QueryInterface(&pClassFactory
->IClassFactory_iface
, riid
, ppv
);
94 HeapFree(GetProcessHeap(), 0, pClassFactory
);
101 static HRESULT WINAPI
IClassFactory_fnQueryInterface(LPCLASSFACTORY iface
,
102 REFIID riid
,LPVOID
*ppobj
)
104 TRACE("(%p,%p,%p)\n", iface
, riid
, ppobj
);
106 if ((IsEqualGUID(&IID_IUnknown
, riid
)) ||
107 (IsEqualGUID(&IID_IClassFactory
, riid
))) {
109 IClassFactory_AddRef(iface
);
113 return E_NOINTERFACE
;
116 static ULONG WINAPI
IClassFactory_fnAddRef(LPCLASSFACTORY iface
)
118 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
120 TRACE("(%p)\n", iface
);
122 return ++(This
->dwRef
);
125 static ULONG WINAPI
IClassFactory_fnRelease(LPCLASSFACTORY iface
)
127 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
129 TRACE("(%p)\n", iface
);
130 if ((--(This
->dwRef
)) > 0)
133 HeapFree(GetProcessHeap(), 0, This
);
138 static HRESULT WINAPI
IClassFactory_fnCreateInstance(LPCLASSFACTORY iface
,
140 REFIID riid
,LPVOID
*ppobj
)
142 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
144 TRACE("(%p,%p,%s,%p)\n", iface
, pOuter
, debugstr_guid(riid
),
147 if (ppobj
== NULL
|| pOuter
!= NULL
)
151 if (IsEqualGUID(&CLSID_AVIFile
, &This
->clsid
))
152 return AVIFILE_CreateAVIFile(riid
,ppobj
);
153 if (IsEqualGUID(&CLSID_ICMStream
, &This
->clsid
))
154 return AVIFILE_CreateICMStream(riid
,ppobj
);
155 if (IsEqualGUID(&CLSID_WAVFile
, &This
->clsid
))
156 return AVIFILE_CreateWAVFile(riid
,ppobj
);
157 if (IsEqualGUID(&CLSID_ACMStream
, &This
->clsid
))
158 return AVIFILE_CreateACMStream(riid
,ppobj
);
160 return E_NOINTERFACE
;
163 static HRESULT WINAPI
IClassFactory_fnLockServer(LPCLASSFACTORY iface
,BOOL dolock
)
165 TRACE("(%p,%d)\n",iface
,dolock
);
167 AVIFILE_bLocked
= dolock
;
172 LPCWSTR
AVIFILE_BasenameW(LPCWSTR szPath
)
174 #define SLASH(w) ((w) == '/' || (w) == '\\')
178 for (szCur
= szPath
+ lstrlenW(szPath
);
179 szCur
> szPath
&& !SLASH(*szCur
) && *szCur
!= ':';)
190 /***********************************************************************
191 * DllGetClassObject (AVIFIL32.@)
193 HRESULT WINAPI
DllGetClassObject(REFCLSID pclsid
, REFIID piid
, LPVOID
*ppv
)
195 TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid
), debugstr_guid(piid
), ppv
);
197 if (pclsid
== NULL
|| piid
== NULL
|| ppv
== NULL
)
200 return AVIFILE_CreateClassFactory(pclsid
,piid
,ppv
);
203 /*****************************************************************************
204 * DllCanUnloadNow (AVIFIL32.@)
206 HRESULT WINAPI
DllCanUnloadNow(void)
208 return ((AVIFILE_bLocked
|| AVIFILE_uUseCount
) ? S_FALSE
: S_OK
);
211 /*****************************************************************************
212 * DllMain [AVIFIL32.init]
214 BOOL WINAPI
DllMain(HINSTANCE hInstDll
, DWORD fdwReason
, LPVOID lpvReserved
)
216 TRACE("(%p,%d,%p)\n", hInstDll
, fdwReason
, lpvReserved
);
219 case DLL_PROCESS_ATTACH
:
220 DisableThreadLibraryCalls(hInstDll
);
221 AVIFILE_hModule
= hInstDll
;
223 case DLL_PROCESS_DETACH
:
230 /***********************************************************************
231 * DllRegisterServer (AVIFIL32.@)
233 HRESULT WINAPI
DllRegisterServer(void)
235 return __wine_register_resources( AVIFILE_hModule
);
238 /***********************************************************************
239 * DllUnregisterServer (AVIFIL32.@)
241 HRESULT WINAPI
DllUnregisterServer(void)
243 return __wine_unregister_resources( AVIFILE_hModule
);