- New implementation of SendMessage, ReceiveMessage, ReplyMessage functions
[wine] / ole / bindctx.c
1 /***************************************************************************************
2  *                            BindCtx implementation
3  *
4  *  Copyright 1999  Noomen Hamza
5  ***************************************************************************************/
6
7 #include <ctype.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <assert.h>
11 #include "winerror.h"
12 #include "wine/obj_base.h"
13 #include "wine/obj_storage.h"
14 #include "wine/obj_moniker.h"
15 #include "debug.h"
16 #include "heap.h"
17
18 typedef struct BindCtxImpl{
19
20     ICOM_VTABLE(IBindCtx)*  lpvtbl;   
21                                      
22     ULONG ref;
23
24 } BindCtxImpl;
25
26
27 HRESULT WINAPI BindCtxImpl_QueryInterface(IBindCtx* iface,REFIID riid,void** ppvObject);
28 ULONG   WINAPI BindCtxImpl_AddRef(IBindCtx* iface);
29 ULONG   WINAPI BindCtxImpl_Release(IBindCtx* iface);
30 HRESULT WINAPI BindCtxImpl_RegisterObjectBound(IBindCtx* iface,IUnknown* punk);
31 HRESULT WINAPI BindCtxImpl_RevokeObjectBound(IBindCtx* iface, IUnknown* punk);
32 HRESULT WINAPI BindCtxImpl_ReleaseObjects(IBindCtx* iface);
33 HRESULT WINAPI BindCtxImpl_SetBindOptions(IBindCtx* iface,LPBIND_OPTS2 pbindopts);
34 HRESULT WINAPI BindCtxImpl_GetBindOptions(IBindCtx* iface,LPBIND_OPTS2 pbindopts);
35 HRESULT WINAPI BindCtxImpl_GetRunningObjectTable(IBindCtx* iface,IRunningObjectTable** pprot);
36 HRESULT WINAPI BindCtxImpl_RegisterObjectParam(IBindCtx* iface,LPOLESTR32 pszkey, IUnknown* punk);
37 HRESULT WINAPI BindCtxImpl_GetObjectParam(IBindCtx* iface,LPOLESTR32 pszkey, IUnknown* punk);
38 HRESULT WINAPI BindCtxImpl_EnumObjectParam(IBindCtx* iface,IEnumString** ppenum);
39 HRESULT WINAPI BindCtxImpl_RevokeObjectParam(IBindCtx* iface,LPOLESTR32 pszkey);
40
41 HRESULT WINAPI CreateBindCtx16(DWORD reserved, LPBC * ppbc);
42 HRESULT WINAPI CreateBindCtx32(DWORD reserved, LPBC * ppbc);
43
44 HRESULT WINAPI BindCtxImpl_Construct(BindCtxImpl* This);
45 HRESULT WINAPI BindCtxImpl_Destroy(BindCtxImpl* This);
46
47 // Virtual function table for the BindCtx class.
48 static ICOM_VTABLE(IBindCtx) VT_BindCtxImpl =
49     {
50     BindCtxImpl_QueryInterface,
51     BindCtxImpl_AddRef,
52     BindCtxImpl_Release,
53     BindCtxImpl_RegisterObjectBound,
54     BindCtxImpl_RevokeObjectBound,
55     BindCtxImpl_ReleaseObjects,
56     BindCtxImpl_SetBindOptions,
57     BindCtxImpl_GetBindOptions,
58     BindCtxImpl_GetRunningObjectTable,
59     BindCtxImpl_RegisterObjectParam,
60     BindCtxImpl_GetObjectParam,
61     BindCtxImpl_EnumObjectParam,
62     BindCtxImpl_RevokeObjectParam
63 };
64
65 /*******************************************************************************
66  *        BindCtx_QueryInterface
67  *******************************************************************************/
68 HRESULT WINAPI BindCtxImpl_QueryInterface(IBindCtx* iface,REFIID riid,void** ppvObject)
69 {
70   ICOM_THIS(BindCtxImpl,iface);
71   TRACE(ole,"(%p,%p,%p)\n",This,riid,ppvObject);
72   // Perform a sanity check on the parameters.
73   if ( (This==0) || (ppvObject==0) )    return E_INVALIDARG;
74   
75   // Initialize the return parameter.
76   *ppvObject = 0;
77
78   // Compare the riid with the interface IDs implemented by this object.
79   if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
80       *ppvObject = (IBindCtx*)This;
81   else
82       if (memcmp(&IID_IBindCtx, riid, sizeof(IID_IBindCtx)) == 0)
83           *ppvObject = (IBindCtx*)This;
84
85   // Check that we obtained an interface.
86   if ((*ppvObject)==0)        return E_NOINTERFACE;
87   
88    // Query Interface always increases the reference count by one when it is successful
89   BindCtxImpl_AddRef(iface);
90
91   return S_OK;
92 }
93
94 /******************************************************************************
95  *       BindCtx_ _AddRef
96  ******************************************************************************/
97 ULONG WINAPI BindCtxImpl_AddRef(IBindCtx* iface)
98 {
99     ICOM_THIS(BindCtxImpl,iface);
100     TRACE(ole,"(%p)\n",This);
101
102     return ++(This->ref);
103 }
104
105 /******************************************************************************
106  *        BindCtx_Release
107  ******************************************************************************/
108 ULONG WINAPI BindCtxImpl_Release(IBindCtx* iface)
109 {
110     ICOM_THIS(BindCtxImpl,iface);
111     TRACE(ole,"(%p)\n",This);
112
113     This->ref--;
114
115     if (This->ref==0){
116         BindCtxImpl_Destroy(This);
117         return 0;
118     }
119     return This->ref;;
120 }
121
122
123 /******************************************************************************
124  *         BindCtx_Construct
125  *******************************************************************************/
126 HRESULT WINAPI BindCtxImpl_Construct(BindCtxImpl* This)
127 {
128     FIXME(ole,"(%p),stub!\n",This);
129
130     memset(This, 0, sizeof(BindCtxImpl));
131
132     //Initialize the virtual fgunction table.
133     This->lpvtbl       = &VT_BindCtxImpl;
134
135     return E_NOTIMPL;
136 }
137
138 /******************************************************************************
139  *        BindCtx_Destroy
140  *******************************************************************************/
141 HRESULT WINAPI BindCtxImpl_Destroy(BindCtxImpl* This)
142 {
143     FIXME(ole,"(%p),stub!\n",This);
144
145     SEGPTR_FREE(This);
146
147     return S_OK;
148 }
149
150
151 /******************************************************************************
152  *        BindCtx_RegisterObjectBound
153  ******************************************************************************/
154 HRESULT WINAPI BindCtxImpl_RegisterObjectBound(IBindCtx* iface,IUnknown* punk)
155 {
156     ICOM_THIS(BindCtxImpl,iface);
157     FIXME(ole,"(%p,%p),stub!\n",This,punk);
158
159     return E_NOTIMPL;
160 }
161
162 /******************************************************************************
163  *        BindCtx_RevokeObjectBound
164  ******************************************************************************/
165 HRESULT WINAPI BindCtxImpl_RevokeObjectBound(IBindCtx* iface, IUnknown* punk)
166 {
167     ICOM_THIS(BindCtxImpl,iface);
168     FIXME(ole,"(%p,%p),stub!\n",This,punk);
169
170     return E_NOTIMPL;
171 }
172
173 /******************************************************************************
174  *        BindCtx_ReleaseObjects
175  ******************************************************************************/
176 HRESULT WINAPI BindCtxImpl_ReleaseObjects(IBindCtx* iface)
177 {
178     ICOM_THIS(BindCtxImpl,iface);
179     FIXME(ole,"(%p),stub!\n",This);
180
181     return E_NOTIMPL;
182 }
183
184 /******************************************************************************
185  *        BindCtx_SetBindOptions
186  ******************************************************************************/
187 HRESULT WINAPI BindCtxImpl_SetBindOptions(IBindCtx* iface,LPBIND_OPTS2 pbindopts)
188 {
189     ICOM_THIS(BindCtxImpl,iface);
190     FIXME(ole,"(%p,%p),stub!\n",This,pbindopts);
191
192     return E_NOTIMPL;
193 }
194
195 /******************************************************************************
196  *        BindCtx_GetBindOptions
197  ******************************************************************************/
198 HRESULT WINAPI BindCtxImpl_GetBindOptions(IBindCtx* iface,LPBIND_OPTS2 pbindopts)
199 {
200     ICOM_THIS(BindCtxImpl,iface);
201     FIXME(ole,"(%p,%p),stub!\n",This,pbindopts);
202
203     return E_NOTIMPL;
204 }
205
206 /******************************************************************************
207  *        BindCtx_GetRunningObjectTable
208  ******************************************************************************/
209 HRESULT WINAPI BindCtxImpl_GetRunningObjectTable(IBindCtx* iface,IRunningObjectTable** pprot)
210 {
211     ICOM_THIS(BindCtxImpl,iface);
212     FIXME(ole,"(%p,%p),stub!\n",This,pprot);
213
214     return E_NOTIMPL;
215 }
216
217 /******************************************************************************
218  *        BindCtx_RegisterObjectParam
219  ******************************************************************************/
220 HRESULT WINAPI BindCtxImpl_RegisterObjectParam(IBindCtx* iface,LPOLESTR32 pszkey, IUnknown* punk)
221 {
222     ICOM_THIS(BindCtxImpl,iface);
223     FIXME(ole,"(%p,%p,%p),stub!\n",This,pszkey,punk);
224
225     return E_NOTIMPL;
226 }
227
228 /******************************************************************************
229  *        BindCtx_GetObjectParam
230  ******************************************************************************/
231 HRESULT WINAPI BindCtxImpl_GetObjectParam(IBindCtx* iface,LPOLESTR32 pszkey, IUnknown* punk)
232 {
233     ICOM_THIS(BindCtxImpl,iface);
234     FIXME(ole,"(%p,%p,%p),stub!\n",This,pszkey,punk);
235
236     return E_NOTIMPL;
237 }
238
239 /******************************************************************************
240  *        BindCtx_EnumObjectParam
241  ******************************************************************************/
242 HRESULT WINAPI BindCtxImpl_EnumObjectParam(IBindCtx* iface,IEnumString** ppenum)
243 {
244     ICOM_THIS(BindCtxImpl,iface);
245     FIXME(ole,"(%p,%p),stub!\n",This,ppenum);
246
247     return E_NOTIMPL;
248 }
249
250 /******************************************************************************
251  *        BindCtx_RevokeObjectParam
252  ******************************************************************************/
253 HRESULT WINAPI BindCtxImpl_RevokeObjectParam(IBindCtx* iface,LPOLESTR32 pszkey)
254 {
255     ICOM_THIS(BindCtxImpl,iface);
256     FIXME(ole,"(%p,%p),stub!\n",This,pszkey);
257
258     return E_NOTIMPL;
259 }
260
261
262 /******************************************************************************
263  *        CreateBindCtx16
264  ******************************************************************************/
265 HRESULT WINAPI CreateBindCtx16(DWORD reserved, LPBC * ppbc)
266 {
267     FIXME(ole,"(%ld,%p),stub!\n",reserved,ppbc);
268
269     return E_NOTIMPL;
270 }
271
272 /******************************************************************************
273  *        CreateBindCtx32
274  ******************************************************************************/
275 HRESULT WINAPI CreateBindCtx32(DWORD reserved, LPBC * ppbc)
276 {
277     BindCtxImpl* newBindCtx = 0;
278     HRESULT        hr = S_OK;
279
280     TRACE(ole,"(%ld,%p)\n",reserved,ppbc);
281
282     newBindCtx = HeapAlloc(GetProcessHeap(), 0, sizeof(BindCtxImpl));
283
284     if (newBindCtx == 0)
285         return STG_E_INSUFFICIENTMEMORY;
286
287     hr = BindCtxImpl_Construct(newBindCtx);
288
289     if (FAILED(hr))
290         return hr;
291
292     hr = BindCtxImpl_QueryInterface((IBindCtx*)newBindCtx,&IID_IBindCtx,(void**)ppbc);
293
294     return hr;
295 }