Create this branch to work on loading of different Kernel-Debugger DLL providers...
[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 #define WIN32_NO_STATUS
21 #define _INC_WINDOWS
22 #define COM_NO_WINDOWS_H
23
24 #include <stdarg.h>
25
26 #define COBJMACROS
27
28 #include <windef.h>
29 #include <winbase.h>
30 #include <winreg.h>
31 //#include "winerror.h"
32 //#include "objbase.h"
33 #include <sti.h>
34
35 #include <wine/debug.h>
36 #include <wine/unicode.h>
37
38 WINE_DEFAULT_DEBUG_CHANNEL(sti);
39
40 static const WCHAR registeredAppsLaunchPath[] = {
41 'S','O','F','T','W','A','R','E','\\',
42 'M','i','c','r','o','s','o','f','t','\\',
43 'W','i','n','d','o','w','s','\\',
44 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
45 'S','t','i','l','l','I','m','a','g','e','\\',
46 'R','e','g','i','s','t','e','r','e','d',' ','A','p','p','l','i','c','a','t','i','o','n','s',0
47 };
48
49 typedef struct _stillimage
50 {
51 IStillImageW IStillImageW_iface;
52 IUnknown IUnknown_iface;
53 IUnknown *pUnkOuter;
54 LONG ref;
55 } stillimage;
56
57 static inline stillimage *impl_from_IStillImageW(IStillImageW *iface)
58 {
59 return CONTAINING_RECORD(iface, stillimage, IStillImageW_iface);
60 }
61
62 static HRESULT WINAPI stillimagew_QueryInterface(IStillImageW *iface, REFIID riid, void **ppvObject)
63 {
64 stillimage *This = impl_from_IStillImageW(iface);
65 TRACE("(%p %s %p)\n", This, debugstr_guid(riid), ppvObject);
66 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
67 }
68
69 static ULONG WINAPI stillimagew_AddRef(IStillImageW *iface)
70 {
71 stillimage *This = impl_from_IStillImageW(iface);
72 return IUnknown_AddRef(This->pUnkOuter);
73 }
74
75 static ULONG WINAPI stillimagew_Release(IStillImageW *iface)
76 {
77 stillimage *This = impl_from_IStillImageW(iface);
78 return IUnknown_Release(This->pUnkOuter);
79 }
80
81 static HRESULT WINAPI stillimagew_Initialize(IStillImageW *iface, HINSTANCE hinst, DWORD dwVersion)
82 {
83 stillimage *This = impl_from_IStillImageW(iface);
84 TRACE("(%p, %p, 0x%X)\n", This, hinst, dwVersion);
85 return S_OK;
86 }
87
88 static HRESULT WINAPI stillimagew_GetDeviceList(IStillImageW *iface, DWORD dwType, DWORD dwFlags,
89 DWORD *pdwItemsReturned, LPVOID *ppBuffer)
90 {
91 stillimage *This = impl_from_IStillImageW(iface);
92 FIXME("(%p, %u, 0x%X, %p, %p): stub\n", This, dwType, dwFlags, pdwItemsReturned, ppBuffer);
93 return E_NOTIMPL;
94 }
95
96 static HRESULT WINAPI stillimagew_GetDeviceInfo(IStillImageW *iface, LPWSTR pwszDeviceName,
97 LPVOID *ppBuffer)
98 {
99 stillimage *This = impl_from_IStillImageW(iface);
100 FIXME("(%p, %s, %p): stub\n", This, debugstr_w(pwszDeviceName), ppBuffer);
101 return E_NOTIMPL;
102 }
103
104 static HRESULT WINAPI stillimagew_CreateDevice(IStillImageW *iface, LPWSTR pwszDeviceName, DWORD dwMode,
105 PSTIDEVICEW *pDevice, LPUNKNOWN pUnkOuter)
106 {
107 stillimage *This = impl_from_IStillImageW(iface);
108 FIXME("(%p, %s, %u, %p, %p): stub\n", This, debugstr_w(pwszDeviceName), dwMode, pDevice, pUnkOuter);
109 return E_NOTIMPL;
110 }
111
112 static HRESULT WINAPI stillimagew_GetDeviceValue(IStillImageW *iface, LPWSTR pwszDeviceName, LPWSTR pValueName,
113 LPDWORD pType, LPBYTE pData, LPDWORD cbData)
114 {
115 stillimage *This = impl_from_IStillImageW(iface);
116 FIXME("(%p, %s, %s, %p, %p, %p): stub\n", This, debugstr_w(pwszDeviceName), debugstr_w(pValueName),
117 pType, pData, cbData);
118 return E_NOTIMPL;
119 }
120
121 static HRESULT WINAPI stillimagew_SetDeviceValue(IStillImageW *iface, LPWSTR pwszDeviceName, LPWSTR pValueName,
122 DWORD type, LPBYTE pData, DWORD cbData)
123 {
124 stillimage *This = impl_from_IStillImageW(iface);
125 FIXME("(%p, %s, %s, %u, %p, %u): stub\n", This, debugstr_w(pwszDeviceName), debugstr_w(pValueName),
126 type, pData, cbData);
127 return E_NOTIMPL;
128 }
129
130 static HRESULT WINAPI stillimagew_GetSTILaunchInformation(IStillImageW *iface, LPWSTR pwszDeviceName,
131 DWORD *pdwEventCode, LPWSTR pwszEventName)
132 {
133 stillimage *This = impl_from_IStillImageW(iface);
134 FIXME("(%p, %p, %p, %p): stub\n", This, pwszDeviceName,
135 pdwEventCode, pwszEventName);
136 return E_NOTIMPL;
137 }
138
139 static HRESULT WINAPI stillimagew_RegisterLaunchApplication(IStillImageW *iface, LPWSTR pwszAppName,
140 LPWSTR pwszCommandLine)
141 {
142 static const WCHAR format[] = {'%','s',' ','%','s',0};
143 static const WCHAR commandLineSuffix[] = {
144 '/','S','t','i','D','e','v','i','c','e',':','%','1',' ',
145 '/','S','t','i','E','v','e','n','t',':','%','2',0};
146 HKEY registeredAppsKey = NULL;
147 DWORD ret;
148 HRESULT hr = S_OK;
149 stillimage *This = impl_from_IStillImageW(iface);
150
151 TRACE("(%p, %s, %s)\n", This, debugstr_w(pwszAppName), debugstr_w(pwszCommandLine));
152
153 ret = RegCreateKeyW(HKEY_LOCAL_MACHINE, registeredAppsLaunchPath, &registeredAppsKey);
154 if (ret == ERROR_SUCCESS)
155 {
156 WCHAR *value = HeapAlloc(GetProcessHeap(), 0,
157 (lstrlenW(pwszCommandLine) + 1 + lstrlenW(commandLineSuffix) + 1) * sizeof(WCHAR));
158 if (value)
159 {
160 sprintfW(value, format, pwszCommandLine, commandLineSuffix);
161 ret = RegSetValueExW(registeredAppsKey, pwszAppName, 0,
162 REG_SZ, (BYTE*)value, (lstrlenW(value)+1)*sizeof(WCHAR));
163 if (ret != ERROR_SUCCESS)
164 hr = HRESULT_FROM_WIN32(ret);
165 HeapFree(GetProcessHeap(), 0, value);
166 }
167 else
168 hr = E_OUTOFMEMORY;
169 RegCloseKey(registeredAppsKey);
170 }
171 else
172 hr = HRESULT_FROM_WIN32(ret);
173 return hr;
174 }
175
176 static HRESULT WINAPI stillimagew_UnregisterLaunchApplication(IStillImageW *iface, LPWSTR pwszAppName)
177 {
178 stillimage *This = impl_from_IStillImageW(iface);
179 HKEY registeredAppsKey = NULL;
180 DWORD ret;
181 HRESULT hr = S_OK;
182
183 TRACE("(%p, %s)\n", This, debugstr_w(pwszAppName));
184
185 ret = RegCreateKeyW(HKEY_LOCAL_MACHINE, registeredAppsLaunchPath, &registeredAppsKey);
186 if (ret == ERROR_SUCCESS)
187 {
188 ret = RegDeleteValueW(registeredAppsKey, pwszAppName);
189 if (ret != ERROR_SUCCESS)
190 hr = HRESULT_FROM_WIN32(ret);
191 RegCloseKey(registeredAppsKey);
192 }
193 else
194 hr = HRESULT_FROM_WIN32(ret);
195 return hr;
196 }
197
198 static HRESULT WINAPI stillimagew_EnableHwNotifications(IStillImageW *iface, LPCWSTR pwszDeviceName,
199 BOOL bNewState)
200 {
201 stillimage *This = impl_from_IStillImageW(iface);
202 FIXME("(%p, %s, %u): stub\n", This, debugstr_w(pwszDeviceName), bNewState);
203 return E_NOTIMPL;
204 }
205
206 static HRESULT WINAPI stillimagew_GetHwNotificationState(IStillImageW *iface, LPCWSTR pwszDeviceName,
207 BOOL *pbCurrentState)
208 {
209 stillimage *This = impl_from_IStillImageW(iface);
210 FIXME("(%p, %s, %p): stub\n", This, debugstr_w(pwszDeviceName), pbCurrentState);
211 return E_NOTIMPL;
212 }
213
214 static HRESULT WINAPI stillimagew_RefreshDeviceBus(IStillImageW *iface, LPCWSTR pwszDeviceName)
215 {
216 stillimage *This = impl_from_IStillImageW(iface);
217 FIXME("(%p, %s): stub\n", This, debugstr_w(pwszDeviceName));
218 return E_NOTIMPL;
219 }
220
221 static HRESULT WINAPI stillimagew_LaunchApplicationForDevice(IStillImageW *iface, LPWSTR pwszDeviceName,
222 LPWSTR pwszAppName, LPSTINOTIFY pStiNotify)
223 {
224 stillimage *This = impl_from_IStillImageW(iface);
225 FIXME("(%p, %s, %s, %p): stub\n", This, debugstr_w(pwszDeviceName), debugstr_w(pwszAppName),
226 pStiNotify);
227 return E_NOTIMPL;
228 }
229
230 static HRESULT WINAPI stillimagew_SetupDeviceParameters(IStillImageW *iface, PSTI_DEVICE_INFORMATIONW pDevInfo)
231 {
232 stillimage *This = impl_from_IStillImageW(iface);
233 FIXME("(%p, %p): stub\n", This, pDevInfo);
234 return E_NOTIMPL;
235 }
236
237 static HRESULT WINAPI stillimagew_WriteToErrorLog(IStillImageW *iface, DWORD dwMessageType, LPCWSTR pszMessage)
238 {
239 stillimage *This = impl_from_IStillImageW(iface);
240 FIXME("(%p, %u, %s): stub\n", This, dwMessageType, debugstr_w(pszMessage));
241 return E_NOTIMPL;
242 }
243
244 static const struct IStillImageWVtbl stillimagew_vtbl =
245 {
246 stillimagew_QueryInterface,
247 stillimagew_AddRef,
248 stillimagew_Release,
249 stillimagew_Initialize,
250 stillimagew_GetDeviceList,
251 stillimagew_GetDeviceInfo,
252 stillimagew_CreateDevice,
253 stillimagew_GetDeviceValue,
254 stillimagew_SetDeviceValue,
255 stillimagew_GetSTILaunchInformation,
256 stillimagew_RegisterLaunchApplication,
257 stillimagew_UnregisterLaunchApplication,
258 stillimagew_EnableHwNotifications,
259 stillimagew_GetHwNotificationState,
260 stillimagew_RefreshDeviceBus,
261 stillimagew_LaunchApplicationForDevice,
262 stillimagew_SetupDeviceParameters,
263 stillimagew_WriteToErrorLog
264 };
265
266 static inline stillimage *impl_from_IUnknown(IUnknown *iface)
267 {
268 return CONTAINING_RECORD(iface, stillimage, IUnknown_iface);
269 }
270
271 static HRESULT WINAPI Internal_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObject)
272 {
273 stillimage *This = impl_from_IUnknown(iface);
274
275 TRACE("(%p %s %p)\n", This, debugstr_guid(riid), ppvObject);
276
277 if (IsEqualGUID(riid, &IID_IUnknown))
278 *ppvObject = iface;
279 else if (IsEqualGUID(riid, &IID_IStillImageW))
280 *ppvObject = &This->IStillImageW_iface;
281 else
282 {
283 if (IsEqualGUID(riid, &IID_IStillImageA))
284 FIXME("interface IStillImageA is unsupported on Windows Vista too, please report if it's needed\n");
285 else
286 FIXME("interface %s not implemented\n", debugstr_guid(riid));
287 *ppvObject = NULL;
288 return E_NOINTERFACE;
289 }
290
291 IUnknown_AddRef((IUnknown*) *ppvObject);
292 return S_OK;
293 }
294
295 static ULONG WINAPI Internal_AddRef(IUnknown *iface)
296 {
297 stillimage *This = impl_from_IUnknown(iface);
298 return InterlockedIncrement(&This->ref);
299 }
300
301 static ULONG WINAPI Internal_Release(IUnknown *iface)
302 {
303 ULONG ref;
304 stillimage *This = impl_from_IUnknown(iface);
305
306 ref = InterlockedDecrement(&This->ref);
307 if (ref == 0)
308 HeapFree(GetProcessHeap(), 0, This);
309 return ref;
310 }
311
312 static const struct IUnknownVtbl internal_unk_vtbl =
313 {
314 Internal_QueryInterface,
315 Internal_AddRef,
316 Internal_Release
317 };
318
319 /******************************************************************************
320 * StiCreateInstanceA (STI.@)
321 */
322 HRESULT WINAPI StiCreateInstanceA(HINSTANCE hinst, DWORD dwVer, PSTIA *ppSti, LPUNKNOWN pUnkOuter)
323 {
324 FIXME("(%p, %u, %p, %p): stub, unimplemented on Windows Vista too, please report if it's needed\n", hinst, dwVer, ppSti, pUnkOuter);
325 return STG_E_UNIMPLEMENTEDFUNCTION;
326 }
327
328 /******************************************************************************
329 * StiCreateInstanceW (STI.@)
330 */
331 HRESULT WINAPI StiCreateInstanceW(HINSTANCE hinst, DWORD dwVer, PSTIW *ppSti, LPUNKNOWN pUnkOuter)
332 {
333 stillimage *This;
334 HRESULT hr;
335
336 TRACE("(%p, %u, %p, %p)\n", hinst, dwVer, ppSti, pUnkOuter);
337
338 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(stillimage));
339 if (This)
340 {
341 This->IStillImageW_iface.lpVtbl = &stillimagew_vtbl;
342 This->IUnknown_iface.lpVtbl = &internal_unk_vtbl;
343 if (pUnkOuter)
344 This->pUnkOuter = pUnkOuter;
345 else
346 This->pUnkOuter = &This->IUnknown_iface;
347 This->ref = 1;
348
349 hr = IStillImage_Initialize(&This->IStillImageW_iface, hinst, dwVer);
350 if (SUCCEEDED(hr))
351 {
352 if (pUnkOuter)
353 *ppSti = (IStillImageW*) &This->IUnknown_iface;
354 else
355 *ppSti = &This->IStillImageW_iface;
356 }
357 }
358 else
359 hr = E_OUTOFMEMORY;
360
361 return hr;
362 }