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
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
);
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
);
55 FIXME( "interface %s not implemented\n", debugstr_guid(riid
) );
59 static ULONG WINAPI
msadocf_AddRef( IClassFactory
*iface
)
64 static ULONG WINAPI
msadocf_Release( IClassFactory
*iface
)
69 static HRESULT WINAPI
msadocf_CreateInstance( IClassFactory
*iface
, LPUNKNOWN outer
, REFIID riid
, void **obj
)
71 struct msadocf
*cf
= impl_from_IClassFactory( iface
);
75 TRACE( "%p, %s, %p\n", outer
, debugstr_guid(riid
), obj
);
79 return CLASS_E_NOAGGREGATION
;
81 hr
= cf
->pfnCreateInstance( (void **)&unknown
);
85 hr
= IUnknown_QueryInterface( unknown
, riid
, obj
);
86 IUnknown_Release( unknown
);
90 static HRESULT WINAPI
msadocf_LockServer( IClassFactory
*iface
, BOOL dolock
)
92 FIXME( "%p, %d\n", iface
, dolock
);
96 static const struct IClassFactoryVtbl msadocf_vtbl
=
98 msadocf_QueryInterface
,
101 msadocf_CreateInstance
,
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 /***********************************************************************
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
,
154 static HRESULT
load_typelib(void)
162 hres
= LoadRegTypeLib(&LIBID_ADODB
, 2, 8, LOCALE_SYSTEM_DEFAULT
, &tl
);
164 ERR("LoadRegTypeLib failed: %08lx\n", hres
);
168 if(InterlockedCompareExchangePointer((void**)&typelib
, tl
, NULL
))
169 ITypeLib_Release(tl
);
173 HRESULT
get_typeinfo(tid_t tid
, ITypeInfo
**typeinfo
)
177 if (FAILED(hres
= load_typelib()))
180 if(!typeinfos
[tid
]) {
183 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, tid_ids
[tid
], &ti
);
185 ERR("GetTypeInfoOfGuid(%s) failed: %08lx\n", debugstr_guid(tid_ids
[tid
]), hres
);
189 if(InterlockedCompareExchangePointer((void**)(typeinfos
+tid
), ti
, NULL
))
190 ITypeInfo_Release(ti
);
193 *typeinfo
= typeinfos
[tid
];
194 ITypeInfo_AddRef(*typeinfo
);