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