Return OLE automation build value as win2k by default.
[wine] / dlls / avifil32 / factory.c
1 /*
2  * Copyright 2002 Michael Günnewig
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <assert.h>
20 #include <stdarg.h>
21
22 #define COBJMACROS
23 #define COM_NO_WINDOWS_H
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "winnls.h"
30 #include "winerror.h"
31
32 #include "ole2.h"
33 #include "vfw.h"
34
35 #include "wine/debug.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(avifile);
38
39 #include "initguid.h"
40 #include "avifile_private.h"
41
42 HMODULE AVIFILE_hModule   = NULL;
43
44 BOOL    AVIFILE_bLocked   = FALSE;
45 UINT    AVIFILE_uUseCount = 0;
46
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);
52
53 static IClassFactoryVtbl iclassfact = {
54   IClassFactory_fnQueryInterface,
55   IClassFactory_fnAddRef,
56   IClassFactory_fnRelease,
57   IClassFactory_fnCreateInstance,
58   IClassFactory_fnLockServer
59 };
60
61 typedef struct
62 {
63   /* IUnknown fields */
64   IClassFactoryVtbl *lpVtbl;
65   DWORD  dwRef;
66
67   CLSID  clsid;
68 } IClassFactoryImpl;
69
70 static HRESULT AVIFILE_CreateClassFactory(const CLSID *pclsid, const IID *riid,
71                                           LPVOID *ppv)
72 {
73   IClassFactoryImpl *pClassFactory = NULL;
74   HRESULT            hr;
75
76   *ppv = NULL;
77
78   pClassFactory = (IClassFactoryImpl*)LocalAlloc(LPTR, sizeof(*pClassFactory));
79   if (pClassFactory == NULL)
80     return E_OUTOFMEMORY;
81
82   pClassFactory->lpVtbl    = &iclassfact;
83   pClassFactory->dwRef     = 0;
84   memcpy(&pClassFactory->clsid, pclsid, sizeof(pClassFactory->clsid));
85
86   hr = IClassFactory_QueryInterface((IClassFactory*)pClassFactory, riid, ppv);
87   if (FAILED(hr)) {
88     LocalFree((HLOCAL)pClassFactory);
89     *ppv = NULL;
90   }
91
92   return hr;
93 }
94
95 static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,
96                                                      REFIID riid,LPVOID *ppobj)
97 {
98   TRACE("(%p,%p,%p)\n", iface, riid, ppobj);
99
100   if ((IsEqualGUID(&IID_IUnknown, riid)) ||
101       (IsEqualGUID(&IID_IClassFactory, riid))) {
102     *ppobj = iface;
103     IClassFactory_AddRef(iface);
104     return S_OK;
105   }
106
107   return E_NOINTERFACE;
108 }
109
110 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface)
111 {
112   IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
113
114   TRACE("(%p)\n", iface);
115
116   return ++(This->dwRef);
117 }
118
119 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface)
120 {
121   IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
122
123   TRACE("(%p)\n", iface);
124   if ((--(This->dwRef)) > 0)
125     return This->dwRef;
126
127   return 0;
128 }
129
130 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,
131                                                      LPUNKNOWN pOuter,
132                                                      REFIID riid,LPVOID *ppobj)
133 {
134   IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
135
136   TRACE("(%p,%p,%s,%p)\n", iface, pOuter, debugstr_guid(riid),
137         ppobj);
138
139   if (ppobj == NULL || pOuter != NULL)
140     return E_FAIL;
141   *ppobj = NULL;
142
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);
151
152   return E_NOINTERFACE;
153 }
154
155 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock)
156 {
157   TRACE("(%p,%d)\n",iface,dolock);
158
159   AVIFILE_bLocked = dolock;
160
161   return S_OK;
162 }
163
164 LPCWSTR AVIFILE_BasenameW(LPCWSTR szPath)
165 {
166 #define SLASH(w) ((w) == '/' || (w) == '\\')
167
168   LPCWSTR szCur;
169
170   for (szCur = szPath + lstrlenW(szPath);
171        szCur > szPath && !SLASH(*szCur) && *szCur != ':';)
172     szCur--;
173
174   if (szCur == szPath)
175     return szCur;
176   else
177     return szCur + 1;
178
179 #undef SLASH
180 }
181
182 /***********************************************************************
183  *              DllGetClassObject (AVIFIL32.@)
184  */
185 HRESULT WINAPI AVIFILE_DllGetClassObject(const CLSID* pclsid,REFIID piid,LPVOID *ppv)
186 {
187   TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid), debugstr_guid(piid), ppv);
188
189   if (pclsid == NULL || piid == NULL || ppv == NULL)
190     return E_FAIL;
191
192   return AVIFILE_CreateClassFactory(pclsid,piid,ppv);
193 }
194
195 /*****************************************************************************
196  *              DllCanUnloadNow         (AVIFIL32.@)
197  */
198 DWORD WINAPI AVIFILE_DllCanUnloadNow(void)
199 {
200   return ((AVIFILE_bLocked || AVIFILE_uUseCount) ? S_FALSE : S_OK);
201 }
202
203 /*****************************************************************************
204  *              DllMain         [AVIFIL32.init]
205  */
206 BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
207 {
208   TRACE("(%p,%lu,%p)\n", hInstDll, fdwReason, lpvReserved);
209
210   switch (fdwReason) {
211   case DLL_PROCESS_ATTACH:
212     DisableThreadLibraryCalls(hInstDll);
213     AVIFILE_hModule = (HMODULE)hInstDll;
214     break;
215   case DLL_PROCESS_DETACH:
216     break;
217   };
218
219   return TRUE;
220 }