Added a stub implementation for FileMoniker, ItemMoniker and BindCtx
[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(BindCtxImpl* This,REFIID riid,void** ppvObject);
28 ULONG   WINAPI BindCtxImpl_AddRef(BindCtxImpl* This);
29 ULONG   WINAPI BindCtxImpl_Release(BindCtxImpl* This);
30 HRESULT WINAPI BindCtxImpl_Construct(BindCtxImpl* This);
31 HRESULT WINAPI BindCtxImpl_destroy(BindCtxImpl* This);
32 HRESULT WINAPI BindCtxImpl_RegisterObjectBound(BindCtxImpl* This,IUnknown* punk);
33 HRESULT WINAPI BindCtxImpl_RevokeObjectBound(BindCtxImpl* This, IUnknown* punk);
34 HRESULT WINAPI BindCtxImpl_ReleaseObjects(BindCtxImpl* This);
35 HRESULT WINAPI BindCtxImpl_SetBindOptions(BindCtxImpl* This,LPBIND_OPTS2 pbindopts);
36 HRESULT WINAPI BindCtxImpl_GetBindOptions(BindCtxImpl* This,LPBIND_OPTS2 pbindopts);
37 HRESULT WINAPI BindCtxImpl_GetRunningObjectTable(BindCtxImpl* This,IRunningObjectTable** pprot);
38 HRESULT WINAPI BindCtxImpl_RegisterObjectParam(BindCtxImpl* This,LPOLESTR32 pszkey, IUnknown* punk);
39 HRESULT WINAPI BindCtxImpl_GetObjectParam(BindCtxImpl* This,LPOLESTR32 pszkey, IUnknown* punk);
40 HRESULT WINAPI BindCtxImpl_EnumObjectParam(BindCtxImpl* This,IEnumString** ppenum);
41 HRESULT WINAPI BindCtxImpl_RevokeObjectParam(BindCtxImpl* This,LPOLESTR32 pszkey);
42 HRESULT WINAPI CreateBindCtx16(DWORD reserved, LPBC * ppbc);
43 HRESULT WINAPI CreateBindCtx32(DWORD reserved, LPBC * ppbc);
44
45 #define VTABLE_FUNC(a) (void*)(a)
46 // Virtual function table for the BindCtx class.
47 static ICOM_VTABLE(IBindCtx) VT_BindCtxImpl =
48 {
49     {
50       VTABLE_FUNC(BindCtxImpl_QueryInterface),
51       VTABLE_FUNC(BindCtxImpl_AddRef),
52       VTABLE_FUNC(BindCtxImpl_Release)
53     },
54     VTABLE_FUNC(BindCtxImpl_RegisterObjectBound),
55     VTABLE_FUNC(BindCtxImpl_RevokeObjectBound),
56     VTABLE_FUNC(BindCtxImpl_ReleaseObjects),
57     VTABLE_FUNC(BindCtxImpl_SetBindOptions),
58     VTABLE_FUNC(BindCtxImpl_GetBindOptions),
59     VTABLE_FUNC(BindCtxImpl_GetRunningObjectTable),
60     VTABLE_FUNC(BindCtxImpl_RegisterObjectParam),
61     VTABLE_FUNC(BindCtxImpl_GetObjectParam),
62     VTABLE_FUNC(BindCtxImpl_EnumObjectParam),
63     VTABLE_FUNC(BindCtxImpl_RevokeObjectParam)
64 };
65
66 /*******************************************************************************
67  *        BindCtx_QueryInterface
68  *******************************************************************************/
69 HRESULT WINAPI BindCtxImpl_QueryInterface(BindCtxImpl* This,REFIID riid,void** ppvObject){
70
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(This);
90
91   return S_OK;
92 }
93
94 /******************************************************************************
95  *       BindCtx_ _AddRef
96  ******************************************************************************/
97 ULONG WINAPI BindCtxImpl_AddRef(BindCtxImpl* This){
98
99     TRACE(ole,"(%p)\n",This);
100
101     return ++(This->ref);
102 }
103
104 /******************************************************************************
105  *        BindCtx_Release
106  ******************************************************************************/
107 ULONG WINAPI BindCtxImpl_Release(BindCtxImpl* This){
108
109     TRACE(ole,"(%p)\n",This);
110
111     This->ref--;
112
113     if (This->ref==0){
114         BindCtxImpl_destroy(This);
115         return 0;
116     }
117     return This->ref;;
118 }
119
120
121 /******************************************************************************
122  *         BindCtx_Constructor
123  *******************************************************************************/
124 HRESULT WINAPI BindCtxImpl_Construct(BindCtxImpl* This){
125
126     FIXME(ole,"(%p),stub!\n",This);
127
128     memset(This, 0, sizeof(BindCtxImpl));
129
130     //Initialize the virtual fgunction table.
131     This->lpvtbl       = &VT_BindCtxImpl;
132
133     return E_NOTIMPL;
134 }
135
136 /******************************************************************************
137  *        BindCtx_destructor
138  *******************************************************************************/
139 HRESULT WINAPI BindCtxImpl_destroy(BindCtxImpl* This){
140
141     FIXME(ole,"(%p),stub!\n",This);
142
143     SEGPTR_FREE(This);
144
145     return S_OK;
146 }
147
148
149 /******************************************************************************
150  *        BindCtx_RegisterObjectBound
151  ******************************************************************************/
152 HRESULT WINAPI BindCtxImpl_RegisterObjectBound(BindCtxImpl* This,IUnknown* punk){
153
154     FIXME(ole,"(%p,%p),stub!\n",This,punk);
155
156     return E_NOTIMPL;
157 }
158
159 /******************************************************************************
160  *        BindCtx_RevokeObjectBound
161  ******************************************************************************/
162 HRESULT WINAPI BindCtxImpl_RevokeObjectBound(BindCtxImpl* This, IUnknown* punk){
163
164     FIXME(ole,"(%p,%p),stub!\n",This,punk);
165
166     return E_NOTIMPL;
167 }
168
169 /******************************************************************************
170  *        BindCtx_ReleaseObjects
171  ******************************************************************************/
172 HRESULT WINAPI BindCtxImpl_ReleaseObjects(BindCtxImpl* This){
173
174     FIXME(ole,"(%p),stub!\n",This);
175
176     return E_NOTIMPL;
177 }
178
179 /******************************************************************************
180  *        BindCtx_SetBindOptions
181  ******************************************************************************/
182 HRESULT WINAPI BindCtxImpl_SetBindOptions(BindCtxImpl* This,LPBIND_OPTS2 pbindopts){
183
184     FIXME(ole,"(%p,%p),stub!\n",This,pbindopts);
185
186     return E_NOTIMPL;
187 }
188
189 /******************************************************************************
190  *        BindCtx_GetBindOptions
191  ******************************************************************************/
192 HRESULT WINAPI BindCtxImpl_GetBindOptions(BindCtxImpl* This,LPBIND_OPTS2 pbindopts){
193
194     FIXME(ole,"(%p,%p),stub!\n",This,pbindopts);
195
196     return E_NOTIMPL;
197 }
198
199 /******************************************************************************
200  *        BindCtx_GetRunningObjectTable
201  ******************************************************************************/
202 HRESULT WINAPI BindCtxImpl_GetRunningObjectTable(BindCtxImpl* This,IRunningObjectTable** pprot){
203
204     FIXME(ole,"(%p,%p),stub!\n",This,pprot);
205
206     return E_NOTIMPL;
207 }
208
209 /******************************************************************************
210  *        BindCtx_RegisterObjectParam
211  ******************************************************************************/
212 HRESULT WINAPI BindCtxImpl_RegisterObjectParam(BindCtxImpl* This,LPOLESTR32 pszkey, IUnknown* punk){
213
214     FIXME(ole,"(%p,%p,%p),stub!\n",This,pszkey,punk);
215
216     return E_NOTIMPL;
217 }
218
219 /******************************************************************************
220  *        BindCtx_GetObjectParam
221  ******************************************************************************/
222 HRESULT WINAPI BindCtxImpl_GetObjectParam(BindCtxImpl* This,LPOLESTR32 pszkey, IUnknown* punk){
223
224     FIXME(ole,"(%p,%p,%p),stub!\n",This,pszkey,punk);
225
226     return E_NOTIMPL;
227 }
228
229 /******************************************************************************
230  *        BindCtx_EnumObjectParam
231  ******************************************************************************/
232 HRESULT WINAPI BindCtxImpl_EnumObjectParam(BindCtxImpl* This,IEnumString** ppenum){
233
234     FIXME(ole,"(%p,%p),stub!\n",This,ppenum);
235
236     return E_NOTIMPL;
237 }
238
239 /******************************************************************************
240  *        BindCtx_RevokeObjectParam
241  ******************************************************************************/
242 HRESULT WINAPI BindCtxImpl_RevokeObjectParam(BindCtxImpl* This,LPOLESTR32 pszkey){
243
244     FIXME(ole,"(%p,%p),stub!\n",This,pszkey);
245
246     return E_NOTIMPL;
247 }
248
249
250 /******************************************************************************
251  *        CreateBindCtx16
252  ******************************************************************************/
253 HRESULT WINAPI CreateBindCtx16(DWORD reserved, LPBC * ppbc){
254
255     FIXME(ole,"(%ld,%p),stub!\n",reserved,ppbc);
256
257     return E_NOTIMPL;
258 }
259
260 /******************************************************************************
261  *        CreateBindCtx32
262  ******************************************************************************/
263 HRESULT WINAPI CreateBindCtx32(DWORD reserved, LPBC * ppbc){
264
265     BindCtxImpl* newBindCtx = 0;
266     HRESULT        hr = S_OK;
267
268     TRACE(ole,"(%ld,%p)\n",reserved,ppbc);
269
270     newBindCtx = HeapAlloc(GetProcessHeap(), 0, sizeof(BindCtxImpl));
271
272     if (newBindCtx == 0)
273         return STG_E_INSUFFICIENTMEMORY;
274
275     hr = BindCtxImpl_Construct(newBindCtx);
276
277     if (FAILED(hr))
278         return hr;
279
280     hr = BindCtxImpl_QueryInterface(newBindCtx,&IID_IBindCtx,(void**)ppbc);
281
282     return hr;
283 }