msado15: Use the correct version when loading the typelib.
[wine.git] / dlls / msado15 / main.c
blob2d2f220c06f82a15679145d9daad359a336fa456
1 /*
2 * Copyright 2019 Hans Leidekker for CodeWeavers
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.
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.
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
19 #include <stdarg.h>
20 #include "windef.h"
21 #include "winbase.h"
22 #define COBJMACROS
23 #include "objbase.h"
24 #include "rpcproxy.h"
25 #include "msdasc.h"
26 #include "msado15_backcompat.h"
28 #include "wine/debug.h"
30 #include "msado15_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(msado15);
34 typedef HRESULT (*fnCreateInstance)( void **obj );
36 struct msadocf
38 IClassFactory IClassFactory_iface;
39 fnCreateInstance pfnCreateInstance;
42 static inline struct msadocf *impl_from_IClassFactory( IClassFactory *iface )
44 return CONTAINING_RECORD( iface, struct msadocf, IClassFactory_iface );
47 static HRESULT WINAPI msadocf_QueryInterface( IClassFactory *iface, REFIID riid, void **obj )
49 if (IsEqualGUID( riid, &IID_IUnknown ) || IsEqualGUID( riid, &IID_IClassFactory ))
51 IClassFactory_AddRef( iface );
52 *obj = iface;
53 return S_OK;
55 FIXME( "interface %s not implemented\n", debugstr_guid(riid) );
56 return E_NOINTERFACE;
59 static ULONG WINAPI msadocf_AddRef( IClassFactory *iface )
61 return 2;
64 static ULONG WINAPI msadocf_Release( IClassFactory *iface )
66 return 1;
69 static HRESULT WINAPI msadocf_CreateInstance( IClassFactory *iface, LPUNKNOWN outer, REFIID riid, void **obj )
71 struct msadocf *cf = impl_from_IClassFactory( iface );
72 IUnknown *unknown;
73 HRESULT hr;
75 TRACE( "%p, %s, %p\n", outer, debugstr_guid(riid), obj );
77 *obj = NULL;
78 if (outer)
79 return CLASS_E_NOAGGREGATION;
81 hr = cf->pfnCreateInstance( (void **)&unknown );
82 if (FAILED(hr))
83 return hr;
85 hr = IUnknown_QueryInterface( unknown, riid, obj );
86 IUnknown_Release( unknown );
87 return hr;
90 static HRESULT WINAPI msadocf_LockServer( IClassFactory *iface, BOOL dolock )
92 FIXME( "%p, %d\n", iface, dolock );
93 return S_OK;
96 static const struct IClassFactoryVtbl msadocf_vtbl =
98 msadocf_QueryInterface,
99 msadocf_AddRef,
100 msadocf_Release,
101 msadocf_CreateInstance,
102 msadocf_LockServer
105 static struct msadocf command_cf = { { &msadocf_vtbl }, Command_create };
106 static struct msadocf connection_cf = { { &msadocf_vtbl }, Connection_create };
107 static struct msadocf recordset_cf = { { &msadocf_vtbl }, Recordset_create };
108 static struct msadocf stream_cf = { { &msadocf_vtbl }, Stream_create };
110 /***********************************************************************
111 * DllGetClassObject
113 HRESULT WINAPI DllGetClassObject( REFCLSID clsid, REFIID iid, void **obj )
115 IClassFactory *cf = NULL;
117 TRACE( "%s, %s, %p\n", debugstr_guid(clsid), debugstr_guid(iid), obj );
119 if (IsEqualGUID( clsid, &CLSID_Connection ))
121 cf = &connection_cf.IClassFactory_iface;
123 else if (IsEqualGUID( clsid, &CLSID_Recordset ))
125 cf = &recordset_cf.IClassFactory_iface;
127 else if (IsEqualGUID( clsid, &CLSID_Stream ))
129 cf = &stream_cf.IClassFactory_iface;
131 else if (IsEqualGUID( clsid, &CLSID_Command ))
133 cf = &command_cf.IClassFactory_iface;
135 if (!cf) return CLASS_E_CLASSNOTAVAILABLE;
136 return IClassFactory_QueryInterface( cf, iid, obj );
139 static ITypeLib *typelib;
140 static ITypeInfo *typeinfos[LAST_tid];
142 static REFIID tid_ids[] = {
143 &IID_ADORecordsetConstruction,
144 &IID__Command,
145 &IID__Connection,
146 &IID_Field,
147 &IID_Fields,
148 &IID_Properties,
149 &IID_Property,
150 &IID__Recordset,
151 &IID__Stream,
154 static HRESULT load_typelib(void)
156 HRESULT hres;
157 ITypeLib *tl;
159 if(typelib)
160 return S_OK;
162 hres = LoadRegTypeLib(&LIBID_ADODB, 2, 8, LOCALE_SYSTEM_DEFAULT, &tl);
163 if(FAILED(hres)) {
164 ERR("LoadRegTypeLib failed: %08lx\n", hres);
165 return hres;
168 if(InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
169 ITypeLib_Release(tl);
170 return hres;
173 HRESULT get_typeinfo(tid_t tid, ITypeInfo **typeinfo)
175 HRESULT hres;
177 if (FAILED(hres = load_typelib()))
178 return hres;
180 if(!typeinfos[tid]) {
181 ITypeInfo *ti;
183 hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
184 if(FAILED(hres)) {
185 ERR("GetTypeInfoOfGuid(%s) failed: %08lx\n", debugstr_guid(tid_ids[tid]), hres);
186 return hres;
189 if(InterlockedCompareExchangePointer((void**)(typeinfos+tid), ti, NULL))
190 ITypeInfo_Release(ti);
193 *typeinfo = typeinfos[tid];
194 ITypeInfo_AddRef(*typeinfo);
195 return S_OK;