Keep track of per-column information inside the listview.
[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
21 #include "winbase.h"
22 #include "winnls.h"
23 #include "winerror.h"
24
25 #include "ole2.h"
26 #include "vfw.h"
27
28 #include "wine/debug.h"
29
30 WINE_DEFAULT_DEBUG_CHANNEL(avifile);
31
32 #include "initguid.h"
33 #include "avifile_private.h"
34
35 HMODULE AVIFILE_hModule   = (HMODULE)NULL;
36
37 BOOL    AVIFILE_bLocked   = FALSE;
38 UINT    AVIFILE_uUseCount = 0;
39
40 static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj);
41 static ULONG   WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface);
42 static ULONG   WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface);
43 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj);
44 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock);
45
46 static ICOM_VTABLE(IClassFactory) iclassfact = {
47   ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
48   IClassFactory_fnQueryInterface,
49   IClassFactory_fnAddRef,
50   IClassFactory_fnRelease,
51   IClassFactory_fnCreateInstance,
52   IClassFactory_fnLockServer
53 };
54
55 typedef struct
56 {
57   /* IUnknown fields */
58   ICOM_VFIELD(IClassFactory);
59   DWORD  dwRef;
60
61   CLSID  clsid;
62 } IClassFactoryImpl;
63
64 static HRESULT AVIFILE_CreateClassFactory(const CLSID *pclsid, const IID *riid,
65                                           LPVOID *ppv)
66 {
67   IClassFactoryImpl *pClassFactory = NULL;
68   HRESULT            hr;
69
70   *ppv = NULL;
71
72   pClassFactory = (IClassFactoryImpl*)LocalAlloc(LPTR, sizeof(*pClassFactory));
73   if (pClassFactory == NULL)
74     return E_OUTOFMEMORY;
75
76   ICOM_VTBL(pClassFactory) = &iclassfact;
77   pClassFactory->dwRef     = 0;
78   memcpy(&pClassFactory->clsid, pclsid, sizeof(pClassFactory->clsid));
79
80   hr = IUnknown_QueryInterface((IUnknown*)pClassFactory, riid, ppv);
81   if (FAILED(hr)) {
82     LocalFree((HLOCAL)pClassFactory);
83     *ppv = NULL;
84   }
85
86   return hr;
87 }
88
89 static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,
90                                                      REFIID riid,LPVOID *ppobj)
91 {
92   TRACE("(%p,%p,%p)\n", iface, riid, ppobj);
93
94   if ((IsEqualGUID(&IID_IUnknown, riid)) ||
95       (IsEqualGUID(&IID_IClassFactory, riid))) {
96     *ppobj = iface;
97     IClassFactory_AddRef(iface);
98     return S_OK;
99   }
100
101   return E_NOINTERFACE;
102 }
103
104 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface)
105 {
106   ICOM_THIS(IClassFactoryImpl,iface);
107
108   TRACE("(%p)\n", iface);
109
110   return ++(This->dwRef);
111 }
112
113 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface)
114 {
115   ICOM_THIS(IClassFactoryImpl,iface);
116
117   TRACE("(%p)\n", iface);
118   if ((--(This->dwRef)) > 0)
119     return This->dwRef;
120
121   return 0;
122 }
123
124 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,
125                                                      LPUNKNOWN pOuter,
126                                                      REFIID riid,LPVOID *ppobj)
127 {
128   ICOM_THIS(IClassFactoryImpl,iface);
129
130   FIXME("(%p,%p,%s,%p): partial stub!\n", iface, pOuter, debugstr_guid(riid),
131         ppobj);
132
133   if (ppobj == NULL || pOuter != NULL)
134     return E_FAIL;
135   *ppobj = NULL;
136
137   if (IsEqualGUID(&CLSID_AVIFile, &This->clsid))
138     return AVIFILE_CreateAVIFile(riid,ppobj);
139 /*   if (IsEqualGUID(&CLSID_ICMStream, &This->clsid)) */
140 /*     return AVIFILE_CreateICMStream(riid,ppobj); */
141   if (IsEqualGUID(&CLSID_WAVFile, &This->clsid))
142     return AVIFILE_CreateWAVFile(riid,ppobj);
143 /*   if (IsEqualGUID(&CLSID_ACMStream, &This->clsid)) */
144 /*     return AVIFILE_CreateACMStream(riid,ppobj); */
145
146   return E_NOINTERFACE;
147 }
148
149 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock)
150 {
151   TRACE("(%p,%d)\n",iface,dolock);
152
153   AVIFILE_bLocked = dolock;
154
155   return S_OK;
156 }
157
158 LPCWSTR AVIFILE_BasenameW(LPCWSTR szPath)
159 {
160 #define SLASH(w) ((w) == '/' || (w) == '\\')
161
162   LPCWSTR szCur;
163
164   for (szCur = szPath + lstrlenW(szPath);
165        szCur > szPath && !SLASH(*szCur) && *szCur != ':';)
166     szCur--;
167
168   if (szCur == szPath)
169     return szCur;
170   else
171     return szCur + 1;
172
173 #undef SLASH
174 }
175
176 /***********************************************************************
177  *              DllGetClassObject (AVIFIL32.@)
178  */
179 HRESULT WINAPI AVIFILE_DllGetClassObject(const CLSID* pclsid,REFIID piid,LPVOID *ppv)
180 {
181   TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid), debugstr_guid(piid), ppv);
182
183   if (pclsid == NULL || piid == NULL || ppv == NULL)
184     return E_FAIL;
185
186   return AVIFILE_CreateClassFactory(pclsid,piid,ppv);
187 }
188
189 /*****************************************************************************
190  *              DllCanUnloadNow         (AVIFIL32.@)
191  */
192 DWORD WINAPI AVIFILE_DllCanUnloadNow(void)
193 {
194   return ((AVIFILE_bLocked || AVIFILE_uUseCount) ? S_FALSE : S_OK);
195 }
196
197 /*****************************************************************************
198  *              AVIFILE_DllMain         [internal]
199  */
200 BOOL WINAPI AVIFILE_DllMain(HINSTANCE hInstDll, DWORD fdwReason,
201                             LPVOID lpvReserved)
202 {
203   TRACE("(%p,%lu,%p)\n", hInstDll, fdwReason, lpvReserved);
204
205   switch (fdwReason) {
206   case DLL_PROCESS_ATTACH:
207     if (AVIFILE_hModule == (HMODULE)NULL)
208       AVIFILE_hModule = (HMODULE)hInstDll;
209     break;
210   case DLL_PROCESS_DETACH:
211     break;
212   case DLL_THREAD_ATTACH:
213     break;
214   case DLL_THREAD_DETACH:
215     break;
216   };
217
218   return TRUE;
219 }