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
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
);
45 DISPPARAMS dispparams
;
50 typedef struct ErrorInfoImpl
52 IErrorInfo IErrorInfo_iface
;
53 IErrorRecords IErrorRecords_iface
;
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
);
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
;
87 IUnknown_AddRef( (IUnknown
*)*ppvoid
);
91 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
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);
112 LIST_FOR_EACH_ENTRY_SAFE(cursor
, cursor2
, &This
->errors
, struct ErrorEntry
, entry
)
114 list_remove(&cursor
->entry
);
116 IUnknown_Release(cursor
->unknown
);
125 static HRESULT WINAPI
IErrorInfoImpl_GetGUID(IErrorInfo
* iface
, GUID
*guid
)
127 ErrorInfoImpl
*This
= impl_from_IErrorInfo(iface
);
129 TRACE("(%p)->(%p)\n", This
, guid
);
139 static HRESULT WINAPI
IErrorInfoImpl_GetSource(IErrorInfo
* iface
, BSTR
*source
)
141 ErrorInfoImpl
*This
= impl_from_IErrorInfo(iface
);
143 TRACE("(%p)->(%p)\n", This
, source
);
153 static HRESULT WINAPI
IErrorInfoImpl_GetDescription(IErrorInfo
* iface
, BSTR
*description
)
155 ErrorInfoImpl
*This
= impl_from_IErrorInfo(iface
);
157 TRACE("(%p)->(%p)\n", This
, description
);
167 static HRESULT WINAPI
IErrorInfoImpl_GetHelpFile(IErrorInfo
* iface
, BSTR
*helpfile
)
169 ErrorInfoImpl
*This
= impl_from_IErrorInfo(iface
);
171 TRACE("(%p)->(%p)\n", This
, helpfile
);
181 static HRESULT WINAPI
IErrorInfoImpl_GetHelpContext(IErrorInfo
* iface
, DWORD
*context
)
183 ErrorInfoImpl
*This
= impl_from_IErrorInfo(iface
);
185 TRACE("(%p)->(%p)\n", This
, context
);
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
);
236 entry
= heap_alloc(sizeof(*entry
));
238 return E_OUTOFMEMORY
;
240 entry
->info
= *pErrorInfo
;
242 entry
->dispparams
= *pdispparams
;
243 entry
->unknown
= punkCustomError
;
245 IUnknown_AddRef(entry
->unknown
);
246 entry
->lookupID
= dwDynamicErrorID
;
248 list_add_head(&This
->errors
, &entry
->entry
);
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
);
263 if(ulRecordNum
> list_count(&This
->errors
))
264 return DB_E_BADRECORDNUM
;
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
);
281 if(ulRecordNum
> list_count(&This
->errors
))
282 return DB_E_BADRECORDNUM
;
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
);
297 if(ulRecordNum
> list_count(&This
->errors
))
298 return DB_E_BADRECORDNUM
;
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
);
313 if(ulRecordNum
> list_count(&This
->errors
))
314 return DB_E_BADRECORDNUM
;
319 static HRESULT WINAPI
errorrec_GetRecordCount(IErrorRecords
*iface
, ULONG
*records
)
321 ErrorInfoImpl
*This
= impl_from_IErrorRecords(iface
);
323 TRACE("(%p)->(%p)\n", This
, records
);
328 *records
= list_count(&This
->errors
);
330 TRACE("<--(%d)\n", *records
);
335 static const IErrorRecordsVtbl ErrorRecordsVtbl
=
337 errorrec_QueryInterface
,
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
)
352 TRACE("(%p, %p)\n", outer
, obj
);
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
;
365 list_init(&This
->errors
);
367 *obj
= &This
->IErrorInfo_iface
;