* Sync up to trunk HEAD (r62502).
[reactos.git] / dll / win32 / sti / sti.c
1 /*
2 * Copyright (C) 2002 Aric Stewart for CodeWeavers
3 * Copyright (C) 2009 Damjan Jovanovic
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #include "precomp.h"
21
22 #include <winreg.h>
23
24 #include <wine/unicode.h>
25
26 static const WCHAR registeredAppsLaunchPath[] = {
27 'S','O','F','T','W','A','R','E','\\',
28 'M','i','c','r','o','s','o','f','t','\\',
29 'W','i','n','d','o','w','s','\\',
30 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
31 'S','t','i','l','l','I','m','a','g','e','\\',
32 'R','e','g','i','s','t','e','r','e','d',' ','A','p','p','l','i','c','a','t','i','o','n','s',0
33 };
34
35 typedef struct _stillimage
36 {
37 IStillImageW IStillImageW_iface;
38 IUnknown IUnknown_iface;
39 IUnknown *pUnkOuter;
40 LONG ref;
41 } stillimage;
42
43 static inline stillimage *impl_from_IStillImageW(IStillImageW *iface)
44 {
45 return CONTAINING_RECORD(iface, stillimage, IStillImageW_iface);
46 }
47
48 static HRESULT WINAPI stillimagew_QueryInterface(IStillImageW *iface, REFIID riid, void **ppvObject)
49 {
50 stillimage *This = impl_from_IStillImageW(iface);
51 TRACE("(%p %s %p)\n", This, debugstr_guid(riid), ppvObject);
52 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
53 }
54
55 static ULONG WINAPI stillimagew_AddRef(IStillImageW *iface)
56 {
57 stillimage *This = impl_from_IStillImageW(iface);
58 return IUnknown_AddRef(This->pUnkOuter);
59 }
60
61 static ULONG WINAPI stillimagew_Release(IStillImageW *iface)
62 {
63 stillimage *This = impl_from_IStillImageW(iface);
64 return IUnknown_Release(This->pUnkOuter);
65 }
66
67 static HRESULT WINAPI stillimagew_Initialize(IStillImageW *iface, HINSTANCE hinst, DWORD dwVersion)
68 {
69 stillimage *This = impl_from_IStillImageW(iface);
70 TRACE("(%p, %p, 0x%X)\n", This, hinst, dwVersion);
71 return S_OK;
72 }
73
74 static HRESULT WINAPI stillimagew_GetDeviceList(IStillImageW *iface, DWORD dwType, DWORD dwFlags,
75 DWORD *pdwItemsReturned, LPVOID *ppBuffer)
76 {
77 stillimage *This = impl_from_IStillImageW(iface);
78 FIXME("(%p, %u, 0x%X, %p, %p): stub\n", This, dwType, dwFlags, pdwItemsReturned, ppBuffer);
79 return E_NOTIMPL;
80 }
81
82 static HRESULT WINAPI stillimagew_GetDeviceInfo(IStillImageW *iface, LPWSTR pwszDeviceName,
83 LPVOID *ppBuffer)
84 {
85 stillimage *This = impl_from_IStillImageW(iface);
86 FIXME("(%p, %s, %p): stub\n", This, debugstr_w(pwszDeviceName), ppBuffer);
87 return E_NOTIMPL;
88 }
89
90 static HRESULT WINAPI stillimagew_CreateDevice(IStillImageW *iface, LPWSTR pwszDeviceName, DWORD dwMode,
91 PSTIDEVICEW *pDevice, LPUNKNOWN pUnkOuter)
92 {
93 stillimage *This = impl_from_IStillImageW(iface);
94 FIXME("(%p, %s, %u, %p, %p): stub\n", This, debugstr_w(pwszDeviceName), dwMode, pDevice, pUnkOuter);
95 return E_NOTIMPL;
96 }
97
98 static HRESULT WINAPI stillimagew_GetDeviceValue(IStillImageW *iface, LPWSTR pwszDeviceName, LPWSTR pValueName,
99 LPDWORD pType, LPBYTE pData, LPDWORD cbData)
100 {
101 stillimage *This = impl_from_IStillImageW(iface);
102 FIXME("(%p, %s, %s, %p, %p, %p): stub\n", This, debugstr_w(pwszDeviceName), debugstr_w(pValueName),
103 pType, pData, cbData);
104 return E_NOTIMPL;
105 }
106
107 static HRESULT WINAPI stillimagew_SetDeviceValue(IStillImageW *iface, LPWSTR pwszDeviceName, LPWSTR pValueName,
108 DWORD type, LPBYTE pData, DWORD cbData)
109 {
110 stillimage *This = impl_from_IStillImageW(iface);
111 FIXME("(%p, %s, %s, %u, %p, %u): stub\n", This, debugstr_w(pwszDeviceName), debugstr_w(pValueName),
112 type, pData, cbData);
113 return E_NOTIMPL;
114 }
115
116 static HRESULT WINAPI stillimagew_GetSTILaunchInformation(IStillImageW *iface, LPWSTR pwszDeviceName,
117 DWORD *pdwEventCode, LPWSTR pwszEventName)
118 {
119 stillimage *This = impl_from_IStillImageW(iface);
120 FIXME("(%p, %p, %p, %p): stub\n", This, pwszDeviceName,
121 pdwEventCode, pwszEventName);
122 return E_NOTIMPL;
123 }
124
125 static HRESULT WINAPI stillimagew_RegisterLaunchApplication(IStillImageW *iface, LPWSTR pwszAppName,
126 LPWSTR pwszCommandLine)
127 {
128 static const WCHAR format[] = {'%','s',' ','%','s',0};
129 static const WCHAR commandLineSuffix[] = {
130 '/','S','t','i','D','e','v','i','c','e',':','%','1',' ',
131 '/','S','t','i','E','v','e','n','t',':','%','2',0};
132 HKEY registeredAppsKey = NULL;
133 DWORD ret;
134 HRESULT hr = S_OK;
135 stillimage *This = impl_from_IStillImageW(iface);
136
137 TRACE("(%p, %s, %s)\n", This, debugstr_w(pwszAppName), debugstr_w(pwszCommandLine));
138
139 ret = RegCreateKeyW(HKEY_LOCAL_MACHINE, registeredAppsLaunchPath, &registeredAppsKey);
140 if (ret == ERROR_SUCCESS)
141 {
142 WCHAR *value = HeapAlloc(GetProcessHeap(), 0,
143 (lstrlenW(pwszCommandLine) + 1 + lstrlenW(commandLineSuffix) + 1) * sizeof(WCHAR));
144 if (value)
145 {
146 sprintfW(value, format, pwszCommandLine, commandLineSuffix);
147 ret = RegSetValueExW(registeredAppsKey, pwszAppName, 0,
148 REG_SZ, (BYTE*)value, (lstrlenW(value)+1)*sizeof(WCHAR));
149 if (ret != ERROR_SUCCESS)
150 hr = HRESULT_FROM_WIN32(ret);
151 HeapFree(GetProcessHeap(), 0, value);
152 }
153 else
154 hr = E_OUTOFMEMORY;
155 RegCloseKey(registeredAppsKey);
156 }
157 else
158 hr = HRESULT_FROM_WIN32(ret);
159 return hr;
160 }
161
162 static HRESULT WINAPI stillimagew_UnregisterLaunchApplication(IStillImageW *iface, LPWSTR pwszAppName)
163 {
164 stillimage *This = impl_from_IStillImageW(iface);
165 HKEY registeredAppsKey = NULL;
166 DWORD ret;
167 HRESULT hr = S_OK;
168
169 TRACE("(%p, %s)\n", This, debugstr_w(pwszAppName));
170
171 ret = RegCreateKeyW(HKEY_LOCAL_MACHINE, registeredAppsLaunchPath, &registeredAppsKey);
172 if (ret == ERROR_SUCCESS)
173 {
174 ret = RegDeleteValueW(registeredAppsKey, pwszAppName);
175 if (ret != ERROR_SUCCESS)
176 hr = HRESULT_FROM_WIN32(ret);
177 RegCloseKey(registeredAppsKey);
178 }
179 else
180 hr = HRESULT_FROM_WIN32(ret);
181 return hr;
182 }
183
184 static HRESULT WINAPI stillimagew_EnableHwNotifications(IStillImageW *iface, LPCWSTR pwszDeviceName,
185 BOOL bNewState)
186 {
187 stillimage *This = impl_from_IStillImageW(iface);
188 FIXME("(%p, %s, %u): stub\n", This, debugstr_w(pwszDeviceName), bNewState);
189 return E_NOTIMPL;
190 }
191
192 static HRESULT WINAPI stillimagew_GetHwNotificationState(IStillImageW *iface, LPCWSTR pwszDeviceName,
193 BOOL *pbCurrentState)
194 {
195 stillimage *This = impl_from_IStillImageW(iface);
196 FIXME("(%p, %s, %p): stub\n", This, debugstr_w(pwszDeviceName), pbCurrentState);
197 return E_NOTIMPL;
198 }
199
200 static HRESULT WINAPI stillimagew_RefreshDeviceBus(IStillImageW *iface, LPCWSTR pwszDeviceName)
201 {
202 stillimage *This = impl_from_IStillImageW(iface);
203 FIXME("(%p, %s): stub\n", This, debugstr_w(pwszDeviceName));
204 return E_NOTIMPL;
205 }
206
207 static HRESULT WINAPI stillimagew_LaunchApplicationForDevice(IStillImageW *iface, LPWSTR pwszDeviceName,
208 LPWSTR pwszAppName, LPSTINOTIFY pStiNotify)
209 {
210 stillimage *This = impl_from_IStillImageW(iface);
211 FIXME("(%p, %s, %s, %p): stub\n", This, debugstr_w(pwszDeviceName), debugstr_w(pwszAppName),
212 pStiNotify);
213 return E_NOTIMPL;
214 }
215
216 static HRESULT WINAPI stillimagew_SetupDeviceParameters(IStillImageW *iface, PSTI_DEVICE_INFORMATIONW pDevInfo)
217 {
218 stillimage *This = impl_from_IStillImageW(iface);
219 FIXME("(%p, %p): stub\n", This, pDevInfo);
220 return E_NOTIMPL;
221 }
222
223 static HRESULT WINAPI stillimagew_WriteToErrorLog(IStillImageW *iface, DWORD dwMessageType, LPCWSTR pszMessage)
224 {
225 stillimage *This = impl_from_IStillImageW(iface);
226 FIXME("(%p, %u, %s): stub\n", This, dwMessageType, debugstr_w(pszMessage));
227 return E_NOTIMPL;
228 }
229
230 static const struct IStillImageWVtbl stillimagew_vtbl =
231 {
232 stillimagew_QueryInterface,
233 stillimagew_AddRef,
234 stillimagew_Release,
235 stillimagew_Initialize,
236 stillimagew_GetDeviceList,
237 stillimagew_GetDeviceInfo,
238 stillimagew_CreateDevice,
239 stillimagew_GetDeviceValue,
240 stillimagew_SetDeviceValue,
241 stillimagew_GetSTILaunchInformation,
242 stillimagew_RegisterLaunchApplication,
243 stillimagew_UnregisterLaunchApplication,
244 stillimagew_EnableHwNotifications,
245 stillimagew_GetHwNotificationState,
246 stillimagew_RefreshDeviceBus,
247 stillimagew_LaunchApplicationForDevice,
248 stillimagew_SetupDeviceParameters,
249 stillimagew_WriteToErrorLog
250 };
251
252 static inline stillimage *impl_from_IUnknown(IUnknown *iface)
253 {
254 return CONTAINING_RECORD(iface, stillimage, IUnknown_iface);
255 }
256
257 static HRESULT WINAPI Internal_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObject)
258 {
259 stillimage *This = impl_from_IUnknown(iface);
260
261 TRACE("(%p %s %p)\n", This, debugstr_guid(riid), ppvObject);
262
263 if (IsEqualGUID(riid, &IID_IUnknown))
264 *ppvObject = iface;
265 else if (IsEqualGUID(riid, &IID_IStillImageW))
266 *ppvObject = &This->IStillImageW_iface;
267 else
268 {
269 if (IsEqualGUID(riid, &IID_IStillImageA))
270 FIXME("interface IStillImageA is unsupported on Windows Vista too, please report if it's needed\n");
271 else
272 FIXME("interface %s not implemented\n", debugstr_guid(riid));
273 *ppvObject = NULL;
274 return E_NOINTERFACE;
275 }
276
277 IUnknown_AddRef((IUnknown*) *ppvObject);
278 return S_OK;
279 }
280
281 static ULONG WINAPI Internal_AddRef(IUnknown *iface)
282 {
283 stillimage *This = impl_from_IUnknown(iface);
284 return InterlockedIncrement(&This->ref);
285 }
286
287 static ULONG WINAPI Internal_Release(IUnknown *iface)
288 {
289 ULONG ref;
290 stillimage *This = impl_from_IUnknown(iface);
291
292 ref = InterlockedDecrement(&This->ref);
293 if (ref == 0)
294 HeapFree(GetProcessHeap(), 0, This);
295 return ref;
296 }
297
298 static const struct IUnknownVtbl internal_unk_vtbl =
299 {
300 Internal_QueryInterface,
301 Internal_AddRef,
302 Internal_Release
303 };
304
305 /******************************************************************************
306 * StiCreateInstanceA (STI.@)
307 */
308 HRESULT WINAPI StiCreateInstanceA(HINSTANCE hinst, DWORD dwVer, PSTIA *ppSti, LPUNKNOWN pUnkOuter)
309 {
310 FIXME("(%p, %u, %p, %p): stub, unimplemented on Windows Vista too, please report if it's needed\n", hinst, dwVer, ppSti, pUnkOuter);
311 return STG_E_UNIMPLEMENTEDFUNCTION;
312 }
313
314 /******************************************************************************
315 * StiCreateInstanceW (STI.@)
316 */
317 HRESULT WINAPI StiCreateInstanceW(HINSTANCE hinst, DWORD dwVer, PSTIW *ppSti, LPUNKNOWN pUnkOuter)
318 {
319 stillimage *This;
320 HRESULT hr;
321
322 TRACE("(%p, %u, %p, %p)\n", hinst, dwVer, ppSti, pUnkOuter);
323
324 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(stillimage));
325 if (This)
326 {
327 This->IStillImageW_iface.lpVtbl = &stillimagew_vtbl;
328 This->IUnknown_iface.lpVtbl = &internal_unk_vtbl;
329 if (pUnkOuter)
330 This->pUnkOuter = pUnkOuter;
331 else
332 This->pUnkOuter = &This->IUnknown_iface;
333 This->ref = 1;
334
335 hr = IStillImage_Initialize(&This->IStillImageW_iface, hinst, dwVer);
336 if (SUCCEEDED(hr))
337 {
338 if (pUnkOuter)
339 *ppSti = (IStillImageW*) &This->IUnknown_iface;
340 else
341 *ppSti = &This->IStillImageW_iface;
342 }
343 }
344 else
345 hr = E_OUTOFMEMORY;
346
347 return hr;
348 }