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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #define COM_NO_WINDOWS_H
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(avifile
);
40 #include "avifile_private.h"
42 HMODULE AVIFILE_hModule
= NULL
;
44 BOOL AVIFILE_bLocked
= FALSE
;
45 UINT AVIFILE_uUseCount
= 0;
47 static HRESULT WINAPI
IClassFactory_fnQueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
);
48 static ULONG WINAPI
IClassFactory_fnAddRef(LPCLASSFACTORY iface
);
49 static ULONG WINAPI
IClassFactory_fnRelease(LPCLASSFACTORY iface
);
50 static HRESULT WINAPI
IClassFactory_fnCreateInstance(LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
);
51 static HRESULT WINAPI
IClassFactory_fnLockServer(LPCLASSFACTORY iface
,BOOL dolock
);
53 static const IClassFactoryVtbl iclassfact
= {
54 IClassFactory_fnQueryInterface
,
55 IClassFactory_fnAddRef
,
56 IClassFactory_fnRelease
,
57 IClassFactory_fnCreateInstance
,
58 IClassFactory_fnLockServer
64 const IClassFactoryVtbl
*lpVtbl
;
70 static HRESULT
AVIFILE_CreateClassFactory(const CLSID
*pclsid
, const IID
*riid
,
73 IClassFactoryImpl
*pClassFactory
= NULL
;
78 pClassFactory
= (IClassFactoryImpl
*)LocalAlloc(LPTR
, sizeof(*pClassFactory
));
79 if (pClassFactory
== NULL
)
82 pClassFactory
->lpVtbl
= &iclassfact
;
83 pClassFactory
->dwRef
= 0;
84 memcpy(&pClassFactory
->clsid
, pclsid
, sizeof(pClassFactory
->clsid
));
86 hr
= IClassFactory_QueryInterface((IClassFactory
*)pClassFactory
, riid
, ppv
);
88 LocalFree((HLOCAL
)pClassFactory
);
95 static HRESULT WINAPI
IClassFactory_fnQueryInterface(LPCLASSFACTORY iface
,
96 REFIID riid
,LPVOID
*ppobj
)
98 TRACE("(%p,%p,%p)\n", iface
, riid
, ppobj
);
100 if ((IsEqualGUID(&IID_IUnknown
, riid
)) ||
101 (IsEqualGUID(&IID_IClassFactory
, riid
))) {
103 IClassFactory_AddRef(iface
);
107 return E_NOINTERFACE
;
110 static ULONG WINAPI
IClassFactory_fnAddRef(LPCLASSFACTORY iface
)
112 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
114 TRACE("(%p)\n", iface
);
116 return ++(This
->dwRef
);
119 static ULONG WINAPI
IClassFactory_fnRelease(LPCLASSFACTORY iface
)
121 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
123 TRACE("(%p)\n", iface
);
124 if ((--(This
->dwRef
)) > 0)
130 static HRESULT WINAPI
IClassFactory_fnCreateInstance(LPCLASSFACTORY iface
,
132 REFIID riid
,LPVOID
*ppobj
)
134 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
136 TRACE("(%p,%p,%s,%p)\n", iface
, pOuter
, debugstr_guid(riid
),
139 if (ppobj
== NULL
|| pOuter
!= NULL
)
143 if (IsEqualGUID(&CLSID_AVIFile
, &This
->clsid
))
144 return AVIFILE_CreateAVIFile(riid
,ppobj
);
145 if (IsEqualGUID(&CLSID_ICMStream
, &This
->clsid
))
146 return AVIFILE_CreateICMStream(riid
,ppobj
);
147 if (IsEqualGUID(&CLSID_WAVFile
, &This
->clsid
))
148 return AVIFILE_CreateWAVFile(riid
,ppobj
);
149 if (IsEqualGUID(&CLSID_ACMStream
, &This
->clsid
))
150 return AVIFILE_CreateACMStream(riid
,ppobj
);
152 return E_NOINTERFACE
;
155 static HRESULT WINAPI
IClassFactory_fnLockServer(LPCLASSFACTORY iface
,BOOL dolock
)
157 TRACE("(%p,%d)\n",iface
,dolock
);
159 AVIFILE_bLocked
= dolock
;
164 LPCWSTR
AVIFILE_BasenameW(LPCWSTR szPath
)
166 #define SLASH(w) ((w) == '/' || (w) == '\\')
170 for (szCur
= szPath
+ lstrlenW(szPath
);
171 szCur
> szPath
&& !SLASH(*szCur
) && *szCur
!= ':';)
182 /***********************************************************************
183 * DllGetClassObject (AVIFIL32.@)
185 HRESULT WINAPI
DllGetClassObject(REFCLSID pclsid
, REFIID piid
, LPVOID
*ppv
)
187 TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid
), debugstr_guid(piid
), ppv
);
189 if (pclsid
== NULL
|| piid
== NULL
|| ppv
== NULL
)
192 return AVIFILE_CreateClassFactory(pclsid
,piid
,ppv
);
195 /*****************************************************************************
196 * DllCanUnloadNow (AVIFIL32.@)
198 HRESULT WINAPI
DllCanUnloadNow(void)
200 return ((AVIFILE_bLocked
|| AVIFILE_uUseCount
) ? S_FALSE
: S_OK
);
203 /*****************************************************************************
204 * DllMain [AVIFIL32.init]
206 BOOL WINAPI
DllMain(HINSTANCE hInstDll
, DWORD fdwReason
, LPVOID lpvReserved
)
208 TRACE("(%p,%ld,%p)\n", hInstDll
, fdwReason
, lpvReserved
);
211 case DLL_PROCESS_ATTACH
:
212 DisableThreadLibraryCalls(hInstDll
);
213 AVIFILE_hModule
= (HMODULE
)hInstDll
;
215 case DLL_PROCESS_DETACH
: