1 /* OLE DB Conversion library
3 * Copyright 2009 Huw Davies
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
23 #define NONAMELESSUNION
24 #define NONAMELESSSTRUCT
32 #include "oledb_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(oledb);
40 const struct IDataConvertVtbl *lpVtbl;
41 const struct IDCInfoVtbl *lpDCInfoVtbl;
45 UINT version; /* Set by IDCInfo_SetInfo */
48 static inline convert *impl_from_IDataConvert(IDataConvert *iface)
50 return (convert *)((char*)iface - FIELD_OFFSET(convert, lpVtbl));
53 static inline convert *impl_from_IDCInfo(IDCInfo *iface)
55 return (convert *)((char*)iface - FIELD_OFFSET(convert, lpDCInfoVtbl));
58 static HRESULT WINAPI convert_QueryInterface(IDataConvert* iface,
62 convert *This = impl_from_IDataConvert(iface);
63 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), obj);
67 if(IsEqualIID(riid, &IID_IUnknown) ||
68 IsEqualIID(riid, &IID_IDataConvert))
72 else if(IsEqualIID(riid, &IID_IDCInfo))
74 *obj = &This->lpDCInfoVtbl;
78 FIXME("interface %s not implemented\n", debugstr_guid(riid));
82 IDataConvert_AddRef(iface);
87 static ULONG WINAPI convert_AddRef(IDataConvert* iface)
89 convert *This = impl_from_IDataConvert(iface);
90 TRACE("(%p)\n", This);
92 return InterlockedIncrement(&This->ref);
96 static ULONG WINAPI convert_Release(IDataConvert* iface)
98 convert *This = impl_from_IDataConvert(iface);
101 TRACE("(%p)\n", This);
103 ref = InterlockedDecrement(&This->ref);
106 HeapFree(GetProcessHeap(), 0, This);
112 static HRESULT WINAPI convert_DataConvert(IDataConvert* iface,
113 DBTYPE wSrcType, DBTYPE wDstType,
114 DBLENGTH cbSrcLength, DBLENGTH *pcbDstLength,
115 void *pSrc, void *pDst,
116 DBLENGTH cbDstMaxLength,
117 DBSTATUS dbsSrcStatus, DBSTATUS *pdbsDstStatus,
118 BYTE bPrecision, BYTE bScale,
119 DBDATACONVERT dwFlags)
121 convert *This = impl_from_IDataConvert(iface);
122 FIXME("(%p)->(%d, %d, %d, %p, %p, %p, %d, %d, %p, %d, %d, %x): stub\n", This,
123 wSrcType, wDstType, cbSrcLength, pcbDstLength, pSrc, pDst, cbDstMaxLength,
124 dbsSrcStatus, pdbsDstStatus, bPrecision, bScale, dwFlags);
129 static HRESULT WINAPI convert_CanConvert(IDataConvert* iface,
130 DBTYPE wSrcType, DBTYPE wDstType)
132 convert *This = impl_from_IDataConvert(iface);
133 FIXME("(%p)->(%d, %d): stub\n", This, wSrcType, wDstType);
138 static HRESULT WINAPI convert_GetConversionSize(IDataConvert* iface,
139 DBTYPE wSrcType, DBTYPE wDstType,
140 DBLENGTH *pcbSrcLength, DBLENGTH *pcbDstLength,
143 convert *This = impl_from_IDataConvert(iface);
144 FIXME("(%p)->(%d, %d, %p, %p, %p): stub\n", This, wSrcType, wDstType, pcbSrcLength, pcbDstLength, pSrc);
149 static const struct IDataConvertVtbl convert_vtbl =
151 convert_QueryInterface,
156 convert_GetConversionSize
159 static HRESULT WINAPI dcinfo_QueryInterface(IDCInfo* iface, REFIID riid, void **obj)
161 convert *This = impl_from_IDCInfo(iface);
163 return IDataConvert_QueryInterface((IDataConvert *)This, riid, obj);
166 static ULONG WINAPI dcinfo_AddRef(IDCInfo* iface)
168 convert *This = impl_from_IDCInfo(iface);
170 return IDataConvert_AddRef((IDataConvert *)This);
173 static ULONG WINAPI dcinfo_Release(IDCInfo* iface)
175 convert *This = impl_from_IDCInfo(iface);
177 return IDataConvert_Release((IDataConvert *)This);
180 static HRESULT WINAPI dcinfo_GetInfo(IDCInfo *iface, ULONG num, DCINFOTYPE types[], DCINFO **info_ptr)
182 convert *This = impl_from_IDCInfo(iface);
186 TRACE("(%p)->(%d, %p, %p)\n", This, num, types, info_ptr);
188 *info_ptr = infos = CoTaskMemAlloc(num * sizeof(*infos));
189 if(!infos) return E_OUTOFMEMORY;
191 for(i = 0; i < num; i++)
193 infos[i].eInfoType = types[i];
194 VariantInit(&infos[i].vData);
198 case DCINFOTYPE_VERSION:
199 V_VT(&infos[i].vData) = VT_UI4;
200 V_UI4(&infos[i].vData) = This->version;
208 static HRESULT WINAPI dcinfo_SetInfo(IDCInfo* iface, ULONG num, DCINFO info[])
210 convert *This = impl_from_IDCInfo(iface);
214 TRACE("(%p)->(%d, %p)\n", This, num, info);
216 for(i = 0; i < num; i++)
218 switch(info[i].eInfoType)
220 case DCINFOTYPE_VERSION:
221 if(V_VT(&info[i].vData) != VT_UI4)
223 FIXME("VERSION with vt %x\n", V_VT(&info[i].vData));
224 hr = DB_S_ERRORSOCCURRED;
227 This->version = V_UI4(&info[i].vData);
231 FIXME("Unhandled info type %d (vt %x)\n", info[i].eInfoType, V_VT(&info[i].vData));
237 static const struct IDCInfoVtbl dcinfo_vtbl =
239 dcinfo_QueryInterface,
246 HRESULT create_oledb_convert(IUnknown *outer, void **obj)
250 TRACE("(%p, %p)\n", outer, obj);
254 if(outer) return CLASS_E_NOAGGREGATION;
256 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
257 if(!This) return E_OUTOFMEMORY;
259 This->lpVtbl = &convert_vtbl;
260 This->lpDCInfoVtbl = &dcinfo_vtbl;
262 This->version = 0x110;
264 *obj = &This->lpVtbl;