Release 1.5.29.
[wine] / dlls / oledb32 / main.c
1 /* OLE DB Initialization
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 "rpcproxy.h"
30 #include "msdasc.h"
31
32 #include "initguid.h"
33 #include "msdaguid.h"
34
35 #include "oledb_private.h"
36
37 #include "wine/debug.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(oledb);
40
41 static HINSTANCE instance;
42
43 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID lpv)
44 {
45     switch(reason)
46     {
47     case DLL_PROCESS_ATTACH:
48         instance = hinst;
49         DisableThreadLibraryCalls(hinst);
50         break;
51     }
52     return TRUE;
53 }
54
55 /******************************************************************************
56  * ClassFactory
57  */
58 typedef struct
59 {
60     IClassFactory IClassFactory_iface;
61     HRESULT (*create_object)( IUnknown*, LPVOID* );
62 } cf;
63
64 static inline cf *impl_from_IClassFactory(IClassFactory *iface)
65 {
66     return CONTAINING_RECORD(iface, cf, IClassFactory_iface);
67 }
68
69 static HRESULT WINAPI CF_QueryInterface(IClassFactory *iface, REFIID riid, void **obj)
70 {
71     cf *This = impl_from_IClassFactory(iface);
72
73     TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), obj);
74
75     if( IsEqualCLSID( riid, &IID_IUnknown ) ||
76         IsEqualCLSID( riid, &IID_IClassFactory ) )
77     {
78         IClassFactory_AddRef( iface );
79         *obj = iface;
80         return S_OK;
81     }
82     return E_NOINTERFACE;
83 }
84
85 static ULONG WINAPI CF_AddRef(IClassFactory *iface)
86 {
87     return 2;
88 }
89
90 static ULONG WINAPI CF_Release(IClassFactory *iface)
91 {
92     return 1;
93 }
94
95 static HRESULT WINAPI CF_CreateInstance(IClassFactory *iface, IUnknown *pOuter, REFIID riid, void **obj)
96 {
97     cf *This = impl_from_IClassFactory(iface);
98     IUnknown *unk = NULL;
99     HRESULT r;
100
101     TRACE("(%p, %p, %s, %p)\n", This, pOuter, debugstr_guid(riid), obj);
102
103     r = This->create_object( pOuter, (void **) &unk );
104     if (SUCCEEDED(r))
105     {
106         r = IUnknown_QueryInterface( unk, riid, obj );
107         IUnknown_Release( unk );
108     }
109     return r;
110 }
111
112 static HRESULT WINAPI CF_LockServer(IClassFactory *iface, BOOL dolock)
113 {
114     FIXME("(%p, %d): stub\n", iface, dolock);
115     return S_OK;
116 }
117
118 static const IClassFactoryVtbl CF_Vtbl =
119 {
120     CF_QueryInterface,
121     CF_AddRef,
122     CF_Release,
123     CF_CreateInstance,
124     CF_LockServer
125 };
126
127 static cf oledb_convert_cf = { { &CF_Vtbl }, create_oledb_convert };
128 static cf oledb_datainit_cf = { { &CF_Vtbl }, create_data_init };
129
130 /******************************************************************
131  * DllGetClassObject
132  */
133 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **obj)
134 {
135     TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), obj);
136
137     if ( IsEqualCLSID (rclsid, &CLSID_OLEDB_CONVERSIONLIBRARY) )
138     {
139         *obj = &oledb_convert_cf;
140         return S_OK;
141     }
142     else if ( IsEqualCLSID (rclsid, &CLSID_MSDAINITIALIZE) )
143     {
144         *obj = &oledb_datainit_cf;
145         return S_OK;
146     }
147
148     return CLASS_E_CLASSNOTAVAILABLE;
149 }
150
151 /******************************************************************
152  *              DllCanUnloadNow
153  */
154 HRESULT WINAPI DllCanUnloadNow(void)
155 {
156     return S_FALSE;
157 }
158
159 /***********************************************************************
160  *              DllRegisterServer
161  */
162 HRESULT WINAPI DllRegisterServer(void)
163 {
164     return __wine_register_resources( instance );
165 }
166
167 /***********************************************************************
168  *              DllUnregisterServer
169  */
170 HRESULT WINAPI DllUnregisterServer(void)
171 {
172     return __wine_unregister_resources( instance );
173 }