msvcrt: Added UTF16 support to read function.
[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     case DLL_PROCESS_DETACH:
53         break;
54     }
55     return TRUE;
56 }
57
58 /******************************************************************************
59  * ClassFactory
60  */
61 typedef struct
62 {
63     IClassFactory IClassFactory_iface;
64     HRESULT (*create_object)( IUnknown*, LPVOID* );
65 } cf;
66
67 static inline cf *impl_from_IClassFactory(IClassFactory *iface)
68 {
69     return CONTAINING_RECORD(iface, cf, IClassFactory_iface);
70 }
71
72 static HRESULT WINAPI CF_QueryInterface(IClassFactory *iface, REFIID riid, void **obj)
73 {
74     cf *This = impl_from_IClassFactory(iface);
75
76     TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), obj);
77
78     if( IsEqualCLSID( riid, &IID_IUnknown ) ||
79         IsEqualCLSID( riid, &IID_IClassFactory ) )
80     {
81         IClassFactory_AddRef( iface );
82         *obj = iface;
83         return S_OK;
84     }
85     return E_NOINTERFACE;
86 }
87
88 static ULONG WINAPI CF_AddRef(IClassFactory *iface)
89 {
90     return 2;
91 }
92
93 static ULONG WINAPI CF_Release(IClassFactory *iface)
94 {
95     return 1;
96 }
97
98 static HRESULT WINAPI CF_CreateInstance(IClassFactory *iface, IUnknown *pOuter, REFIID riid, void **obj)
99 {
100     cf *This = impl_from_IClassFactory(iface);
101     IUnknown *unk = NULL;
102     HRESULT r;
103
104     TRACE("(%p, %p, %s, %p)\n", This, pOuter, debugstr_guid(riid), obj);
105
106     r = This->create_object( pOuter, (void **) &unk );
107     if (SUCCEEDED(r))
108     {
109         r = IUnknown_QueryInterface( unk, riid, obj );
110         IUnknown_Release( unk );
111     }
112     return r;
113 }
114
115 static HRESULT WINAPI CF_LockServer(IClassFactory *iface, BOOL dolock)
116 {
117     FIXME("(%p, %d): stub\n", iface, dolock);
118     return S_OK;
119 }
120
121 static const IClassFactoryVtbl CF_Vtbl =
122 {
123     CF_QueryInterface,
124     CF_AddRef,
125     CF_Release,
126     CF_CreateInstance,
127     CF_LockServer
128 };
129
130 static cf oledb_convert_cf = { { &CF_Vtbl }, create_oledb_convert };
131 static cf oledb_datainit_cf = { { &CF_Vtbl }, create_data_init };
132
133 /******************************************************************
134  * DllGetClassObject
135  */
136 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **obj)
137 {
138     TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), obj);
139
140     if ( IsEqualCLSID (rclsid, &CLSID_OLEDB_CONVERSIONLIBRARY) )
141     {
142         *obj = &oledb_convert_cf;
143         return S_OK;
144     }
145     else if ( IsEqualCLSID (rclsid, &CLSID_MSDAINITIALIZE) )
146     {
147         *obj = &oledb_datainit_cf;
148         return S_OK;
149     }
150
151     return CLASS_E_CLASSNOTAVAILABLE;
152 }
153
154 /******************************************************************
155  *              DllCanUnloadNow
156  */
157 HRESULT WINAPI DllCanUnloadNow(void)
158 {
159     return S_FALSE;
160 }
161
162 /***********************************************************************
163  *              DllRegisterServer
164  */
165 HRESULT WINAPI DllRegisterServer(void)
166 {
167     return __wine_register_resources( instance );
168 }
169
170 /***********************************************************************
171  *              DllUnregisterServer
172  */
173 HRESULT WINAPI DllUnregisterServer(void)
174 {
175     return __wine_unregister_resources( instance );
176 }