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
= HeapAlloc(GetProcessHeap(), 0, 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 HeapFree(GetProcessHeap(), 0, 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)
127 HeapFree(GetProcessHeap(), 0, This
);
132 static HRESULT WINAPI
IClassFactory_fnCreateInstance(LPCLASSFACTORY iface
,
134 REFIID riid
,LPVOID
*ppobj
)
136 IClassFactoryImpl
*This
= (IClassFactoryImpl
*)iface
;
138 TRACE("(%p,%p,%s,%p)\n", iface
, pOuter
, debugstr_guid(riid
),
141 if (ppobj
== NULL
|| pOuter
!= NULL
)
145 if (IsEqualGUID(&CLSID_AVIFile
, &This
->clsid
))
146 return AVIFILE_CreateAVIFile(riid
,ppobj
);
147 if (IsEqualGUID(&CLSID_ICMStream
, &This
->clsid
))
148 return AVIFILE_CreateICMStream(riid
,ppobj
);
149 if (IsEqualGUID(&CLSID_WAVFile
, &This
->clsid
))
150 return AVIFILE_CreateWAVFile(riid
,ppobj
);
151 if (IsEqualGUID(&CLSID_ACMStream
, &This
->clsid
))
152 return AVIFILE_CreateACMStream(riid
,ppobj
);
154 return E_NOINTERFACE
;
157 static HRESULT WINAPI
IClassFactory_fnLockServer(LPCLASSFACTORY iface
,BOOL dolock
)
159 TRACE("(%p,%d)\n",iface
,dolock
);
161 AVIFILE_bLocked
= dolock
;
166 LPCWSTR
AVIFILE_BasenameW(LPCWSTR szPath
)
168 #define SLASH(w) ((w) == '/' || (w) == '\\')
172 for (szCur
= szPath
+ lstrlenW(szPath
);
173 szCur
> szPath
&& !SLASH(*szCur
) && *szCur
!= ':';)
184 /***********************************************************************
185 * DllGetClassObject (AVIFIL32.@)
187 HRESULT WINAPI
DllGetClassObject(REFCLSID pclsid
, REFIID piid
, LPVOID
*ppv
)
189 TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid
), debugstr_guid(piid
), ppv
);
191 if (pclsid
== NULL
|| piid
== NULL
|| ppv
== NULL
)
194 return AVIFILE_CreateClassFactory(pclsid
,piid
,ppv
);
197 /*****************************************************************************
198 * DllCanUnloadNow (AVIFIL32.@)
200 HRESULT WINAPI
DllCanUnloadNow(void)
202 return ((AVIFILE_bLocked
|| AVIFILE_uUseCount
) ? S_FALSE
: S_OK
);
205 /*****************************************************************************
206 * DllMain [AVIFIL32.init]
208 BOOL WINAPI
DllMain(HINSTANCE hInstDll
, DWORD fdwReason
, LPVOID lpvReserved
)
210 TRACE("(%p,%ld,%p)\n", hInstDll
, fdwReason
, lpvReserved
);
213 case DLL_PROCESS_ATTACH
:
214 DisableThreadLibraryCalls(hInstDll
);
215 AVIFILE_hModule
= (HMODULE
)hInstDll
;
217 case DLL_PROCESS_DETACH
: