rsaenh: Add some traces to key importing.
[wine] / dlls / 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 <stdarg.h>
21
22 #define COBJMACROS
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winreg.h"
27 #include "winerror.h"
28 #include "objbase.h"
29 #include "sti.h"
30
31 #include "sti_private.h"
32
33 #include "wine/debug.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(sti);
36
37 static inline stillimage *impl_from_StillImageW(IStillImageW *iface)
38 {
39     return (stillimage *)((char*)iface - FIELD_OFFSET(stillimage, lpVtbl));
40 }
41
42 static HRESULT WINAPI stillimagew_QueryInterface(IStillImageW *iface, REFIID riid, void **ppvObject)
43 {
44     stillimage *This = impl_from_StillImageW(iface);
45     TRACE("(%p %s %p)\n", This, debugstr_guid(riid), ppvObject);
46     return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
47 }
48
49 static ULONG WINAPI stillimagew_AddRef(IStillImageW *iface)
50 {
51     stillimage *This = impl_from_StillImageW(iface);
52     return IUnknown_AddRef(This->pUnkOuter);
53 }
54
55 static ULONG WINAPI stillimagew_Release(IStillImageW *iface)
56 {
57     stillimage *This = impl_from_StillImageW(iface);
58     return IUnknown_Release(This->pUnkOuter);
59 }
60
61 static HRESULT WINAPI stillimagew_Initialize(IStillImageW *iface, HINSTANCE hinst, DWORD dwVersion)
62 {
63     stillimage *This = impl_from_StillImageW(iface);
64     TRACE("(%p, %p, 0x%X)\n", This, hinst, dwVersion);
65     return S_OK;
66 }
67
68 static HRESULT WINAPI stillimagew_GetDeviceList(IStillImageW *iface, DWORD dwType, DWORD dwFlags,
69                                                 DWORD *pdwItemsReturned, LPVOID *ppBuffer)
70 {
71     stillimage *This = impl_from_StillImageW(iface);
72     FIXME("(%p, %u, 0x%X, %p, %p): stub\n", This, dwType, dwFlags, pdwItemsReturned, ppBuffer);
73     return E_NOTIMPL;
74 }
75
76 static HRESULT WINAPI stillimagew_GetDeviceInfo(IStillImageW *iface, LPWSTR pwszDeviceName,
77                                                 LPVOID *ppBuffer)
78 {
79     stillimage *This = impl_from_StillImageW(iface);
80     FIXME("(%p, %s, %p): stub\n", This, debugstr_w(pwszDeviceName), ppBuffer);
81     return E_NOTIMPL;
82 }
83
84 static HRESULT WINAPI stillimagew_CreateDevice(IStillImageW *iface, LPWSTR pwszDeviceName, DWORD dwMode,
85                                                PSTIDEVICEW *pDevice, LPUNKNOWN pUnkOuter)
86 {
87     stillimage *This = impl_from_StillImageW(iface);
88     FIXME("(%p, %s, %u, %p, %p): stub\n", This, debugstr_w(pwszDeviceName), dwMode, pDevice, pUnkOuter);
89     return E_NOTIMPL;
90 }
91
92 static HRESULT WINAPI stillimagew_GetDeviceValue(IStillImageW *iface, LPWSTR pwszDeviceName, LPWSTR pValueName,
93                                                  LPDWORD pType, LPBYTE pData, LPDWORD cbData)
94 {
95     stillimage *This = impl_from_StillImageW(iface);
96     FIXME("(%p, %s, %s, %p, %p, %p): stub\n", This, debugstr_w(pwszDeviceName), debugstr_w(pValueName),
97         pType, pData, cbData);
98     return E_NOTIMPL;
99 }
100
101 static HRESULT WINAPI stillimagew_SetDeviceValue(IStillImageW *iface, LPWSTR pwszDeviceName, LPWSTR pValueName,
102                                                  DWORD type, LPBYTE pData, DWORD cbData)
103 {
104     stillimage *This = impl_from_StillImageW(iface);
105     FIXME("(%p, %s, %s, %u, %p, %u): stub\n", This, debugstr_w(pwszDeviceName), debugstr_w(pValueName),
106         type, pData, cbData);
107     return E_NOTIMPL;
108 }
109
110 static HRESULT WINAPI stillimagew_GetSTILaunchInformation(IStillImageW *iface, LPWSTR pwszDeviceName,
111                                                           DWORD *pdwEventCode, LPWSTR pwszEventName)
112 {
113     stillimage *This = impl_from_StillImageW(iface);
114     FIXME("(%p, %p, %p, %p): stub\n", This, pwszDeviceName,
115         pdwEventCode, pwszEventName);
116     return E_NOTIMPL;
117 }
118
119 static HRESULT WINAPI stillimagew_RegisterLaunchApplication(IStillImageW *iface, LPWSTR pwszAppName,
120                                                             LPWSTR pwszCommandLine)
121 {
122     stillimage *This = impl_from_StillImageW(iface);
123     FIXME("(%p, %s, %s): stub\n", This, debugstr_w(pwszAppName), debugstr_w(pwszCommandLine));
124     return E_NOTIMPL;
125 }
126
127 static HRESULT WINAPI stillimagew_UnregisterLaunchApplication(IStillImageW *iface, LPWSTR pwszAppName)
128 {
129     stillimage *This = impl_from_StillImageW(iface);
130     FIXME("(%p, %s): stub\n", This, debugstr_w(pwszAppName));
131     return S_OK;
132 }
133
134 static HRESULT WINAPI stillimagew_EnableHwNotifications(IStillImageW *iface, LPCWSTR pwszDeviceName,
135                                                         BOOL bNewState)
136 {
137     stillimage *This = impl_from_StillImageW(iface);
138     FIXME("(%p, %s, %u): stub\n", This, debugstr_w(pwszDeviceName), bNewState);
139     return E_NOTIMPL;
140 }
141
142 static HRESULT WINAPI stillimagew_GetHwNotificationState(IStillImageW *iface, LPCWSTR pwszDeviceName,
143                                                          BOOL *pbCurrentState)
144 {
145     stillimage *This = impl_from_StillImageW(iface);
146     FIXME("(%p, %s, %p): stub\n", This, debugstr_w(pwszDeviceName), pbCurrentState);
147     return E_NOTIMPL;
148 }
149
150 static HRESULT WINAPI stillimagew_RefreshDeviceBus(IStillImageW *iface, LPCWSTR pwszDeviceName)
151 {
152     stillimage *This = impl_from_StillImageW(iface);
153     FIXME("(%p, %s): stub\n", This, debugstr_w(pwszDeviceName));
154     return E_NOTIMPL;
155 }
156
157 static HRESULT WINAPI stillimagew_LaunchApplicationForDevice(IStillImageW *iface, LPWSTR pwszDeviceName,
158                                                              LPWSTR pwszAppName, LPSTINOTIFY pStiNotify)
159 {
160     stillimage *This = impl_from_StillImageW(iface);
161     FIXME("(%p, %s, %s, %p): stub\n", This, debugstr_w(pwszDeviceName), debugstr_w(pwszAppName),
162         pStiNotify);
163     return E_NOTIMPL;
164 }
165
166 static HRESULT WINAPI stillimagew_SetupDeviceParameters(IStillImageW *iface, PSTI_DEVICE_INFORMATIONW pDevInfo)
167 {
168     stillimage *This = impl_from_StillImageW(iface);
169     FIXME("(%p, %p): stub\n", This, pDevInfo);
170     return E_NOTIMPL;
171 }
172
173 static HRESULT WINAPI stillimagew_WriteToErrorLog(IStillImageW *iface, DWORD dwMessageType, LPCWSTR pszMessage)
174 {
175     stillimage *This = impl_from_StillImageW(iface);
176     FIXME("(%p, %u, %s): stub\n", This, dwMessageType, debugstr_w(pszMessage));
177     return E_NOTIMPL;
178 }
179
180 static const struct IStillImageWVtbl stillimagew_vtbl =
181 {
182     stillimagew_QueryInterface,
183     stillimagew_AddRef,
184     stillimagew_Release,
185     stillimagew_Initialize,
186     stillimagew_GetDeviceList,
187     stillimagew_GetDeviceInfo,
188     stillimagew_CreateDevice,
189     stillimagew_GetDeviceValue,
190     stillimagew_SetDeviceValue,
191     stillimagew_GetSTILaunchInformation,
192     stillimagew_RegisterLaunchApplication,
193     stillimagew_UnregisterLaunchApplication,
194     stillimagew_EnableHwNotifications,
195     stillimagew_GetHwNotificationState,
196     stillimagew_RefreshDeviceBus,
197     stillimagew_LaunchApplicationForDevice,
198     stillimagew_SetupDeviceParameters,
199     stillimagew_WriteToErrorLog
200 };
201
202 static inline stillimage *impl_from_InternalUnknown(IUnknown *iface)
203 {
204     return (stillimage *)((char*)iface - FIELD_OFFSET(stillimage, lpInternalUnkVtbl));
205 }
206
207 static HRESULT WINAPI Internal_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObject)
208 {
209     stillimage *This = impl_from_InternalUnknown(iface);
210
211     TRACE("(%p %s %p)\n", This, debugstr_guid(riid), ppvObject);
212
213     if (IsEqualGUID(riid, &IID_IUnknown))
214         *ppvObject = iface;
215     else if (IsEqualGUID(riid, &IID_IStillImageW))
216         *ppvObject = &This->lpVtbl;
217     else
218     {
219         if (IsEqualGUID(riid, &IID_IStillImageA))
220             FIXME("interface IStillImageA is unsupported on Windows Vista too, please report if it's needed\n");
221         else
222             FIXME("interface %s not implemented\n", debugstr_guid(riid));
223         *ppvObject = NULL;
224         return E_NOINTERFACE;
225     }
226
227     IUnknown_AddRef((IUnknown*) *ppvObject);
228     return S_OK;
229 }
230
231 static ULONG WINAPI Internal_AddRef(IUnknown *iface)
232 {
233     stillimage *This = impl_from_InternalUnknown(iface);
234     return InterlockedIncrement(&This->ref);
235 }
236
237 static ULONG WINAPI Internal_Release(IUnknown *iface)
238 {
239     ULONG ref;
240     stillimage *This = impl_from_InternalUnknown(iface);
241
242     ref = InterlockedDecrement(&This->ref);
243     if (ref == 0)
244         HeapFree(GetProcessHeap(), 0, This);
245     return ref;
246 }
247
248 static const struct IUnknownVtbl internal_unk_vtbl =
249 {
250     Internal_QueryInterface,
251     Internal_AddRef,
252     Internal_Release
253 };
254
255 /******************************************************************************
256  *           StiCreateInstanceA   (STI.@)
257  */
258 HRESULT WINAPI StiCreateInstanceA(HINSTANCE hinst, DWORD dwVer, PSTIA *ppSti, LPUNKNOWN pUnkOuter)
259 {
260     FIXME("(%p, %u, %p, %p): stub, unimplemented on Windows Vista too, please report if it's needed\n", hinst, dwVer, ppSti, pUnkOuter);
261     return STG_E_UNIMPLEMENTEDFUNCTION;
262 }
263
264 /******************************************************************************
265  *           StiCreateInstanceW   (STI.@)
266  */
267 HRESULT WINAPI StiCreateInstanceW(HINSTANCE hinst, DWORD dwVer, PSTIW *ppSti, LPUNKNOWN pUnkOuter)
268 {
269     stillimage *This;
270     HRESULT hr;
271
272     TRACE("(%p, %u, %p, %p)\n", hinst, dwVer, ppSti, pUnkOuter);
273
274     This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(stillimage));
275     if (This)
276     {
277         This->lpVtbl = &stillimagew_vtbl;
278         This->lpInternalUnkVtbl = &internal_unk_vtbl;
279         if (pUnkOuter)
280             This->pUnkOuter = pUnkOuter;
281         else
282             This->pUnkOuter = (IUnknown*) &This->lpInternalUnkVtbl;
283         This->ref = 1;
284
285         hr = IStillImage_Initialize((IStillImageW*) &This->lpVtbl, hinst, dwVer);
286         if (SUCCEEDED(hr))
287         {
288             if (pUnkOuter)
289                 *ppSti = (IStillImageW*) &This->lpInternalUnkVtbl;
290             else
291                 *ppSti = (IStillImageW*) &This->lpVtbl;
292         }
293     }
294     else
295         hr = E_OUTOFMEMORY;
296
297     return hr;
298 }