Sweden-Number/dlls/oledb32/errorinfo.c

437 lines
11 KiB
C
Raw Normal View History

2013-06-14 02:23:43 +02:00
/* OLE DB ErrorInfo
*
* Copyright 2013 Alistair Leslie-Hughes
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdarg.h>
#include <string.h>
#define COBJMACROS
#include "windef.h"
#include "winbase.h"
#include "objbase.h"
#include "oleauto.h"
#include "winerror.h"
#include "oledb.h"
#include "oledberr.h"
#include "oledb_private.h"
#include "wine/heap.h"
2013-06-14 02:23:43 +02:00
#include "wine/list.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(oledb);
struct ErrorEntry
{
ERRORINFO info;
2013-06-14 02:23:43 +02:00
DISPPARAMS dispparams;
IUnknown *custom_error;
2013-06-14 02:23:43 +02:00
DWORD lookupID;
};
typedef struct errorrecords
2013-06-14 02:23:43 +02:00
{
IErrorInfo IErrorInfo_iface;
IErrorRecords IErrorRecords_iface;
LONG ref;
struct ErrorEntry *records;
unsigned int allocated;
unsigned int count;
} errorrecords;
2013-06-14 02:23:43 +02:00
static inline errorrecords *impl_from_IErrorInfo( IErrorInfo *iface )
2013-06-14 02:23:43 +02:00
{
return CONTAINING_RECORD(iface, errorrecords, IErrorInfo_iface);
2013-06-14 02:23:43 +02:00
}
static inline errorrecords *impl_from_IErrorRecords( IErrorRecords *iface )
2013-06-14 02:23:43 +02:00
{
return CONTAINING_RECORD(iface, errorrecords, IErrorRecords_iface);
2013-06-14 02:23:43 +02:00
}
static HRESULT WINAPI errorrecords_QueryInterface(IErrorInfo* iface, REFIID riid, void **ppvoid)
2013-06-14 02:23:43 +02:00
{
errorrecords *This = impl_from_IErrorInfo(iface);
2013-06-14 02:23:43 +02:00
TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid),ppvoid);
*ppvoid = NULL;
if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IErrorInfo))
{
*ppvoid = &This->IErrorInfo_iface;
}
else if (IsEqualIID(riid, &IID_IErrorRecords))
{
*ppvoid = &This->IErrorRecords_iface;
}
if(*ppvoid)
{
IUnknown_AddRef( (IUnknown*)*ppvoid );
return S_OK;
}
FIXME("interface %s not implemented\n", debugstr_guid(riid));
return E_NOINTERFACE;
}
static ULONG WINAPI errorrecords_AddRef(IErrorInfo* iface)
2013-06-14 02:23:43 +02:00
{
errorrecords *This = impl_from_IErrorInfo(iface);
TRACE("(%p)->%lu\n",This,This->ref);
2013-06-14 02:23:43 +02:00
return InterlockedIncrement(&This->ref);
}
static ULONG WINAPI errorrecords_Release(IErrorInfo* iface)
2013-06-14 02:23:43 +02:00
{
errorrecords *This = impl_from_IErrorInfo(iface);
2013-06-14 02:23:43 +02:00
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p)->%lu\n",This,ref+1);
2013-06-14 02:23:43 +02:00
if (!ref)
{
unsigned int i;
for (i = 0; i < This->count; i++)
{
DISPPARAMS *dispparams = &This->records[i].dispparams;
unsigned int j;
if (This->records[i].custom_error)
IUnknown_Release(This->records[i].custom_error);
for (j = 0; j < dispparams->cArgs && dispparams->rgvarg; j++)
VariantClear(&dispparams->rgvarg[i]);
CoTaskMemFree(dispparams->rgvarg);
CoTaskMemFree(dispparams->rgdispidNamedArgs);
}
heap_free(This->records);
heap_free(This);
2013-06-14 02:23:43 +02:00
}
return ref;
}
static HRESULT WINAPI errorrecords_GetGUID(IErrorInfo* iface, GUID *guid)
2013-06-14 02:23:43 +02:00
{
errorrecords *This = impl_from_IErrorInfo(iface);
2013-06-14 02:23:43 +02:00
TRACE("(%p)->(%p)\n", This, guid);
2013-06-14 02:23:43 +02:00
if (!guid)
2013-06-14 02:23:43 +02:00
return E_INVALIDARG;
*guid = GUID_NULL;
2013-06-14 02:23:43 +02:00
return S_OK;
}
static HRESULT WINAPI errorrecords_GetSource(IErrorInfo* iface, BSTR *source)
2013-06-14 02:23:43 +02:00
{
errorrecords *This = impl_from_IErrorInfo(iface);
2013-06-14 02:23:43 +02:00
TRACE("(%p)->(%p)\n", This, source);
2013-06-14 02:23:43 +02:00
if (!source)
2013-06-14 02:23:43 +02:00
return E_INVALIDARG;
*source = NULL;
2013-06-14 02:23:43 +02:00
return E_FAIL;
2013-06-14 02:23:43 +02:00
}
static HRESULT WINAPI errorrecords_GetDescription(IErrorInfo* iface, BSTR *description)
2013-06-14 02:23:43 +02:00
{
errorrecords *This = impl_from_IErrorInfo(iface);
2013-06-14 02:23:43 +02:00
TRACE("(%p)->(%p)\n", This, description);
2013-06-14 02:23:43 +02:00
if (!description)
2013-06-14 02:23:43 +02:00
return E_INVALIDARG;
*description = NULL;
2013-06-14 02:23:43 +02:00
return E_FAIL;
2013-06-14 02:23:43 +02:00
}
static HRESULT WINAPI errorrecords_GetHelpFile(IErrorInfo* iface, BSTR *helpfile)
2013-06-14 02:23:43 +02:00
{
errorrecords *This = impl_from_IErrorInfo(iface);
2013-06-14 02:23:43 +02:00
TRACE("(%p)->(%p)\n", This, helpfile);
2013-06-14 02:23:43 +02:00
if (!helpfile)
2013-06-14 02:23:43 +02:00
return E_INVALIDARG;
*helpfile = NULL;
2013-06-14 02:23:43 +02:00
return E_FAIL;
2013-06-14 02:23:43 +02:00
}
static HRESULT WINAPI errorrecords_GetHelpContext(IErrorInfo* iface, DWORD *context)
2013-06-14 02:23:43 +02:00
{
errorrecords *This = impl_from_IErrorInfo(iface);
2013-06-14 02:23:43 +02:00
TRACE("(%p)->(%p)\n", This, context);
2013-06-14 02:23:43 +02:00
if (!context)
2013-06-14 02:23:43 +02:00
return E_INVALIDARG;
*context = 0;
2013-06-14 02:23:43 +02:00
return E_FAIL;
2013-06-14 02:23:43 +02:00
}
static const IErrorInfoVtbl ErrorInfoVtbl =
{
errorrecords_QueryInterface,
errorrecords_AddRef,
errorrecords_Release,
errorrecords_GetGUID,
errorrecords_GetSource,
errorrecords_GetDescription,
errorrecords_GetHelpFile,
errorrecords_GetHelpContext
2013-06-14 02:23:43 +02:00
};
static HRESULT WINAPI errorrec_QueryInterface(IErrorRecords *iface, REFIID riid, void **ppvObject)
{
errorrecords *This = impl_from_IErrorRecords(iface);
2013-06-14 02:23:43 +02:00
return IErrorInfo_QueryInterface(&This->IErrorInfo_iface, riid, ppvObject);
}
static ULONG WINAPI errorrec_AddRef(IErrorRecords *iface)
2013-06-14 02:23:43 +02:00
{
errorrecords *This = impl_from_IErrorRecords(iface);
2013-06-14 02:23:43 +02:00
return IErrorInfo_AddRef(&This->IErrorInfo_iface);
}
static ULONG WINAPI errorrec_Release(IErrorRecords *iface)
2013-06-14 02:23:43 +02:00
{
errorrecords *This = impl_from_IErrorRecords(iface);
2013-06-14 02:23:43 +02:00
return IErrorInfo_Release(&This->IErrorInfo_iface);
}
static HRESULT dup_dispparams(DISPPARAMS *src, DISPPARAMS *dest)
{
unsigned int i;
if (!src)
{
memset(dest, 0, sizeof(*dest));
return S_OK;
}
*dest = *src;
if (src->cArgs)
{
dest->rgvarg = CoTaskMemAlloc(dest->cArgs * sizeof(*dest->rgvarg));
for (i = 0; i < src->cArgs; i++)
{
VariantInit(&dest->rgvarg[i]);
VariantCopy(&dest->rgvarg[i], &src->rgvarg[i]);
}
}
if (src->cNamedArgs)
{
dest->rgdispidNamedArgs = CoTaskMemAlloc(dest->cNamedArgs * sizeof(*dest->rgdispidNamedArgs));
memcpy(dest->rgdispidNamedArgs, src->rgdispidNamedArgs, dest->cNamedArgs * sizeof(*dest->rgdispidNamedArgs));
}
return S_OK;
}
2013-06-14 02:23:43 +02:00
static HRESULT WINAPI errorrec_AddErrorRecord(IErrorRecords *iface, ERRORINFO *pErrorInfo,
DWORD dwLookupID, DISPPARAMS *pdispparams, IUnknown *punkCustomError, DWORD dwDynamicErrorID)
{
errorrecords *This = impl_from_IErrorRecords(iface);
struct ErrorEntry *entry;
HRESULT hr;
2013-06-14 02:23:43 +02:00
TRACE("(%p)->(%p %ld %p %p %ld)\n", This, pErrorInfo, dwLookupID, pdispparams, punkCustomError, dwDynamicErrorID);
2013-06-14 02:23:43 +02:00
if(!pErrorInfo)
2013-06-14 02:23:43 +02:00
return E_INVALIDARG;
if (!This->records)
{
const unsigned int initial_size = 16;
if (!(This->records = heap_alloc(initial_size * sizeof(*This->records))))
return E_OUTOFMEMORY;
This->allocated = initial_size;
}
else if (This->count == This->allocated)
{
struct ErrorEntry *new_ptr;
new_ptr = heap_realloc(This->records, 2 * This->allocated * sizeof(*This->records));
if (!new_ptr)
return E_OUTOFMEMORY;
This->records = new_ptr;
This->allocated *= 2;
}
entry = This->records + This->count;
entry->info = *pErrorInfo;
if (FAILED(hr = dup_dispparams(pdispparams, &entry->dispparams)))
return hr;
entry->custom_error = punkCustomError;
if (entry->custom_error)
IUnknown_AddRef(entry->custom_error);
entry->lookupID = dwDynamicErrorID;
This->count++;
2013-06-14 02:23:43 +02:00
return S_OK;
}
static HRESULT WINAPI errorrec_GetBasicErrorInfo(IErrorRecords *iface, ULONG index, ERRORINFO *info)
2013-06-14 02:23:43 +02:00
{
errorrecords *This = impl_from_IErrorRecords(iface);
2013-06-14 02:23:43 +02:00
TRACE("(%p)->(%lu %p)\n", This, index, info);
2013-06-14 02:23:43 +02:00
if (!info)
2013-06-14 02:23:43 +02:00
return E_INVALIDARG;
if (index >= This->count)
2013-06-14 02:23:43 +02:00
return DB_E_BADRECORDNUM;
index = This->count - index - 1;
*info = This->records[index].info;
return S_OK;
2013-06-14 02:23:43 +02:00
}
static HRESULT WINAPI errorrec_GetCustomErrorObject(IErrorRecords *iface, ULONG index,
REFIID riid, IUnknown **object)
2013-06-14 02:23:43 +02:00
{
errorrecords *This = impl_from_IErrorRecords(iface);
2013-06-14 02:23:43 +02:00
TRACE("(%p)->(%lu %s %p)\n", This, index, debugstr_guid(riid), object);
2013-06-14 02:23:43 +02:00
if (!object)
2013-06-14 02:23:43 +02:00
return E_INVALIDARG;
*object = NULL;
2013-06-14 02:23:43 +02:00
if (index >= This->count)
2013-06-14 02:23:43 +02:00
return DB_E_BADRECORDNUM;
index = This->count - index - 1;
if (This->records[index].custom_error)
return IUnknown_QueryInterface(This->records[index].custom_error, riid, (void **)object);
else
return S_OK;
2013-06-14 02:23:43 +02:00
}
static HRESULT WINAPI errorrec_GetErrorInfo(IErrorRecords *iface, ULONG index,
2013-06-14 02:23:43 +02:00
LCID lcid, IErrorInfo **ppErrorInfo)
{
errorrecords *This = impl_from_IErrorRecords(iface);
2013-06-14 02:23:43 +02:00
FIXME("(%p)->(%lu %ld, %p)\n", This, index, lcid, ppErrorInfo);
2013-06-14 02:23:43 +02:00
if (!ppErrorInfo)
return E_INVALIDARG;
if (index >= This->count)
2013-06-14 02:23:43 +02:00
return DB_E_BADRECORDNUM;
return IErrorInfo_QueryInterface(&This->IErrorInfo_iface, &IID_IErrorInfo, (void **)ppErrorInfo);
2013-06-14 02:23:43 +02:00
}
static HRESULT WINAPI errorrec_GetErrorParameters(IErrorRecords *iface, ULONG index, DISPPARAMS *pdispparams)
2013-06-14 02:23:43 +02:00
{
errorrecords *This = impl_from_IErrorRecords(iface);
2013-06-14 02:23:43 +02:00
TRACE("(%p)->(%lu %p)\n", This, index, pdispparams);
2013-06-14 02:23:43 +02:00
if (!pdispparams)
return E_INVALIDARG;
if (index >= This->count)
2013-06-14 02:23:43 +02:00
return DB_E_BADRECORDNUM;
index = This->count - index - 1;
return dup_dispparams(&This->records[index].dispparams, pdispparams);
2013-06-14 02:23:43 +02:00
}
static HRESULT WINAPI errorrec_GetRecordCount(IErrorRecords *iface, ULONG *count)
2013-06-14 02:23:43 +02:00
{
errorrecords *This = impl_from_IErrorRecords(iface);
2013-06-14 02:23:43 +02:00
TRACE("(%p)->(%p)\n", This, count);
2013-06-14 02:23:43 +02:00
if(!count)
2013-06-14 02:23:43 +02:00
return E_INVALIDARG;
*count = This->count;
2013-06-14 02:23:43 +02:00
TRACE("<--(%lu)\n", *count);
2013-06-14 02:23:43 +02:00
return S_OK;
}
static const IErrorRecordsVtbl ErrorRecordsVtbl =
{
errorrec_QueryInterface,
errorrec_AddRef,
errorrec_Release,
errorrec_AddErrorRecord,
errorrec_GetBasicErrorInfo,
errorrec_GetCustomErrorObject,
errorrec_GetErrorInfo,
errorrec_GetErrorParameters,
errorrec_GetRecordCount
};
HRESULT create_error_info(IUnknown *outer, void **obj)
{
errorrecords *This;
2013-06-14 02:23:43 +02:00
TRACE("(%p, %p)\n", outer, obj);
*obj = NULL;
if(outer) return CLASS_E_NOAGGREGATION;
This = heap_alloc(sizeof(*This));
2013-06-14 02:23:43 +02:00
if(!This) return E_OUTOFMEMORY;
This->IErrorInfo_iface.lpVtbl = &ErrorInfoVtbl;
This->IErrorRecords_iface.lpVtbl = &ErrorRecordsVtbl;
This->ref = 1;
This->records = NULL;
This->allocated = 0;
This->count = 0;
2013-06-14 02:23:43 +02:00
*obj = &This->IErrorInfo_iface;
return S_OK;
}