mshtml: Pass DispatchEx pointer instead of outer IUnknown to DispatchEx's vtbl functions.
[wine] / dlls / msdaps / main.c
1 /*
2  * msdaps initialisation.
3  *
4  * Copyright 2010 Huw Davies
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 #include <stdarg.h>
21 #include <string.h>
22
23 #define COBJMACROS
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "winerror.h"
32 #include "objbase.h"
33 #include "oleauto.h"
34 #define DBINITCONSTANTS
35 #include "oledb.h"
36
37 #include "row_server.h"
38
39 #include "wine/debug.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(oledb);
42
43 extern BOOL WINAPI msdaps_DllMain(HINSTANCE, DWORD, LPVOID) DECLSPEC_HIDDEN;
44 extern HRESULT WINAPI msdaps_DllGetClassObject(REFCLSID, REFIID, LPVOID *) DECLSPEC_HIDDEN;
45 extern HRESULT WINAPI msdaps_DllCanUnloadNow(void) DECLSPEC_HIDDEN;
46 extern HRESULT WINAPI msdaps_DllRegisterServer(void) DECLSPEC_HIDDEN;
47 extern HRESULT WINAPI msdaps_DllUnregisterServer(void) DECLSPEC_HIDDEN;
48
49 /*****************************************************************************
50  *              DllMain
51  */
52 BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
53 {
54     return msdaps_DllMain(instance, reason, reserved);
55 }
56
57
58 /******************************************************************************
59  * ClassFactory
60  */
61 typedef struct
62 {
63     const IClassFactoryVtbl *lpVtbl;
64     HRESULT (*create_object)( IUnknown*, LPVOID* );
65 } cf;
66
67 static HRESULT WINAPI CF_QueryInterface(IClassFactory *iface, REFIID riid, void **obj)
68 {
69     cf *This = (cf *)iface;
70
71     TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), obj);
72
73     if( IsEqualCLSID( riid, &IID_IUnknown ) ||
74         IsEqualCLSID( riid, &IID_IClassFactory ) )
75     {
76         IClassFactory_AddRef( iface );
77         *obj = iface;
78         return S_OK;
79     }
80     return E_NOINTERFACE;
81 }
82
83 static ULONG WINAPI CF_AddRef(IClassFactory *iface)
84 {
85     return 2;
86 }
87
88 static ULONG WINAPI CF_Release(IClassFactory *iface)
89 {
90     return 1;
91 }
92
93 static HRESULT WINAPI CF_CreateInstance(IClassFactory *iface, IUnknown *pOuter, REFIID riid, void **obj)
94 {
95     cf *This = (cf *)iface;
96     IUnknown *unk = NULL;
97     HRESULT r;
98
99     TRACE("(%p, %p, %s, %p)\n", This, pOuter, debugstr_guid(riid), obj);
100
101     r = This->create_object( pOuter, (void **) &unk );
102     if (SUCCEEDED(r))
103     {
104         r = IUnknown_QueryInterface( unk, riid, obj );
105         IUnknown_Release( unk );
106     }
107     return r;
108 }
109
110 static HRESULT WINAPI CF_LockServer(IClassFactory *iface, BOOL dolock)
111 {
112     FIXME("(%p, %d): stub\n", iface, dolock);
113     return S_OK;
114 }
115
116 static const IClassFactoryVtbl CF_Vtbl =
117 {
118     CF_QueryInterface,
119     CF_AddRef,
120     CF_Release,
121     CF_CreateInstance,
122     CF_LockServer
123 };
124
125 static cf row_server_cf = { &CF_Vtbl, create_row_server };
126 static cf row_proxy_cf  = { &CF_Vtbl, create_row_marshal };
127 static cf rowset_server_cf = { &CF_Vtbl, create_rowset_server };
128 static cf rowset_proxy_cf  = { &CF_Vtbl, create_rowset_marshal };
129
130 /***********************************************************************
131  *              DllGetClassObject
132  */
133 HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID iid, LPVOID *obj)
134 {
135     TRACE("(%s, %s, %p)\n", debugstr_guid(clsid), debugstr_guid(iid), obj);
136
137     if (IsEqualCLSID(clsid, &CLSID_wine_row_server))
138     {
139         *obj = &row_server_cf;
140         return S_OK;
141     }
142
143     if (IsEqualCLSID(clsid, &CLSID_wine_row_proxy))
144     {
145         *obj = &row_proxy_cf;
146         return S_OK;
147     }
148
149     if (IsEqualCLSID(clsid, &CLSID_wine_rowset_server))
150     {
151         *obj = &rowset_server_cf;
152         return S_OK;
153     }
154
155     if (IsEqualCLSID(clsid, &CLSID_wine_rowset_proxy))
156     {
157         *obj = &rowset_proxy_cf;
158         return S_OK;
159     }
160
161     return msdaps_DllGetClassObject(clsid, iid, obj);
162 }
163
164 /***********************************************************************
165  *              DllCanUnloadNow
166  */
167 HRESULT WINAPI DllCanUnloadNow(void)
168 {
169     return msdaps_DllCanUnloadNow();
170 }
171
172 /***********************************************************************
173  *                DllRegisterServer
174  */
175 HRESULT WINAPI DllRegisterServer(void)
176 {
177     return msdaps_DllRegisterServer();
178 }
179
180 /***********************************************************************
181  *                DllUnregisterServer
182  */
183 HRESULT WINAPI DllUnregisterServer(void)
184 {
185     return msdaps_DllUnregisterServer();
186 }