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
),
151 if (pOuter
&& !IsEqualGUID(&IID_IUnknown
, riid
))
154 if (IsEqualGUID(&CLSID_AVIFile
, &This
->clsid
))
155 return AVIFILE_CreateAVIFile(pOuter
, riid
, ppobj
);
158 return CLASS_E_NOAGGREGATION
;
160 if (IsEqualGUID(&CLSID_ICMStream
, &This
->clsid
))
161 return AVIFILE_CreateICMStream(riid
,ppobj
);
162 if (IsEqualGUID(&CLSID_WAVFile
, &This
->clsid
))
163 return AVIFILE_CreateWAVFile(riid
,ppobj
);
164 if (IsEqualGUID(&CLSID_ACMStream
, &This
->clsid
))
165 return AVIFILE_CreateACMStream(riid
,ppobj
);
167 return E_NOINTERFACE
;
170 static HRESULT WINAPI
IClassFactory_fnLockServer(LPCLASSFACTORY iface
,BOOL dolock
)
172 TRACE("(%p,%d)\n",iface
,dolock
);
174 AVIFILE_bLocked
= dolock
;
179 LPCWSTR
AVIFILE_BasenameW(LPCWSTR szPath
)
181 #define SLASH(w) ((w) == '/' || (w) == '\\')
185 for (szCur
= szPath
+ lstrlenW(szPath
);
186 szCur
> szPath
&& !SLASH(*szCur
) && *szCur
!= ':';)
197 /***********************************************************************
198 * DllGetClassObject (AVIFIL32.@)
200 HRESULT WINAPI
DllGetClassObject(REFCLSID pclsid
, REFIID piid
, LPVOID
*ppv
)
202 TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid
), debugstr_guid(piid
), ppv
);
204 if (pclsid
== NULL
|| piid
== NULL
|| ppv
== NULL
)
207 return AVIFILE_CreateClassFactory(pclsid
,piid
,ppv
);
210 /*****************************************************************************
211 * DllCanUnloadNow (AVIFIL32.@)
213 HRESULT WINAPI
DllCanUnloadNow(void)
215 return ((AVIFILE_bLocked
|| AVIFILE_uUseCount
) ? S_FALSE
: S_OK
);
218 /*****************************************************************************
219 * DllMain [AVIFIL32.init]
221 BOOL WINAPI
DllMain(HINSTANCE hInstDll
, DWORD fdwReason
, LPVOID lpvReserved
)
223 TRACE("(%p,%d,%p)\n", hInstDll
, fdwReason
, lpvReserved
);
226 case DLL_PROCESS_ATTACH
:
227 DisableThreadLibraryCalls(hInstDll
);
228 AVIFILE_hModule
= hInstDll
;
235 /***********************************************************************
236 * DllRegisterServer (AVIFIL32.@)
238 HRESULT WINAPI
DllRegisterServer(void)
240 return __wine_register_resources( AVIFILE_hModule
);
243 /***********************************************************************
244 * DllUnregisterServer (AVIFIL32.@)
246 HRESULT WINAPI
DllUnregisterServer(void)
248 return __wine_unregister_resources( AVIFILE_hModule
);