comctl32/header: Implement HDF_FIXEDWIDTH format flag.
[wine] / dlls / oledb32 / convert.c
1 /* OLE DB Conversion library
2  *
3  * Copyright 2009 Huw Davies
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 #define NONAMELESSUNION
24 #define NONAMELESSSTRUCT
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "msdadc.h"
30
31 #include "oledb_private.h"
32
33 #include "wine/debug.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(oledb);
36
37 typedef struct
38 {
39     const struct IDataConvertVtbl *lpVtbl;
40
41     LONG ref;
42 } convert;
43
44 static inline convert *impl_from_IDataConvert(IDataConvert *iface)
45 {
46     return (convert *)((char*)iface - FIELD_OFFSET(convert, lpVtbl));
47 }
48
49 static HRESULT WINAPI convert_QueryInterface(IDataConvert* iface,
50                                              REFIID riid,
51                                              void **obj)
52 {
53     convert *This = impl_from_IDataConvert(iface);
54     TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), obj);
55
56     *obj = NULL;
57
58     if(IsEqualIID(riid, &IID_IUnknown) ||
59        IsEqualIID(riid, &IID_IDataConvert))
60     {
61         *obj = iface;
62     }
63     else
64     {
65         FIXME("interface %s not implemented\n", debugstr_guid(riid));
66         return E_NOINTERFACE;
67     }
68
69     IDataConvert_AddRef(iface);
70     return S_OK;
71 }
72
73
74 static ULONG WINAPI convert_AddRef(IDataConvert* iface)
75 {
76     convert *This = impl_from_IDataConvert(iface);
77     TRACE("(%p)\n", This);
78
79     return InterlockedIncrement(&This->ref);
80 }
81
82
83 static ULONG WINAPI convert_Release(IDataConvert* iface)
84 {
85     convert *This = impl_from_IDataConvert(iface);
86     LONG ref;
87
88     TRACE("(%p)\n", This);
89
90     ref = InterlockedDecrement(&This->ref);
91     if(ref == 0)
92     {
93         HeapFree(GetProcessHeap(), 0, This);
94     }
95
96     return ref;
97 }
98
99 static HRESULT WINAPI convert_DataConvert(IDataConvert* iface,
100                                           DBTYPE wSrcType, DBTYPE wDstType,
101                                           DBLENGTH cbSrcLength, DBLENGTH *pcbDstLength,
102                                           void *pSrc, void *pDst,
103                                           DBLENGTH cbDstMaxLength,
104                                           DBSTATUS dbsSrcStatus, DBSTATUS *pdbsDstStatus,
105                                           BYTE bPrecision, BYTE bScale,
106                                           DBDATACONVERT dwFlags)
107 {
108     convert *This = impl_from_IDataConvert(iface);
109     FIXME("(%p)->(%d, %d, %d, %p, %p, %p, %d, %d, %p, %d, %d, %x): stub\n", This,
110           wSrcType, wDstType, cbSrcLength, pcbDstLength, pSrc, pDst, cbDstMaxLength,
111           dbsSrcStatus, pdbsDstStatus, bPrecision, bScale, dwFlags);
112
113     return E_NOTIMPL;
114 }
115
116 static HRESULT WINAPI convert_CanConvert(IDataConvert* iface,
117                                          DBTYPE wSrcType, DBTYPE wDstType)
118 {
119     convert *This = impl_from_IDataConvert(iface);
120     FIXME("(%p)->(%d, %d): stub\n", This, wSrcType, wDstType);
121
122     return E_NOTIMPL;
123 }
124
125 static HRESULT WINAPI convert_GetConversionSize(IDataConvert* iface,
126                                                 DBTYPE wSrcType, DBTYPE wDstType,
127                                                 DBLENGTH *pcbSrcLength, DBLENGTH *pcbDstLength,
128                                                 void *pSrc)
129 {
130     convert *This = impl_from_IDataConvert(iface);
131     FIXME("(%p)->(%d, %d, %p, %p, %p): stub\n", This, wSrcType, wDstType, pcbSrcLength, pcbDstLength, pSrc);
132
133     return E_NOTIMPL;
134
135 }
136
137 static const struct IDataConvertVtbl convert_vtbl =
138 {
139     convert_QueryInterface,
140     convert_AddRef,
141     convert_Release,
142     convert_DataConvert,
143     convert_CanConvert,
144     convert_GetConversionSize
145 };
146
147 HRESULT create_oledb_convert(IUnknown *outer, void **obj)
148 {
149     convert *This;
150
151     TRACE("(%p, %p)\n", outer, obj);
152
153     *obj = NULL;
154
155     if(outer) return CLASS_E_NOAGGREGATION;
156
157     This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
158     if(!This) return E_OUTOFMEMORY;
159
160     This->lpVtbl = &convert_vtbl;
161     This->ref = 1;
162
163     *obj = &This->lpVtbl;
164
165     return S_OK;
166 }