hlink: Add link stack to browser context.
[wine] / dlls / oledb32 / datainit.c
1 /*
2  * Copyright (C) 2012 Alistair Leslie-Hughes
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18 #include <stdarg.h>
19
20 #define COBJMACROS
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winnls.h"
27 #include "ole2.h"
28 #include "msdasc.h"
29 #include "oledberr.h"
30 #include "initguid.h"
31 #include "oledb_private.h"
32
33 #include "wine/debug.h"
34 #include "wine/unicode.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(oledb);
37
38 DEFINE_GUID(DBPROPSET_DBINIT, 0xc8b522bc, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
39
40 typedef struct datainit
41 {
42     IDataInitialize IDataInitialize_iface;
43
44     LONG ref;
45 } datainit;
46
47 static inline datainit *impl_from_IDataInitialize(IDataInitialize *iface)
48 {
49     return CONTAINING_RECORD(iface, datainit, IDataInitialize_iface);
50 }
51
52 typedef struct
53 {
54     IDBInitialize IDBInitialize_iface;
55     IDBProperties IDBProperties_iface;
56
57     LONG ref;
58 } dbinit;
59
60 static inline dbinit *impl_from_IDBInitialize(IDBInitialize *iface)
61 {
62     return CONTAINING_RECORD(iface, dbinit, IDBInitialize_iface);
63 }
64
65 static inline dbinit *impl_from_IDBProperties(IDBProperties *iface)
66 {
67     return CONTAINING_RECORD(iface, dbinit, IDBProperties_iface);
68 }
69
70 static HRESULT WINAPI dbprops_QueryInterface(IDBProperties *iface, REFIID riid, void **ppvObject)
71 {
72     dbinit *This = impl_from_IDBProperties(iface);
73
74     return IDBInitialize_QueryInterface(&This->IDBInitialize_iface, riid, ppvObject);
75 }
76
77 static ULONG WINAPI dbprops_AddRef(IDBProperties *iface)
78 {
79     dbinit *This = impl_from_IDBProperties(iface);
80
81     return IDBInitialize_AddRef(&This->IDBInitialize_iface);
82 }
83
84 static ULONG WINAPI dbprops_Release(IDBProperties *iface)
85 {
86     dbinit *This = impl_from_IDBProperties(iface);
87
88     return IDBInitialize_Release(&This->IDBInitialize_iface);
89 }
90
91 static HRESULT WINAPI dbprops_GetProperties(IDBProperties *iface, ULONG cPropertyIDSets,
92             const DBPROPIDSET rgPropertyIDSets[], ULONG *pcPropertySets, DBPROPSET **prgPropertySets)
93 {
94     dbinit *This = impl_from_IDBProperties(iface);
95
96     FIXME("(%p)->(%d %p %p %p)\n", This, cPropertyIDSets, rgPropertyIDSets, pcPropertySets, prgPropertySets);
97
98     return E_NOTIMPL;
99 }
100
101 static HRESULT WINAPI dbprops_GetPropertyInfo(IDBProperties *iface, ULONG cPropertyIDSets,
102             const DBPROPIDSET rgPropertyIDSets[], ULONG *pcPropertyInfoSets,
103             DBPROPINFOSET **prgPropertyInfoSets, OLECHAR **ppDescBuffer)
104 {
105     dbinit *This = impl_from_IDBProperties(iface);
106
107     FIXME("(%p)->(%d %p %p %p %p)\n", This, cPropertyIDSets, rgPropertyIDSets, pcPropertyInfoSets,
108                 prgPropertyInfoSets, ppDescBuffer);
109
110     return E_NOTIMPL;
111 }
112
113 static HRESULT WINAPI dbprops_SetProperties(IDBProperties *iface, ULONG cPropertySets,
114             DBPROPSET rgPropertySets[])
115 {
116     dbinit *This = impl_from_IDBProperties(iface);
117
118     FIXME("(%p)->(%d %p)\n", This, cPropertySets, rgPropertySets);
119
120     return E_NOTIMPL;
121 }
122
123 static const struct IDBPropertiesVtbl dbprops_vtbl =
124 {
125     dbprops_QueryInterface,
126     dbprops_AddRef,
127     dbprops_Release,
128     dbprops_GetProperties,
129     dbprops_GetPropertyInfo,
130     dbprops_SetProperties
131 };
132
133 static HRESULT WINAPI dbinit_QueryInterface(IDBInitialize *iface, REFIID riid, void **obj)
134 {
135     dbinit *This = impl_from_IDBInitialize(iface);
136     TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), obj);
137
138     *obj = NULL;
139
140     if(IsEqualIID(riid, &IID_IUnknown) ||
141        IsEqualIID(riid, &IID_IDBInitialize))
142     {
143         *obj = iface;
144     }
145     else if(IsEqualIID(riid, &IID_IDBProperties))
146     {
147         *obj = &This->IDBProperties_iface;
148     }
149     else
150     {
151         FIXME("interface %s not implemented\n", debugstr_guid(riid));
152         return E_NOINTERFACE;
153     }
154
155     IDBInitialize_AddRef(iface);
156     return S_OK;
157 }
158
159 static ULONG WINAPI dbinit_AddRef(IDBInitialize *iface)
160 {
161     dbinit *This = impl_from_IDBInitialize(iface);
162     TRACE("(%p)\n", This);
163
164     return InterlockedIncrement(&This->ref);
165 }
166
167 static ULONG WINAPI dbinit_Release(IDBInitialize *iface)
168 {
169     dbinit *This = impl_from_IDBInitialize(iface);
170     LONG ref;
171
172     TRACE("(%p)\n", This);
173
174     ref = InterlockedDecrement(&This->ref);
175     if(ref == 0)
176     {
177         HeapFree(GetProcessHeap(), 0, This);
178     }
179
180     return ref;
181 }
182
183 static HRESULT WINAPI dbinit_Initialize(IDBInitialize *iface)
184 {
185     dbinit *This = impl_from_IDBInitialize(iface);
186
187     FIXME("(%p) stub\n", This);
188
189     return S_OK;
190 }
191
192 static HRESULT WINAPI dbinit_Uninitialize(IDBInitialize *iface)
193 {
194     dbinit *This = impl_from_IDBInitialize(iface);
195
196     FIXME("(%p) stub\n", This);
197
198     return S_OK;
199 }
200
201 static const IDBInitializeVtbl dbinit_vtbl =
202 {
203     dbinit_QueryInterface,
204     dbinit_AddRef,
205     dbinit_Release,
206     dbinit_Initialize,
207     dbinit_Uninitialize
208 };
209
210 static HRESULT create_db_init(void **obj)
211 {
212     dbinit *This;
213
214     TRACE("()\n");
215
216     *obj = NULL;
217
218     This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
219     if(!This) return E_OUTOFMEMORY;
220
221     This->IDBInitialize_iface.lpVtbl = &dbinit_vtbl;
222     This->IDBProperties_iface.lpVtbl = &dbprops_vtbl;
223     This->ref = 1;
224
225     *obj = &This->IDBInitialize_iface;
226
227     return S_OK;
228 }
229
230 static HRESULT WINAPI datainit_QueryInterface(IDataInitialize *iface, REFIID riid, void **obj)
231 {
232     datainit *This = impl_from_IDataInitialize(iface);
233     TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), obj);
234
235     *obj = NULL;
236
237     if(IsEqualIID(riid, &IID_IUnknown) ||
238        IsEqualIID(riid, &IID_IDataInitialize))
239     {
240         *obj = &This->IDataInitialize_iface;
241     }
242     else
243     {
244         FIXME("interface %s not implemented\n", debugstr_guid(riid));
245         return E_NOINTERFACE;
246     }
247
248     IDataInitialize_AddRef(iface);
249     return S_OK;
250 }
251
252 static ULONG WINAPI datainit_AddRef(IDataInitialize *iface)
253 {
254     datainit *This = impl_from_IDataInitialize(iface);
255     TRACE("(%p)\n", This);
256
257     return InterlockedIncrement(&This->ref);
258 }
259
260 static ULONG WINAPI datainit_Release(IDataInitialize *iface)
261 {
262     datainit *This = impl_from_IDataInitialize(iface);
263     LONG ref;
264
265     TRACE("(%p)\n", This);
266
267     ref = InterlockedDecrement(&This->ref);
268     if(ref == 0)
269     {
270         HeapFree(GetProcessHeap(), 0, This);
271     }
272
273     return ref;
274 }
275
276 static void free_dbpropset(ULONG count, DBPROPSET *propset)
277 {
278     ULONG i;
279
280     for (i = 0; i < count; i++)
281     {
282         ULONG p;
283
284         for (p = 0; p < propset[i].cProperties; p++)
285             VariantClear(&propset[i].rgProperties[p].vValue);
286
287         CoTaskMemFree(propset[i].rgProperties);
288     }
289     CoTaskMemFree(propset);
290 }
291
292 struct dbproperty {
293     const WCHAR *name;
294     DBPROPID id;
295     DBPROPOPTIONS options;
296     VARTYPE type;
297 };
298
299 static const WCHAR datasourceW[] = {'D','a','t','a',' ','S','o','u','r','c','e',0};
300 static const WCHAR persistsiW[] = {'P','e','r','s','i','s','t',' ','S','e','c','u','r','i','t','y',' ','I','n','f','o',0};
301
302 static const struct dbproperty dbproperties[] = {
303     { datasourceW, DBPROP_INIT_DATASOURCE, DBPROPOPTIONS_REQUIRED, VT_BSTR },
304     { persistsiW, DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, DBPROPOPTIONS_OPTIONAL, VT_BOOL }
305 };
306
307 static HRESULT set_dbpropset(BSTR name, BSTR value, DBPROPSET **propset)
308 {
309     VARIANT src, dest;
310     int min, max, n;
311     HRESULT hr;
312
313     min = 0;
314     max = sizeof(dbproperties)/sizeof(struct dbproperty) - 1;
315
316     while (min <= max)
317     {
318         int r;
319
320         n = (min+max)/2;
321
322         r = strcmpW(dbproperties[n].name, name);
323         if (!r)
324             break;
325
326         if (r < 0)
327             min = n+1;
328         else
329             max = n-1;
330     }
331
332     if (min > max)
333     {
334         *propset = NULL;
335         FIXME("unsupported property %s\n", debugstr_w(name));
336         return E_FAIL;
337     }
338
339     VariantInit(&dest);
340
341     V_VT(&src) = VT_BSTR;
342     V_BSTR(&src) = value;
343
344     hr = VariantChangeType(&dest, &src, 0, dbproperties[n].type);
345     if (FAILED(hr))
346     {
347         ERR("failed to init property %s value as type %d\n", debugstr_w(name), dbproperties[n].type);
348         return hr;
349     }
350
351     *propset = CoTaskMemAlloc(sizeof(DBPROPSET));
352     if (!*propset)
353     {
354         VariantClear(&dest);
355         return E_OUTOFMEMORY;
356     }
357
358     (*propset)->rgProperties = CoTaskMemAlloc(sizeof(DBPROP));
359     if (!(*propset)->rgProperties)
360     {
361         VariantClear(&dest);
362         CoTaskMemFree(*propset);
363         return E_OUTOFMEMORY;
364     }
365
366     (*propset)->cProperties = 1;
367     (*propset)->guidPropertySet = DBPROPSET_DBINIT;
368     (*propset)->rgProperties[0].dwPropertyID = dbproperties[n].id;
369     (*propset)->rgProperties[0].dwOptions = dbproperties[n].options;
370     (*propset)->rgProperties[0].dwStatus = 0;
371     memset(&(*propset)->rgProperties[0].colid, 0, sizeof(DBID));
372     (*propset)->rgProperties[0].vValue = dest;
373
374     return S_OK;
375 }
376
377 /*** IDataInitialize methods ***/
378 static HRESULT WINAPI datainit_GetDataSource(IDataInitialize *iface, IUnknown *outer, DWORD clsctx,
379                                 LPWSTR initstring, REFIID riid, IUnknown **datasource)
380 {
381     static const WCHAR providerW[] = {'P','r','o','v','i','d','e','r','=',0};
382     static const WCHAR msdasqlW[] = {'M','S','D','A','S','Q','L',0};
383     datainit *This = impl_from_IDataInitialize(iface);
384     IDBProperties *dbprops;
385     DBPROPSET *propset;
386     WCHAR *prov = NULL;
387     CLSID provclsid;
388     HRESULT hr;
389
390     TRACE("(%p)->(%p 0x%x %s %s %p)\n", This, outer, clsctx, debugstr_w(initstring), debugstr_guid(riid), datasource);
391
392     /* first get provider name */
393     provclsid = IID_NULL;
394     if (initstring && (prov = strstrW(initstring, providerW)))
395     {
396         WCHAR *start, *progid;
397         int len;
398
399         prov += sizeof(providerW)/sizeof(WCHAR)-1;
400         start = prov;
401         while (*prov && *prov != ';')
402             ++prov;
403         TRACE("got provider %s\n", debugstr_wn(start, prov-start));
404
405         len = prov - start;
406         progid = CoTaskMemAlloc((len+1)*sizeof(WCHAR));
407         if (!progid) return E_OUTOFMEMORY;
408
409         memcpy(progid, start, len*sizeof(WCHAR));
410         progid[len] = 0;
411
412         hr = CLSIDFromProgID(progid, &provclsid);
413         CoTaskMemFree(progid);
414         if (FAILED(hr))
415         {
416             ERR("provider %s not registered\n", debugstr_wn(start, prov-start));
417             return hr;
418         }
419     }
420     else
421     {
422         hr = CLSIDFromProgID(msdasqlW, &provclsid);
423         if (FAILED(hr))
424             ERR("ODBC provider for OLE DB not registered\n");
425     }
426
427     /* check for provider mismatch if it was specified in init string */
428     if (*datasource && prov)
429     {
430         DBPROPIDSET propidset;
431         enum DBPROPENUM prop;
432         CLSID initprov;
433         ULONG count;
434
435         hr = IUnknown_QueryInterface(*datasource, &IID_IDBProperties, (void**)&dbprops);
436         if (FAILED(hr))
437         {
438             WARN("provider doesn't support IDBProperties\n");
439             return hr;
440         }
441
442         prop = DBPROP_INIT_DATASOURCE;
443         propidset.rgPropertyIDs = &prop;
444         propidset.cPropertyIDs = 1;
445         propidset.guidPropertySet = DBPROPSET_DBINIT;
446         count = 0;
447         propset = NULL;
448         hr = IDBProperties_GetProperties(dbprops, 1, &propidset, &count, &propset);
449         IDBProperties_Release(dbprops);
450         if (FAILED(hr))
451         {
452             WARN("GetProperties failed for datasource, 0x%08x\n", hr);
453             return hr;
454         }
455
456         TRACE("initial data source provider %s\n", debugstr_w(V_BSTR(&propset->rgProperties[0].vValue)));
457         initprov = IID_NULL;
458         CLSIDFromProgID(V_BSTR(&propset->rgProperties[0].vValue), &initprov);
459         free_dbpropset(count, propset);
460
461         if (!IsEqualIID(&provclsid, &initprov)) return DB_E_MISMATCHEDPROVIDER;
462     }
463
464     if (!*datasource)
465     {
466         if (!IsEqualIID(&provclsid, &IID_NULL))
467             hr = CoCreateInstance(&provclsid, outer, clsctx, riid, (void**)datasource);
468
469         if (FAILED(hr) && IsEqualIID(riid, &IID_IDBInitialize))
470             hr = create_db_init((void**)datasource);
471     }
472
473     /* now set properties */
474     if (initstring)
475     {
476         WCHAR *eq, *start;
477
478         hr = IUnknown_QueryInterface(*datasource, &IID_IDBProperties, (void**)&dbprops);
479         if (FAILED(hr))
480         {
481             WARN("provider doesn't support IDBProperties\n");
482             return hr;
483         }
484
485         start = initstring;
486         while (start && (eq = strchrW(start, '=')))
487         {
488             static const WCHAR providerW[] = {'P','r','o','v','i','d','e','r',0};
489             WCHAR *scol = strchrW(eq+1, ';');
490             BSTR value, name;
491
492             name = SysAllocStringLen(start, eq - start);
493             /* skip equal sign to get value */
494             eq++;
495             value = SysAllocStringLen(eq, scol ? scol - eq : -1);
496
497             /* skip semicolon if present */
498             if (scol) scol++;
499             start = scol;
500
501             if (!strcmpW(name, providerW))
502             {
503                 SysFreeString(name);
504                 SysFreeString(value);
505                 continue;
506             }
507
508             TRACE("property (name=%s, value=%s)\n", debugstr_w(name), debugstr_w(value));
509
510             hr = set_dbpropset(name, value, &propset);
511             SysFreeString(name);
512             SysFreeString(value);
513             if (FAILED(hr)) return hr;
514
515             hr = IDBProperties_SetProperties(dbprops, 1, propset);
516             free_dbpropset(1, propset);
517             TRACE("provider ret 0x%08x\n", hr);
518         }
519
520         IDBProperties_Release(dbprops);
521     }
522
523     return hr;
524 }
525
526 /* returns character length of string representation */
527 static int get_propvalue_length(DBPROP *prop)
528 {
529     VARIANT str;
530     HRESULT hr;
531
532     if (V_VT(&prop->vValue) == VT_BSTR) return SysStringLen(V_BSTR(&prop->vValue));
533
534     VariantInit(&str);
535     hr = VariantChangeType(&str, &prop->vValue, 0, VT_BSTR);
536     if (hr == S_OK)
537     {
538         int len = SysStringLen(V_BSTR(&str));
539         VariantClear(&str);
540         return len;
541     }
542
543     return 0;
544 }
545
546 static void write_propvalue_str(WCHAR *str, DBPROP *prop)
547 {
548     VARIANT *v = &prop->vValue;
549     VARIANT vstr;
550     HRESULT hr;
551
552     if (V_VT(v) == VT_BSTR)
553     {
554         strcatW(str, V_BSTR(v));
555         return;
556     }
557
558     VariantInit(&vstr);
559     hr = VariantChangeType(&vstr, v, VARIANT_ALPHABOOL, VT_BSTR);
560     if (hr == S_OK)
561     {
562         strcatW(str, V_BSTR(&vstr));
563         VariantClear(&vstr);
564     }
565 }
566
567 static WCHAR *get_propinfo_descr(DBPROP *prop, DBPROPINFOSET *propinfoset)
568 {
569     ULONG i;
570
571     for (i = 0; i < propinfoset->cPropertyInfos; i++)
572         if (propinfoset->rgPropertyInfos[i].dwPropertyID == prop->dwPropertyID)
573             return propinfoset->rgPropertyInfos[i].pwszDescription;
574
575     return NULL;
576 }
577
578 static void free_dbpropinfoset(ULONG count, DBPROPINFOSET *propinfoset)
579 {
580     ULONG i;
581
582     for (i = 0; i < count; i++)
583     {
584         ULONG p;
585
586         for (p = 0; p < propinfoset[i].cPropertyInfos; p++)
587             VariantClear(&propinfoset[i].rgPropertyInfos[p].vValues);
588
589         CoTaskMemFree(propinfoset[i].rgPropertyInfos);
590     }
591     CoTaskMemFree(propinfoset);
592 }
593
594 static HRESULT WINAPI datainit_GetInitializationString(IDataInitialize *iface, IUnknown *datasource,
595                                 boolean include_pass, LPWSTR *init_string)
596 {
597     static const WCHAR provW[] = {'P','r','o','v','i','d','e','r','=',0};
598     static const WCHAR colW[] = {';',0};
599     datainit *This = impl_from_IDataInitialize(iface);
600     DBPROPINFOSET *propinfoset;
601     IDBProperties *props;
602     DBPROPIDSET propidset;
603     ULONG count, infocount;
604     WCHAR *progid, *desc;
605     DBPROPSET *propset;
606     IPersist *persist;
607     HRESULT hr;
608     CLSID clsid;
609     ULONG i, len;
610
611     TRACE("(%p)->(%p %d %p)\n", This, datasource, include_pass, init_string);
612
613     /* IPersist support is mandatory for data sources */
614     hr = IUnknown_QueryInterface(datasource, &IID_IPersist, (void**)&persist);
615     if (FAILED(hr)) return hr;
616
617     memset(&clsid, 0, sizeof(clsid));
618     hr = IPersist_GetClassID(persist, &clsid);
619     IPersist_Release(persist);
620     if (FAILED(hr)) return hr;
621
622     progid = NULL;
623     ProgIDFromCLSID(&clsid, &progid);
624     TRACE("clsid=%s, progid=%s\n", debugstr_guid(&clsid), debugstr_w(progid));
625
626     /* now get initialization properties */
627     hr = IUnknown_QueryInterface(datasource, &IID_IDBProperties, (void**)&props);
628     if (FAILED(hr))
629     {
630         WARN("IDBProperties not supported\n");
631         CoTaskMemFree(progid);
632         return hr;
633     }
634
635     propidset.rgPropertyIDs = NULL;
636     propidset.cPropertyIDs = 0;
637     propidset.guidPropertySet = DBPROPSET_DBINIT;
638     propset = NULL;
639     count = 0;
640     hr = IDBProperties_GetProperties(props, 1, &propidset, &count, &propset);
641     if (FAILED(hr))
642     {
643         WARN("failed to get data source properties, 0x%08x\n", hr);
644         CoTaskMemFree(progid);
645         return hr;
646     }
647
648     infocount = 0;
649     IDBProperties_GetPropertyInfo(props, 1, &propidset, &infocount, &propinfoset, &desc);
650     IDBProperties_Release(props);
651
652     /* check if we need to skip password */
653     len = strlenW(progid) + strlenW(provW) + 1; /* including ';' */
654     for (i = 0; i < count; i++)
655     {
656         WCHAR *descr = get_propinfo_descr(&propset->rgProperties[i], propinfoset);
657         if (descr)
658         {
659             /* include '=' and ';' */
660             len += strlenW(descr) + 2;
661             len += get_propvalue_length(&propset->rgProperties[i]);
662         }
663
664         if ((propset->rgProperties[i].dwPropertyID == DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO) &&
665             (V_BOOL(&propset->rgProperties[i].vValue) == VARIANT_FALSE))
666            include_pass = FALSE;
667     }
668
669     len *= sizeof(WCHAR);
670     *init_string = CoTaskMemAlloc(len);
671     *init_string[0] = 0;
672
673     /* provider name */
674     strcatW(*init_string, provW);
675     strcatW(*init_string, progid);
676     strcatW(*init_string, colW);
677     CoTaskMemFree(progid);
678
679     for (i = 0; i < count; i++)
680     {
681         WCHAR *descr;
682
683         if (!include_pass && propset->rgProperties[i].dwPropertyID == DBPROP_AUTH_PASSWORD) continue;
684
685         descr = get_propinfo_descr(&propset->rgProperties[i], propinfoset);
686         if (descr)
687         {
688             static const WCHAR eqW[] = {'=',0};
689             strcatW(*init_string, descr);
690             strcatW(*init_string, eqW);
691             write_propvalue_str(*init_string, &propset->rgProperties[i]);
692             strcatW(*init_string, colW);
693         }
694     }
695
696     free_dbpropset(count, propset);
697     free_dbpropinfoset(infocount, propinfoset);
698     CoTaskMemFree(desc);
699
700     if (!include_pass)
701         TRACE("%s\n", debugstr_w(*init_string));
702     return S_OK;
703 }
704
705 static HRESULT WINAPI datainit_CreateDBInstance(IDataInitialize *iface, REFCLSID provider,
706                                 IUnknown *outer, DWORD clsctx, LPWSTR reserved, REFIID riid,
707                                 IUnknown **datasource)
708 {
709     datainit *This = impl_from_IDataInitialize(iface);
710
711     TRACE("(%p)->(%s %p 0x%08x %s %s %p)\n", This, debugstr_guid(provider), outer, clsctx, debugstr_w(reserved),
712         debugstr_guid(riid), datasource);
713
714     return CoCreateInstance(provider, outer, clsctx, riid, (void**)datasource);
715 }
716
717 static HRESULT WINAPI datainit_RemoteCreateDBInstanceEx(IDataInitialize *iface, REFCLSID clsidProvider,
718                                 IUnknown *pUnkOuter, DWORD dwClsCtx, LPWSTR pwszReserved, COSERVERINFO *pServerInfo,
719                                 DWORD cmq, GUID **rgpIID, IUnknown **rgpItf, HRESULT *rghr)
720 {
721     datainit *This = impl_from_IDataInitialize(iface);
722
723     FIXME("(%p)->()\n", This);
724
725     return E_NOTIMPL;
726 }
727
728 static HRESULT WINAPI datainit_LoadStringFromStorage(IDataInitialize *iface, LPWSTR pwszFileName,
729                                 LPWSTR *ppwszInitializationString)
730 {
731     datainit *This = impl_from_IDataInitialize(iface);
732
733     FIXME("(%p)->(%s %p)\n", This, debugstr_w(pwszFileName), ppwszInitializationString);
734
735     return E_NOTIMPL;
736 }
737
738 static HRESULT WINAPI datainit_WriteStringToStorage(IDataInitialize *iface, LPWSTR pwszFileName,
739                                 LPWSTR pwszInitializationString, DWORD dwCreationDisposition)
740 {
741     datainit *This = impl_from_IDataInitialize(iface);
742
743     FIXME("(%p)->(%s %s %d)\n", This, debugstr_w(pwszFileName), debugstr_w(pwszInitializationString), dwCreationDisposition);
744
745     return E_NOTIMPL;
746 }
747
748
749 static const struct IDataInitializeVtbl datainit_vtbl =
750 {
751     datainit_QueryInterface,
752     datainit_AddRef,
753     datainit_Release,
754     datainit_GetDataSource,
755     datainit_GetInitializationString,
756     datainit_CreateDBInstance,
757     datainit_RemoteCreateDBInstanceEx,
758     datainit_LoadStringFromStorage,
759     datainit_WriteStringToStorage
760 };
761
762 HRESULT create_data_init(IUnknown *outer, void **obj)
763 {
764     datainit *This;
765
766     TRACE("(%p)\n", obj);
767
768     if(outer) return CLASS_E_NOAGGREGATION;
769
770     *obj = NULL;
771
772     This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
773     if(!This) return E_OUTOFMEMORY;
774
775     This->IDataInitialize_iface.lpVtbl = &datainit_vtbl;
776     This->ref = 1;
777
778     *obj = &This->IDataInitialize_iface;
779
780     return S_OK;
781 }