dmband: Semi-stub IDirectMusicBand CreateSegment.
[wine.git] / dlls / sti / sti.c
blob962371f92d26124347a9efffe8075dccd06d373b
1 /*
2 * Copyright (C) 2002 Aric Stewart for CodeWeavers
3 * Copyright (C) 2009 Damjan Jovanovic
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.
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.
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
20 #include <stdarg.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winreg.h"
27 #include "winerror.h"
28 #include "objbase.h"
29 #include "sti.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(sti);
35 static const WCHAR registeredAppsLaunchPath[] = {
36 'S','O','F','T','W','A','R','E','\\',
37 'M','i','c','r','o','s','o','f','t','\\',
38 'W','i','n','d','o','w','s','\\',
39 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
40 'S','t','i','l','l','I','m','a','g','e','\\',
41 'R','e','g','i','s','t','e','r','e','d',' ','A','p','p','l','i','c','a','t','i','o','n','s',0
44 typedef struct _stillimage
46 IUnknown IUnknown_inner;
47 IStillImageW IStillImageW_iface;
48 IUnknown *outer_unk;
49 LONG ref;
50 } stillimage;
52 static inline stillimage *impl_from_IStillImageW(IStillImageW *iface)
54 return CONTAINING_RECORD(iface, stillimage, IStillImageW_iface);
57 static HRESULT WINAPI stillimagew_QueryInterface(IStillImageW *iface, REFIID riid, void **ppvObject)
59 stillimage *This = impl_from_IStillImageW(iface);
60 TRACE("(%p %s %p)\n", This, debugstr_guid(riid), ppvObject);
61 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObject);
64 static ULONG WINAPI stillimagew_AddRef(IStillImageW *iface)
66 stillimage *This = impl_from_IStillImageW(iface);
67 return IUnknown_AddRef(This->outer_unk);
70 static ULONG WINAPI stillimagew_Release(IStillImageW *iface)
72 stillimage *This = impl_from_IStillImageW(iface);
73 return IUnknown_Release(This->outer_unk);
76 static HRESULT WINAPI stillimagew_Initialize(IStillImageW *iface, HINSTANCE hinst, DWORD dwVersion)
78 stillimage *This = impl_from_IStillImageW(iface);
79 TRACE("(%p, %p, 0x%X)\n", This, hinst, dwVersion);
80 return S_OK;
83 static HRESULT WINAPI stillimagew_GetDeviceList(IStillImageW *iface, DWORD dwType, DWORD dwFlags,
84 DWORD *pdwItemsReturned, LPVOID *ppBuffer)
86 stillimage *This = impl_from_IStillImageW(iface);
87 FIXME("(%p, %u, 0x%X, %p, %p): stub\n", This, dwType, dwFlags, pdwItemsReturned, ppBuffer);
88 return E_NOTIMPL;
91 static HRESULT WINAPI stillimagew_GetDeviceInfo(IStillImageW *iface, LPWSTR pwszDeviceName,
92 LPVOID *ppBuffer)
94 stillimage *This = impl_from_IStillImageW(iface);
95 FIXME("(%p, %s, %p): stub\n", This, debugstr_w(pwszDeviceName), ppBuffer);
96 return E_NOTIMPL;
99 static HRESULT WINAPI stillimagew_CreateDevice(IStillImageW *iface, LPWSTR pwszDeviceName, DWORD dwMode,
100 PSTIDEVICEW *pDevice, LPUNKNOWN pUnkOuter)
102 stillimage *This = impl_from_IStillImageW(iface);
103 FIXME("(%p, %s, %u, %p, %p): stub\n", This, debugstr_w(pwszDeviceName), dwMode, pDevice, pUnkOuter);
104 return E_NOTIMPL;
107 static HRESULT WINAPI stillimagew_GetDeviceValue(IStillImageW *iface, LPWSTR pwszDeviceName, LPWSTR pValueName,
108 LPDWORD pType, LPBYTE pData, LPDWORD cbData)
110 stillimage *This = impl_from_IStillImageW(iface);
111 FIXME("(%p, %s, %s, %p, %p, %p): stub\n", This, debugstr_w(pwszDeviceName), debugstr_w(pValueName),
112 pType, pData, cbData);
113 return E_NOTIMPL;
116 static HRESULT WINAPI stillimagew_SetDeviceValue(IStillImageW *iface, LPWSTR pwszDeviceName, LPWSTR pValueName,
117 DWORD type, LPBYTE pData, DWORD cbData)
119 stillimage *This = impl_from_IStillImageW(iface);
120 FIXME("(%p, %s, %s, %u, %p, %u): stub\n", This, debugstr_w(pwszDeviceName), debugstr_w(pValueName),
121 type, pData, cbData);
122 return E_NOTIMPL;
125 static HRESULT WINAPI stillimagew_GetSTILaunchInformation(IStillImageW *iface, LPWSTR pwszDeviceName,
126 DWORD *pdwEventCode, LPWSTR pwszEventName)
128 stillimage *This = impl_from_IStillImageW(iface);
129 FIXME("(%p, %p, %p, %p): stub\n", This, pwszDeviceName,
130 pdwEventCode, pwszEventName);
131 return E_NOTIMPL;
134 static HRESULT WINAPI stillimagew_RegisterLaunchApplication(IStillImageW *iface, LPWSTR pwszAppName,
135 LPWSTR pwszCommandLine)
137 static const WCHAR format[] = {'%','s',' ','%','s',0};
138 static const WCHAR commandLineSuffix[] = {
139 '/','S','t','i','D','e','v','i','c','e',':','%','1',' ',
140 '/','S','t','i','E','v','e','n','t',':','%','2',0};
141 HKEY registeredAppsKey = NULL;
142 DWORD ret;
143 HRESULT hr = S_OK;
144 stillimage *This = impl_from_IStillImageW(iface);
146 TRACE("(%p, %s, %s)\n", This, debugstr_w(pwszAppName), debugstr_w(pwszCommandLine));
148 ret = RegCreateKeyW(HKEY_LOCAL_MACHINE, registeredAppsLaunchPath, &registeredAppsKey);
149 if (ret == ERROR_SUCCESS)
151 size_t len = lstrlenW(pwszCommandLine) + 1 + lstrlenW(commandLineSuffix) + 1;
152 WCHAR *value = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
153 if (value)
155 swprintf(value, len, format, pwszCommandLine, commandLineSuffix);
156 ret = RegSetValueExW(registeredAppsKey, pwszAppName, 0,
157 REG_SZ, (BYTE*)value, (lstrlenW(value)+1)*sizeof(WCHAR));
158 if (ret != ERROR_SUCCESS)
159 hr = HRESULT_FROM_WIN32(ret);
160 HeapFree(GetProcessHeap(), 0, value);
162 else
163 hr = E_OUTOFMEMORY;
164 RegCloseKey(registeredAppsKey);
166 else
167 hr = HRESULT_FROM_WIN32(ret);
168 return hr;
171 static HRESULT WINAPI stillimagew_UnregisterLaunchApplication(IStillImageW *iface, LPWSTR pwszAppName)
173 stillimage *This = impl_from_IStillImageW(iface);
174 HKEY registeredAppsKey = NULL;
175 DWORD ret;
176 HRESULT hr = S_OK;
178 TRACE("(%p, %s)\n", This, debugstr_w(pwszAppName));
180 ret = RegCreateKeyW(HKEY_LOCAL_MACHINE, registeredAppsLaunchPath, &registeredAppsKey);
181 if (ret == ERROR_SUCCESS)
183 ret = RegDeleteValueW(registeredAppsKey, pwszAppName);
184 if (ret != ERROR_SUCCESS)
185 hr = HRESULT_FROM_WIN32(ret);
186 RegCloseKey(registeredAppsKey);
188 else
189 hr = HRESULT_FROM_WIN32(ret);
190 return hr;
193 static HRESULT WINAPI stillimagew_EnableHwNotifications(IStillImageW *iface, LPCWSTR pwszDeviceName,
194 BOOL bNewState)
196 stillimage *This = impl_from_IStillImageW(iface);
197 FIXME("(%p, %s, %u): stub\n", This, debugstr_w(pwszDeviceName), bNewState);
198 return E_NOTIMPL;
201 static HRESULT WINAPI stillimagew_GetHwNotificationState(IStillImageW *iface, LPCWSTR pwszDeviceName,
202 BOOL *pbCurrentState)
204 stillimage *This = impl_from_IStillImageW(iface);
205 FIXME("(%p, %s, %p): stub\n", This, debugstr_w(pwszDeviceName), pbCurrentState);
206 return E_NOTIMPL;
209 static HRESULT WINAPI stillimagew_RefreshDeviceBus(IStillImageW *iface, LPCWSTR pwszDeviceName)
211 stillimage *This = impl_from_IStillImageW(iface);
212 FIXME("(%p, %s): stub\n", This, debugstr_w(pwszDeviceName));
213 return E_NOTIMPL;
216 static HRESULT WINAPI stillimagew_LaunchApplicationForDevice(IStillImageW *iface, LPWSTR pwszDeviceName,
217 LPWSTR pwszAppName, LPSTINOTIFY pStiNotify)
219 stillimage *This = impl_from_IStillImageW(iface);
220 FIXME("(%p, %s, %s, %p): stub\n", This, debugstr_w(pwszDeviceName), debugstr_w(pwszAppName),
221 pStiNotify);
222 return E_NOTIMPL;
225 static HRESULT WINAPI stillimagew_SetupDeviceParameters(IStillImageW *iface, PSTI_DEVICE_INFORMATIONW pDevInfo)
227 stillimage *This = impl_from_IStillImageW(iface);
228 FIXME("(%p, %p): stub\n", This, pDevInfo);
229 return E_NOTIMPL;
232 static HRESULT WINAPI stillimagew_WriteToErrorLog(IStillImageW *iface, DWORD dwMessageType, LPCWSTR pszMessage)
234 stillimage *This = impl_from_IStillImageW(iface);
235 FIXME("(%p, %u, %s): stub\n", This, dwMessageType, debugstr_w(pszMessage));
236 return E_NOTIMPL;
239 static const struct IStillImageWVtbl stillimagew_vtbl =
241 stillimagew_QueryInterface,
242 stillimagew_AddRef,
243 stillimagew_Release,
244 stillimagew_Initialize,
245 stillimagew_GetDeviceList,
246 stillimagew_GetDeviceInfo,
247 stillimagew_CreateDevice,
248 stillimagew_GetDeviceValue,
249 stillimagew_SetDeviceValue,
250 stillimagew_GetSTILaunchInformation,
251 stillimagew_RegisterLaunchApplication,
252 stillimagew_UnregisterLaunchApplication,
253 stillimagew_EnableHwNotifications,
254 stillimagew_GetHwNotificationState,
255 stillimagew_RefreshDeviceBus,
256 stillimagew_LaunchApplicationForDevice,
257 stillimagew_SetupDeviceParameters,
258 stillimagew_WriteToErrorLog
261 static inline stillimage *impl_from_IUnknown(IUnknown *iface)
263 return CONTAINING_RECORD(iface, stillimage, IUnknown_inner);
266 static HRESULT WINAPI Internal_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObject)
268 stillimage *This = impl_from_IUnknown(iface);
270 TRACE("(%p %s %p)\n", This, debugstr_guid(riid), ppvObject);
272 if (IsEqualGUID(riid, &IID_IUnknown))
273 *ppvObject = iface;
274 else if (IsEqualGUID(riid, &IID_IStillImageW))
275 *ppvObject = &This->IStillImageW_iface;
276 else
278 if (IsEqualGUID(riid, &IID_IStillImageA))
279 FIXME("interface IStillImageA is unsupported on Windows Vista too, please report if it's needed\n");
280 else
281 FIXME("interface %s not implemented\n", debugstr_guid(riid));
282 *ppvObject = NULL;
283 return E_NOINTERFACE;
286 IUnknown_AddRef((IUnknown*) *ppvObject);
287 return S_OK;
290 static ULONG WINAPI Internal_AddRef(IUnknown *iface)
292 stillimage *This = impl_from_IUnknown(iface);
293 return InterlockedIncrement(&This->ref);
296 static ULONG WINAPI Internal_Release(IUnknown *iface)
298 ULONG ref;
299 stillimage *This = impl_from_IUnknown(iface);
301 ref = InterlockedDecrement(&This->ref);
302 if (ref == 0)
303 HeapFree(GetProcessHeap(), 0, This);
304 return ref;
307 static const struct IUnknownVtbl internal_unk_vtbl =
309 Internal_QueryInterface,
310 Internal_AddRef,
311 Internal_Release
314 /******************************************************************************
315 * StiCreateInstanceA (STI.@)
317 HRESULT WINAPI StiCreateInstanceA(HINSTANCE hinst, DWORD dwVer, PSTIA *ppSti, LPUNKNOWN pUnkOuter)
319 FIXME("(%p, %u, %p, %p): stub, unimplemented on Windows Vista too, please report if it's needed\n", hinst, dwVer, ppSti, pUnkOuter);
320 return STG_E_UNIMPLEMENTEDFUNCTION;
323 /******************************************************************************
324 * StiCreateInstanceW (STI.@)
326 HRESULT WINAPI StiCreateInstanceW(HINSTANCE hinst, DWORD dwVer, PSTIW *ppSti, LPUNKNOWN pUnkOuter)
328 stillimage *This;
329 HRESULT hr;
331 TRACE("(%p, %u, %p, %p)\n", hinst, dwVer, ppSti, pUnkOuter);
333 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(stillimage));
334 if (This)
336 This->IStillImageW_iface.lpVtbl = &stillimagew_vtbl;
337 This->IUnknown_inner.lpVtbl = &internal_unk_vtbl;
338 if (pUnkOuter)
339 This->outer_unk = pUnkOuter;
340 else
341 This->outer_unk = &This->IUnknown_inner;
342 This->ref = 1;
344 hr = IStillImage_Initialize(&This->IStillImageW_iface, hinst, dwVer);
345 if (SUCCEEDED(hr))
347 if (pUnkOuter)
348 *ppSti = (IStillImageW*) &This->IUnknown_inner;
349 else
350 *ppSti = &This->IStillImageW_iface;
353 else
354 hr = E_OUTOFMEMORY;
356 return hr;