include: Specify calling convention explicitly in idl files where needed.
[wine/hramrach.git] / dlls / sti / sti.c
blob974bd06f69320a494f907faf70f6cdf20b8318e7
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 "sti_private.h"
33 #include "wine/debug.h"
34 #include "wine/unicode.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(sti);
38 static const WCHAR registeredAppsLaunchPath[] = {
39 'S','O','F','T','W','A','R','E','\\',
40 'M','i','c','r','o','s','o','f','t','\\',
41 'W','i','n','d','o','w','s','\\',
42 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
43 'S','t','i','l','l','I','m','a','g','e','\\',
44 'R','e','g','i','s','t','e','r','e','d',' ','A','p','p','l','i','c','a','t','i','o','n','s',0
47 static inline stillimage *impl_from_StillImageW(IStillImageW *iface)
49 return (stillimage *)((char*)iface - FIELD_OFFSET(stillimage, lpVtbl));
52 static HRESULT WINAPI stillimagew_QueryInterface(IStillImageW *iface, REFIID riid, void **ppvObject)
54 stillimage *This = impl_from_StillImageW(iface);
55 TRACE("(%p %s %p)\n", This, debugstr_guid(riid), ppvObject);
56 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
59 static ULONG WINAPI stillimagew_AddRef(IStillImageW *iface)
61 stillimage *This = impl_from_StillImageW(iface);
62 return IUnknown_AddRef(This->pUnkOuter);
65 static ULONG WINAPI stillimagew_Release(IStillImageW *iface)
67 stillimage *This = impl_from_StillImageW(iface);
68 return IUnknown_Release(This->pUnkOuter);
71 static HRESULT WINAPI stillimagew_Initialize(IStillImageW *iface, HINSTANCE hinst, DWORD dwVersion)
73 stillimage *This = impl_from_StillImageW(iface);
74 TRACE("(%p, %p, 0x%X)\n", This, hinst, dwVersion);
75 return S_OK;
78 static HRESULT WINAPI stillimagew_GetDeviceList(IStillImageW *iface, DWORD dwType, DWORD dwFlags,
79 DWORD *pdwItemsReturned, LPVOID *ppBuffer)
81 stillimage *This = impl_from_StillImageW(iface);
82 FIXME("(%p, %u, 0x%X, %p, %p): stub\n", This, dwType, dwFlags, pdwItemsReturned, ppBuffer);
83 return E_NOTIMPL;
86 static HRESULT WINAPI stillimagew_GetDeviceInfo(IStillImageW *iface, LPWSTR pwszDeviceName,
87 LPVOID *ppBuffer)
89 stillimage *This = impl_from_StillImageW(iface);
90 FIXME("(%p, %s, %p): stub\n", This, debugstr_w(pwszDeviceName), ppBuffer);
91 return E_NOTIMPL;
94 static HRESULT WINAPI stillimagew_CreateDevice(IStillImageW *iface, LPWSTR pwszDeviceName, DWORD dwMode,
95 PSTIDEVICEW *pDevice, LPUNKNOWN pUnkOuter)
97 stillimage *This = impl_from_StillImageW(iface);
98 FIXME("(%p, %s, %u, %p, %p): stub\n", This, debugstr_w(pwszDeviceName), dwMode, pDevice, pUnkOuter);
99 return E_NOTIMPL;
102 static HRESULT WINAPI stillimagew_GetDeviceValue(IStillImageW *iface, LPWSTR pwszDeviceName, LPWSTR pValueName,
103 LPDWORD pType, LPBYTE pData, LPDWORD cbData)
105 stillimage *This = impl_from_StillImageW(iface);
106 FIXME("(%p, %s, %s, %p, %p, %p): stub\n", This, debugstr_w(pwszDeviceName), debugstr_w(pValueName),
107 pType, pData, cbData);
108 return E_NOTIMPL;
111 static HRESULT WINAPI stillimagew_SetDeviceValue(IStillImageW *iface, LPWSTR pwszDeviceName, LPWSTR pValueName,
112 DWORD type, LPBYTE pData, DWORD cbData)
114 stillimage *This = impl_from_StillImageW(iface);
115 FIXME("(%p, %s, %s, %u, %p, %u): stub\n", This, debugstr_w(pwszDeviceName), debugstr_w(pValueName),
116 type, pData, cbData);
117 return E_NOTIMPL;
120 static HRESULT WINAPI stillimagew_GetSTILaunchInformation(IStillImageW *iface, LPWSTR pwszDeviceName,
121 DWORD *pdwEventCode, LPWSTR pwszEventName)
123 stillimage *This = impl_from_StillImageW(iface);
124 FIXME("(%p, %p, %p, %p): stub\n", This, pwszDeviceName,
125 pdwEventCode, pwszEventName);
126 return E_NOTIMPL;
129 static HRESULT WINAPI stillimagew_RegisterLaunchApplication(IStillImageW *iface, LPWSTR pwszAppName,
130 LPWSTR pwszCommandLine)
132 static const WCHAR format[] = {'%','s',' ','%','s',0};
133 static const WCHAR commandLineSuffix[] = {
134 '/','S','t','i','D','e','v','i','c','e',':','%','1',' ',
135 '/','S','t','i','E','v','e','n','t',':','%','2',0};
136 HKEY registeredAppsKey = NULL;
137 DWORD ret;
138 HRESULT hr = S_OK;
139 stillimage *This = impl_from_StillImageW(iface);
141 TRACE("(%p, %s, %s)\n", This, debugstr_w(pwszAppName), debugstr_w(pwszCommandLine));
143 ret = RegCreateKeyW(HKEY_LOCAL_MACHINE, registeredAppsLaunchPath, &registeredAppsKey);
144 if (ret == ERROR_SUCCESS)
146 WCHAR *value = HeapAlloc(GetProcessHeap(), 0,
147 (lstrlenW(pwszCommandLine) + 1 + lstrlenW(commandLineSuffix) + 1) * sizeof(WCHAR));
148 if (value)
150 sprintfW(value, format, pwszCommandLine, commandLineSuffix);
151 ret = RegSetValueExW(registeredAppsKey, pwszAppName, 0,
152 REG_SZ, (BYTE*)value, (lstrlenW(value)+1)*sizeof(WCHAR));
153 if (ret != ERROR_SUCCESS)
154 hr = HRESULT_FROM_WIN32(ret);
155 HeapFree(GetProcessHeap(), 0, value);
157 else
158 hr = E_OUTOFMEMORY;
159 RegCloseKey(registeredAppsKey);
161 else
162 hr = HRESULT_FROM_WIN32(ret);
163 return hr;
166 static HRESULT WINAPI stillimagew_UnregisterLaunchApplication(IStillImageW *iface, LPWSTR pwszAppName)
168 stillimage *This = impl_from_StillImageW(iface);
169 HKEY registeredAppsKey = NULL;
170 DWORD ret;
171 HRESULT hr = S_OK;
173 TRACE("(%p, %s)\n", This, debugstr_w(pwszAppName));
175 ret = RegCreateKeyW(HKEY_LOCAL_MACHINE, registeredAppsLaunchPath, &registeredAppsKey);
176 if (ret == ERROR_SUCCESS)
178 ret = RegDeleteValueW(registeredAppsKey, pwszAppName);
179 if (ret != ERROR_SUCCESS)
180 hr = HRESULT_FROM_WIN32(ret);
181 RegCloseKey(registeredAppsKey);
183 else
184 hr = HRESULT_FROM_WIN32(ret);
185 return hr;
188 static HRESULT WINAPI stillimagew_EnableHwNotifications(IStillImageW *iface, LPCWSTR pwszDeviceName,
189 BOOL bNewState)
191 stillimage *This = impl_from_StillImageW(iface);
192 FIXME("(%p, %s, %u): stub\n", This, debugstr_w(pwszDeviceName), bNewState);
193 return E_NOTIMPL;
196 static HRESULT WINAPI stillimagew_GetHwNotificationState(IStillImageW *iface, LPCWSTR pwszDeviceName,
197 BOOL *pbCurrentState)
199 stillimage *This = impl_from_StillImageW(iface);
200 FIXME("(%p, %s, %p): stub\n", This, debugstr_w(pwszDeviceName), pbCurrentState);
201 return E_NOTIMPL;
204 static HRESULT WINAPI stillimagew_RefreshDeviceBus(IStillImageW *iface, LPCWSTR pwszDeviceName)
206 stillimage *This = impl_from_StillImageW(iface);
207 FIXME("(%p, %s): stub\n", This, debugstr_w(pwszDeviceName));
208 return E_NOTIMPL;
211 static HRESULT WINAPI stillimagew_LaunchApplicationForDevice(IStillImageW *iface, LPWSTR pwszDeviceName,
212 LPWSTR pwszAppName, LPSTINOTIFY pStiNotify)
214 stillimage *This = impl_from_StillImageW(iface);
215 FIXME("(%p, %s, %s, %p): stub\n", This, debugstr_w(pwszDeviceName), debugstr_w(pwszAppName),
216 pStiNotify);
217 return E_NOTIMPL;
220 static HRESULT WINAPI stillimagew_SetupDeviceParameters(IStillImageW *iface, PSTI_DEVICE_INFORMATIONW pDevInfo)
222 stillimage *This = impl_from_StillImageW(iface);
223 FIXME("(%p, %p): stub\n", This, pDevInfo);
224 return E_NOTIMPL;
227 static HRESULT WINAPI stillimagew_WriteToErrorLog(IStillImageW *iface, DWORD dwMessageType, LPCWSTR pszMessage)
229 stillimage *This = impl_from_StillImageW(iface);
230 FIXME("(%p, %u, %s): stub\n", This, dwMessageType, debugstr_w(pszMessage));
231 return E_NOTIMPL;
234 static const struct IStillImageWVtbl stillimagew_vtbl =
236 stillimagew_QueryInterface,
237 stillimagew_AddRef,
238 stillimagew_Release,
239 stillimagew_Initialize,
240 stillimagew_GetDeviceList,
241 stillimagew_GetDeviceInfo,
242 stillimagew_CreateDevice,
243 stillimagew_GetDeviceValue,
244 stillimagew_SetDeviceValue,
245 stillimagew_GetSTILaunchInformation,
246 stillimagew_RegisterLaunchApplication,
247 stillimagew_UnregisterLaunchApplication,
248 stillimagew_EnableHwNotifications,
249 stillimagew_GetHwNotificationState,
250 stillimagew_RefreshDeviceBus,
251 stillimagew_LaunchApplicationForDevice,
252 stillimagew_SetupDeviceParameters,
253 stillimagew_WriteToErrorLog
256 static inline stillimage *impl_from_InternalUnknown(IUnknown *iface)
258 return (stillimage *)((char*)iface - FIELD_OFFSET(stillimage, lpInternalUnkVtbl));
261 static HRESULT WINAPI Internal_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObject)
263 stillimage *This = impl_from_InternalUnknown(iface);
265 TRACE("(%p %s %p)\n", This, debugstr_guid(riid), ppvObject);
267 if (IsEqualGUID(riid, &IID_IUnknown))
268 *ppvObject = iface;
269 else if (IsEqualGUID(riid, &IID_IStillImageW))
270 *ppvObject = &This->lpVtbl;
271 else
273 if (IsEqualGUID(riid, &IID_IStillImageA))
274 FIXME("interface IStillImageA is unsupported on Windows Vista too, please report if it's needed\n");
275 else
276 FIXME("interface %s not implemented\n", debugstr_guid(riid));
277 *ppvObject = NULL;
278 return E_NOINTERFACE;
281 IUnknown_AddRef((IUnknown*) *ppvObject);
282 return S_OK;
285 static ULONG WINAPI Internal_AddRef(IUnknown *iface)
287 stillimage *This = impl_from_InternalUnknown(iface);
288 return InterlockedIncrement(&This->ref);
291 static ULONG WINAPI Internal_Release(IUnknown *iface)
293 ULONG ref;
294 stillimage *This = impl_from_InternalUnknown(iface);
296 ref = InterlockedDecrement(&This->ref);
297 if (ref == 0)
298 HeapFree(GetProcessHeap(), 0, This);
299 return ref;
302 static const struct IUnknownVtbl internal_unk_vtbl =
304 Internal_QueryInterface,
305 Internal_AddRef,
306 Internal_Release
309 /******************************************************************************
310 * StiCreateInstanceA (STI.@)
312 HRESULT WINAPI StiCreateInstanceA(HINSTANCE hinst, DWORD dwVer, PSTIA *ppSti, LPUNKNOWN pUnkOuter)
314 FIXME("(%p, %u, %p, %p): stub, unimplemented on Windows Vista too, please report if it's needed\n", hinst, dwVer, ppSti, pUnkOuter);
315 return STG_E_UNIMPLEMENTEDFUNCTION;
318 /******************************************************************************
319 * StiCreateInstanceW (STI.@)
321 HRESULT WINAPI StiCreateInstanceW(HINSTANCE hinst, DWORD dwVer, PSTIW *ppSti, LPUNKNOWN pUnkOuter)
323 stillimage *This;
324 HRESULT hr;
326 TRACE("(%p, %u, %p, %p)\n", hinst, dwVer, ppSti, pUnkOuter);
328 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(stillimage));
329 if (This)
331 This->lpVtbl = &stillimagew_vtbl;
332 This->lpInternalUnkVtbl = &internal_unk_vtbl;
333 if (pUnkOuter)
334 This->pUnkOuter = pUnkOuter;
335 else
336 This->pUnkOuter = (IUnknown*) &This->lpInternalUnkVtbl;
337 This->ref = 1;
339 hr = IStillImage_Initialize((IStillImageW*) &This->lpVtbl, hinst, dwVer);
340 if (SUCCEEDED(hr))
342 if (pUnkOuter)
343 *ppSti = (IStillImageW*) &This->lpInternalUnkVtbl;
344 else
345 *ppSti = (IStillImageW*) &This->lpVtbl;
348 else
349 hr = E_OUTOFMEMORY;
351 return hr;