ddraw/tests: Add readback tests to test_palette_gdi.
[wine.git] / dlls / oledb32 / errorinfo.c
blob4a56b46d105251a87468385c4cc39c7ec58669eb
1 /* OLE DB ErrorInfo
3 * Copyright 2013 Alistair Leslie-Hughes
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
19 #include <stdarg.h>
20 #include <string.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "objbase.h"
27 #include "oleauto.h"
28 #include "winerror.h"
29 #include "oledb.h"
30 #include "oledberr.h"
32 #include "oledb_private.h"
34 #include "wine/unicode.h"
35 #include "wine/list.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(oledb);
41 struct ErrorEntry
43 struct list entry;
44 ERRORINFO info;
45 DISPPARAMS dispparams;
46 IUnknown *unknown;
47 DWORD lookupID;
50 typedef struct ErrorInfoImpl
52 IErrorInfo IErrorInfo_iface;
53 IErrorRecords IErrorRecords_iface;
54 LONG ref;
56 struct list errors;
57 } ErrorInfoImpl;
59 static inline ErrorInfoImpl *impl_from_IErrorInfo( IErrorInfo *iface )
61 return CONTAINING_RECORD(iface, ErrorInfoImpl, IErrorInfo_iface);
64 static inline ErrorInfoImpl *impl_from_IErrorRecords( IErrorRecords *iface )
66 return CONTAINING_RECORD(iface, ErrorInfoImpl, IErrorRecords_iface);
69 static HRESULT WINAPI IErrorInfoImpl_QueryInterface(IErrorInfo* iface, REFIID riid, void **ppvoid)
71 ErrorInfoImpl *This = impl_from_IErrorInfo(iface);
72 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid),ppvoid);
74 *ppvoid = NULL;
76 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IErrorInfo))
78 *ppvoid = &This->IErrorInfo_iface;
80 else if (IsEqualIID(riid, &IID_IErrorRecords))
82 *ppvoid = &This->IErrorRecords_iface;
85 if(*ppvoid)
87 IUnknown_AddRef( (IUnknown*)*ppvoid );
88 return S_OK;
91 FIXME("interface %s not implemented\n", debugstr_guid(riid));
92 return E_NOINTERFACE;
95 static ULONG WINAPI IErrorInfoImpl_AddRef(IErrorInfo* iface)
97 ErrorInfoImpl *This = impl_from_IErrorInfo(iface);
98 TRACE("(%p)->%u\n",This,This->ref);
99 return InterlockedIncrement(&This->ref);
102 static ULONG WINAPI IErrorInfoImpl_Release(IErrorInfo* iface)
104 ErrorInfoImpl *This = impl_from_IErrorInfo(iface);
105 ULONG ref = InterlockedDecrement(&This->ref);
106 struct ErrorEntry *cursor, *cursor2;
108 TRACE("(%p)->%u\n",This,ref+1);
110 if (!ref)
112 LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, &This->errors, struct ErrorEntry, entry)
114 list_remove(&cursor->entry);
115 if(cursor->unknown)
116 IUnknown_Release(cursor->unknown);
118 heap_free(cursor);
120 heap_free(This);
122 return ref;
125 static HRESULT WINAPI IErrorInfoImpl_GetGUID(IErrorInfo* iface, GUID *guid)
127 ErrorInfoImpl *This = impl_from_IErrorInfo(iface);
129 TRACE("(%p)->(%p)\n", This, guid);
131 if (!guid)
132 return E_INVALIDARG;
134 *guid = GUID_NULL;
136 return S_OK;
139 static HRESULT WINAPI IErrorInfoImpl_GetSource(IErrorInfo* iface, BSTR *source)
141 ErrorInfoImpl *This = impl_from_IErrorInfo(iface);
143 TRACE("(%p)->(%p)\n", This, source);
145 if (!source)
146 return E_INVALIDARG;
148 *source = NULL;
150 return E_FAIL;
153 static HRESULT WINAPI IErrorInfoImpl_GetDescription(IErrorInfo* iface, BSTR *description)
155 ErrorInfoImpl *This = impl_from_IErrorInfo(iface);
157 TRACE("(%p)->(%p)\n", This, description);
159 if (!description)
160 return E_INVALIDARG;
162 *description = NULL;
164 return E_FAIL;
167 static HRESULT WINAPI IErrorInfoImpl_GetHelpFile(IErrorInfo* iface, BSTR *helpfile)
169 ErrorInfoImpl *This = impl_from_IErrorInfo(iface);
171 TRACE("(%p)->(%p)\n", This, helpfile);
173 if (!helpfile)
174 return E_INVALIDARG;
176 *helpfile = NULL;
178 return E_FAIL;
181 static HRESULT WINAPI IErrorInfoImpl_GetHelpContext(IErrorInfo* iface, DWORD *context)
183 ErrorInfoImpl *This = impl_from_IErrorInfo(iface);
185 TRACE("(%p)->(%p)\n", This, context);
187 if (!context)
188 return E_INVALIDARG;
190 *context = 0;
192 return E_FAIL;
195 static const IErrorInfoVtbl ErrorInfoVtbl =
197 IErrorInfoImpl_QueryInterface,
198 IErrorInfoImpl_AddRef,
199 IErrorInfoImpl_Release,
200 IErrorInfoImpl_GetGUID,
201 IErrorInfoImpl_GetSource,
202 IErrorInfoImpl_GetDescription,
203 IErrorInfoImpl_GetHelpFile,
204 IErrorInfoImpl_GetHelpContext
207 static HRESULT WINAPI errorrec_QueryInterface(IErrorRecords *iface, REFIID riid, void **ppvObject)
209 ErrorInfoImpl *This = impl_from_IErrorRecords(iface);
210 return IErrorInfo_QueryInterface(&This->IErrorInfo_iface, riid, ppvObject);
213 static ULONG WINAPI WINAPI errorrec_AddRef(IErrorRecords *iface)
215 ErrorInfoImpl *This = impl_from_IErrorRecords(iface);
216 return IErrorInfo_AddRef(&This->IErrorInfo_iface);
219 static ULONG WINAPI WINAPI errorrec_Release(IErrorRecords *iface)
221 ErrorInfoImpl *This = impl_from_IErrorRecords(iface);
222 return IErrorInfo_Release(&This->IErrorInfo_iface);
225 static HRESULT WINAPI errorrec_AddErrorRecord(IErrorRecords *iface, ERRORINFO *pErrorInfo,
226 DWORD dwLookupID, DISPPARAMS *pdispparams, IUnknown *punkCustomError, DWORD dwDynamicErrorID)
228 ErrorInfoImpl *This = impl_from_IErrorRecords(iface);
229 struct ErrorEntry *entry;
231 TRACE("(%p)->(%p %d %p %p %d)\n", This, pErrorInfo, dwLookupID, pdispparams, punkCustomError, dwDynamicErrorID);
233 if(!pErrorInfo)
234 return E_INVALIDARG;
236 entry = heap_alloc(sizeof(*entry));
237 if(!entry)
238 return E_OUTOFMEMORY;
240 entry->info = *pErrorInfo;
241 if(pdispparams)
242 entry->dispparams = *pdispparams;
243 entry->unknown = punkCustomError;
244 if(entry->unknown)
245 IUnknown_AddRef(entry->unknown);
246 entry->lookupID = dwDynamicErrorID;
248 list_add_head(&This->errors, &entry->entry);
250 return S_OK;
253 static HRESULT WINAPI errorrec_GetBasicErrorInfo(IErrorRecords *iface, ULONG ulRecordNum,
254 ERRORINFO *pErrorInfo)
256 ErrorInfoImpl *This = impl_from_IErrorRecords(iface);
258 FIXME("(%p)->(%d %p)\n", This, ulRecordNum, pErrorInfo);
260 if(!pErrorInfo)
261 return E_INVALIDARG;
263 if(ulRecordNum > list_count(&This->errors))
264 return DB_E_BADRECORDNUM;
266 return E_NOTIMPL;
269 static HRESULT WINAPI errorrec_GetCustomErrorObject(IErrorRecords *iface, ULONG ulRecordNum,
270 REFIID riid, IUnknown **ppObject)
272 ErrorInfoImpl *This = impl_from_IErrorRecords(iface);
274 FIXME("(%p)->(%d %s, %p)\n", This, ulRecordNum, debugstr_guid(riid), ppObject);
276 if (!ppObject)
277 return E_INVALIDARG;
279 *ppObject = NULL;
281 if(ulRecordNum > list_count(&This->errors))
282 return DB_E_BADRECORDNUM;
284 return E_NOTIMPL;
287 static HRESULT WINAPI errorrec_GetErrorInfo(IErrorRecords *iface, ULONG ulRecordNum,
288 LCID lcid, IErrorInfo **ppErrorInfo)
290 ErrorInfoImpl *This = impl_from_IErrorRecords(iface);
292 FIXME("(%p)->(%d %d, %p)\n", This, ulRecordNum, lcid, ppErrorInfo);
294 if (!ppErrorInfo)
295 return E_INVALIDARG;
297 if(ulRecordNum > list_count(&This->errors))
298 return DB_E_BADRECORDNUM;
300 return E_NOTIMPL;
303 static HRESULT WINAPI errorrec_GetErrorParameters(IErrorRecords *iface, ULONG ulRecordNum,
304 DISPPARAMS *pdispparams)
306 ErrorInfoImpl *This = impl_from_IErrorRecords(iface);
308 FIXME("(%p)->(%d %p)\n", This, ulRecordNum, pdispparams);
310 if (!pdispparams)
311 return E_INVALIDARG;
313 if(ulRecordNum > list_count(&This->errors))
314 return DB_E_BADRECORDNUM;
316 return E_NOTIMPL;
319 static HRESULT WINAPI errorrec_GetRecordCount(IErrorRecords *iface, ULONG *records)
321 ErrorInfoImpl *This = impl_from_IErrorRecords(iface);
323 TRACE("(%p)->(%p)\n", This, records);
325 if(!records)
326 return E_INVALIDARG;
328 *records = list_count(&This->errors);
330 TRACE("<--(%d)\n", *records);
332 return S_OK;
335 static const IErrorRecordsVtbl ErrorRecordsVtbl =
337 errorrec_QueryInterface,
338 errorrec_AddRef,
339 errorrec_Release,
340 errorrec_AddErrorRecord,
341 errorrec_GetBasicErrorInfo,
342 errorrec_GetCustomErrorObject,
343 errorrec_GetErrorInfo,
344 errorrec_GetErrorParameters,
345 errorrec_GetRecordCount
348 HRESULT create_error_info(IUnknown *outer, void **obj)
350 ErrorInfoImpl *This;
352 TRACE("(%p, %p)\n", outer, obj);
354 *obj = NULL;
356 if(outer) return CLASS_E_NOAGGREGATION;
358 This = heap_alloc(sizeof(*This));
359 if(!This) return E_OUTOFMEMORY;
361 This->IErrorInfo_iface.lpVtbl = &ErrorInfoVtbl;
362 This->IErrorRecords_iface.lpVtbl = &ErrorRecordsVtbl;
363 This->ref = 1;
365 list_init(&This->errors);
367 *obj = &This->IErrorInfo_iface;
369 return S_OK;