Release 20000326.
[wine/gsoc-2012-control.git] / dlls / ole32 / oleobj.c
blob870a450cb37d92a38068fcaac93266a4a4f6e7bb
1 /*
2 * OLE2 COM objects
4 * Copyright 1998 Eric Kohl
5 * Copyright 1999 Francis Beaudet
6 */
9 #include <string.h>
10 #include "winbase.h"
11 #include "winerror.h"
12 #include "oleidl.h"
13 #include "debugtools.h"
15 DEFAULT_DEBUG_CHANNEL(ole)
18 /**************************************************************************
19 * OleAdviseHolderImpl Implementation
21 typedef struct OleAdviseHolderImpl
23 ICOM_VFIELD(IOleAdviseHolder);
25 DWORD ref;
27 DWORD maxSinks;
28 IAdviseSink** arrayOfSinks;
30 } OleAdviseHolderImpl;
32 static LPOLEADVISEHOLDER OleAdviseHolderImpl_Constructor();
33 static void OleAdviseHolderImpl_Destructor(OleAdviseHolderImpl* ptrToDestroy);
34 static HRESULT WINAPI OleAdviseHolderImpl_QueryInterface(LPOLEADVISEHOLDER,REFIID,LPVOID*);
35 static ULONG WINAPI OleAdviseHolderImpl_AddRef(LPOLEADVISEHOLDER);
36 static ULONG WINAPI OleAdviseHolderImpl_Release(LPOLEADVISEHOLDER);
37 static HRESULT WINAPI OleAdviseHolderImpl_Advise(LPOLEADVISEHOLDER, IAdviseSink*, DWORD*);
38 static HRESULT WINAPI OleAdviseHolderImpl_Unadvise (LPOLEADVISEHOLDER, DWORD);
39 static HRESULT WINAPI OleAdviseHolderImpl_EnumAdvise (LPOLEADVISEHOLDER, IEnumSTATDATA **);
40 static HRESULT WINAPI OleAdviseHolderImpl_SendOnRename (LPOLEADVISEHOLDER, IMoniker *);
41 static HRESULT WINAPI OleAdviseHolderImpl_SendOnSave (LPOLEADVISEHOLDER);
42 static HRESULT WINAPI OleAdviseHolderImpl_SendOnClose (LPOLEADVISEHOLDER);
45 /**************************************************************************
46 * OleAdviseHolderImpl_VTable
48 static struct ICOM_VTABLE(IOleAdviseHolder) oahvt =
50 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
51 OleAdviseHolderImpl_QueryInterface,
52 OleAdviseHolderImpl_AddRef,
53 OleAdviseHolderImpl_Release,
54 OleAdviseHolderImpl_Advise,
55 OleAdviseHolderImpl_Unadvise,
56 OleAdviseHolderImpl_EnumAdvise,
57 OleAdviseHolderImpl_SendOnRename,
58 OleAdviseHolderImpl_SendOnSave,
59 OleAdviseHolderImpl_SendOnClose
62 /**************************************************************************
63 * OleAdviseHolderImpl_Constructor
66 static LPOLEADVISEHOLDER OleAdviseHolderImpl_Constructor()
68 OleAdviseHolderImpl* lpoah;
69 DWORD index;
71 lpoah= (OleAdviseHolderImpl*)HeapAlloc(GetProcessHeap(),
73 sizeof(OleAdviseHolderImpl));
75 ICOM_VTBL(lpoah) = &oahvt;
76 lpoah->ref = 1;
77 lpoah->maxSinks = 10;
78 lpoah->arrayOfSinks = HeapAlloc(GetProcessHeap(),
80 lpoah->maxSinks * sizeof(IAdviseSink*));
82 for (index = 0; index < lpoah->maxSinks; index++)
83 lpoah->arrayOfSinks[index]=0;
85 return (LPOLEADVISEHOLDER)lpoah;
88 /**************************************************************************
89 * OleAdviseHolderImpl_Destructor
91 static void OleAdviseHolderImpl_Destructor(
92 OleAdviseHolderImpl* ptrToDestroy)
94 DWORD index;
96 for (index = 0; index < ptrToDestroy->maxSinks; index++)
98 if (ptrToDestroy->arrayOfSinks[index]!=0)
100 IAdviseSink_Release(ptrToDestroy->arrayOfSinks[index]);
101 ptrToDestroy->arrayOfSinks[index] = NULL;
105 HeapFree(GetProcessHeap(),
107 ptrToDestroy->arrayOfSinks);
110 HeapFree(GetProcessHeap(),
112 ptrToDestroy);
115 /**************************************************************************
116 * OleAdviseHolderImpl_QueryInterface
118 static HRESULT WINAPI OleAdviseHolderImpl_QueryInterface(
119 LPOLEADVISEHOLDER iface,
120 REFIID riid,
121 LPVOID* ppvObj)
123 ICOM_THIS(OleAdviseHolderImpl, iface);
126 * Sanity check
128 if (ppvObj==NULL)
129 return E_POINTER;
131 *ppvObj = NULL;
133 if (IsEqualIID(riid, &IID_IUnknown))
135 /* IUnknown */
136 *ppvObj = This;
138 else if(IsEqualIID(riid, &IID_IOleAdviseHolder))
140 /* IOleAdviseHolder */
141 *ppvObj = (IOleAdviseHolder*) This;
144 if(*ppvObj == NULL)
145 return E_NOINTERFACE;
148 * A successful QI always increments the reference count.
150 IUnknown_AddRef((IUnknown*)*ppvObj);
152 return S_OK;
155 /******************************************************************************
156 * OleAdviseHolderImpl_AddRef
158 static ULONG WINAPI OleAdviseHolderImpl_AddRef(
159 LPOLEADVISEHOLDER iface)
161 ICOM_THIS(OleAdviseHolderImpl, iface);
163 return ++(This->ref);
166 /******************************************************************************
167 * OleAdviseHolderImpl_Release
169 static ULONG WINAPI OleAdviseHolderImpl_Release(
170 LPOLEADVISEHOLDER iface)
172 ICOM_THIS(OleAdviseHolderImpl, iface);
174 This->ref--;
176 if (This->ref == 0)
178 OleAdviseHolderImpl_Destructor(This);
180 return 0;
183 return This->ref;
186 /******************************************************************************
187 * OleAdviseHolderImpl_Advise
189 static HRESULT WINAPI OleAdviseHolderImpl_Advise(
190 LPOLEADVISEHOLDER iface,
191 IAdviseSink* pAdvise,
192 DWORD* pdwConnection)
194 DWORD index;
196 ICOM_THIS(OleAdviseHolderImpl, iface);
198 TRACE("(%p, %p, %p)\n", This, pAdvise, pdwConnection);
201 * Sanity check
203 if (pdwConnection==NULL)
204 return E_POINTER;
206 *pdwConnection = 0;
209 * Find a free spot in the array.
211 for (index = 0; index < This->maxSinks; index++)
213 if (This->arrayOfSinks[index]==NULL)
214 break;
218 * If the array is full, we need to grow it.
220 if (index == This->maxSinks)
222 DWORD i;
224 This->maxSinks+=10;
226 This->arrayOfSinks = HeapReAlloc(GetProcessHeap(),
228 This->arrayOfSinks,
229 This->maxSinks*sizeof(IAdviseSink*));
231 for (i=index;i < This->maxSinks; i++)
232 This->arrayOfSinks[i]=0;
236 * Store the new sink
238 This->arrayOfSinks[index] = pAdvise;
240 if (This->arrayOfSinks[index]!=NULL)
241 IAdviseSink_AddRef(This->arrayOfSinks[index]);
244 * Return the index as the cookie.
245 * Since 0 is not a valid cookie, we will increment by
246 * 1 the index in the table.
248 *pdwConnection = index+1;
250 return S_OK;
253 /******************************************************************************
254 * OleAdviseHolderImpl_Unadvise
256 static HRESULT WINAPI OleAdviseHolderImpl_Unadvise(
257 LPOLEADVISEHOLDER iface,
258 DWORD dwConnection)
260 ICOM_THIS(OleAdviseHolderImpl, iface);
262 TRACE("(%p, %lu)\n", This, dwConnection);
265 * So we don't return 0 as a cookie, the index was
266 * incremented by 1 in OleAdviseHolderImpl_Advise
267 * we have to compensate.
269 dwConnection--;
272 * Check for invalid cookies.
274 if ( (dwConnection < 0) ||
275 (dwConnection >= This->maxSinks) )
276 return OLE_E_NOCONNECTION;
278 if (This->arrayOfSinks[dwConnection] == NULL)
279 return OLE_E_NOCONNECTION;
282 * Release the sink and mark the spot in the list as free.
284 IAdviseSink_Release(This->arrayOfSinks[dwConnection]);
285 This->arrayOfSinks[dwConnection] = NULL;
287 return S_OK;
290 /******************************************************************************
291 * OleAdviseHolderImpl_EnumAdvise
293 static HRESULT WINAPI
294 OleAdviseHolderImpl_EnumAdvise (LPOLEADVISEHOLDER iface, IEnumSTATDATA **ppenumAdvise)
296 ICOM_THIS(OleAdviseHolderImpl, iface);
297 FIXME("(%p)->(%p)\n", This, ppenumAdvise);
299 *ppenumAdvise = NULL;
301 return S_OK;
304 /******************************************************************************
305 * OleAdviseHolderImpl_SendOnRename
307 static HRESULT WINAPI
308 OleAdviseHolderImpl_SendOnRename (LPOLEADVISEHOLDER iface, IMoniker *pmk)
310 ICOM_THIS(OleAdviseHolderImpl, iface);
311 FIXME("(%p)->(%p)\n", This, pmk);
314 return S_OK;
317 /******************************************************************************
318 * OleAdviseHolderImpl_SendOnSave
320 static HRESULT WINAPI
321 OleAdviseHolderImpl_SendOnSave (LPOLEADVISEHOLDER iface)
323 ICOM_THIS(OleAdviseHolderImpl, iface);
324 FIXME("(%p)\n", This);
327 return S_OK;
330 /******************************************************************************
331 * OleAdviseHolderImpl_SendOnClose
333 static HRESULT WINAPI
334 OleAdviseHolderImpl_SendOnClose (LPOLEADVISEHOLDER iface)
336 ICOM_THIS(OleAdviseHolderImpl, iface);
337 FIXME("(%p)\n", This);
340 return S_OK;
343 /**************************************************************************
344 * DataAdviseHolder Implementation
346 typedef struct DataAdviseHolder
348 ICOM_VFIELD(IDataAdviseHolder);
350 DWORD ref;
351 } DataAdviseHolder;
353 /**************************************************************************
354 * DataAdviseHolder method prototypes
356 static IDataAdviseHolder* DataAdviseHolder_Constructor();
357 static void DataAdviseHolder_Destructor(DataAdviseHolder* ptrToDestroy);
358 static HRESULT WINAPI DataAdviseHolder_QueryInterface(
359 IDataAdviseHolder* iface,
360 REFIID riid,
361 void** ppvObject);
362 static ULONG WINAPI DataAdviseHolder_AddRef(
363 IDataAdviseHolder* iface);
364 static ULONG WINAPI DataAdviseHolder_Release(
365 IDataAdviseHolder* iface);
366 static HRESULT WINAPI DataAdviseHolder_Advise(
367 IDataAdviseHolder* iface,
368 IDataObject* pDataObject,
369 FORMATETC* pFetc,
370 DWORD advf,
371 IAdviseSink* pAdvise,
372 DWORD* pdwConnection);
373 static HRESULT WINAPI DataAdviseHolder_Unadvise(
374 IDataAdviseHolder* iface,
375 DWORD dwConnection);
376 static HRESULT WINAPI DataAdviseHolder_EnumAdvise(
377 IDataAdviseHolder* iface,
378 IEnumSTATDATA** ppenumAdvise);
379 static HRESULT WINAPI DataAdviseHolder_SendOnDataChange(
380 IDataAdviseHolder* iface,
381 IDataObject* pDataObject,
382 DWORD dwReserved,
383 DWORD advf);
385 /**************************************************************************
386 * DataAdviseHolderImpl_VTable
388 static struct ICOM_VTABLE(IDataAdviseHolder) DataAdviseHolderImpl_VTable =
390 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
391 DataAdviseHolder_QueryInterface,
392 DataAdviseHolder_AddRef,
393 DataAdviseHolder_Release,
394 DataAdviseHolder_Advise,
395 DataAdviseHolder_Unadvise,
396 DataAdviseHolder_EnumAdvise,
397 DataAdviseHolder_SendOnDataChange
400 /******************************************************************************
401 * DataAdviseHolder_Constructor
403 static IDataAdviseHolder* DataAdviseHolder_Constructor()
405 DataAdviseHolder* newHolder;
407 newHolder = (DataAdviseHolder*)HeapAlloc(GetProcessHeap(),
409 sizeof(DataAdviseHolder));
411 ICOM_VTBL(newHolder) = &DataAdviseHolderImpl_VTable;
412 newHolder->ref = 1;
414 return (IDataAdviseHolder*)newHolder;
417 /******************************************************************************
418 * DataAdviseHolder_Destructor
420 static void DataAdviseHolder_Destructor(
421 DataAdviseHolder* ptrToDestroy)
423 HeapFree(GetProcessHeap(),
425 ptrToDestroy);
428 /************************************************************************
429 * DataAdviseHolder_QueryInterface (IUnknown)
431 * See Windows documentation for more details on IUnknown methods.
433 static HRESULT WINAPI DataAdviseHolder_QueryInterface(
434 IDataAdviseHolder* iface,
435 REFIID riid,
436 void** ppvObject)
438 ICOM_THIS(DataAdviseHolder, iface);
441 * Perform a sanity check on the parameters.
443 if ( (This==0) || (ppvObject==0) )
444 return E_INVALIDARG;
447 * Initialize the return parameter.
449 *ppvObject = 0;
452 * Compare the riid with the interface IDs implemented by this object.
454 if ( (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0) ||
455 (memcmp(&IID_IDataAdviseHolder, riid, sizeof(IID_IDataAdviseHolder)) == 0) )
457 *ppvObject = iface;
461 * Check that we obtained an interface.
463 if ((*ppvObject)==0)
465 return E_NOINTERFACE;
469 * Query Interface always increases the reference count by one when it is
470 * successful.
472 IUnknown_AddRef((IUnknown*)*ppvObject);
474 return S_OK;;
477 /************************************************************************
478 * DataAdviseHolder_AddRef (IUnknown)
480 * See Windows documentation for more details on IUnknown methods.
482 static ULONG WINAPI DataAdviseHolder_AddRef(
483 IDataAdviseHolder* iface)
485 ICOM_THIS(DataAdviseHolder, iface);
487 This->ref++;
489 return This->ref;
492 /************************************************************************
493 * DataAdviseHolder_Release (IUnknown)
495 * See Windows documentation for more details on IUnknown methods.
497 static ULONG WINAPI DataAdviseHolder_Release(
498 IDataAdviseHolder* iface)
500 ICOM_THIS(DataAdviseHolder, iface);
503 * Decrease the reference count on this object.
505 This->ref--;
508 * If the reference count goes down to 0, perform suicide.
510 if (This->ref==0)
512 DataAdviseHolder_Destructor(This);
514 return 0;
517 return This->ref;
520 static HRESULT WINAPI DataAdviseHolder_Advise(
521 IDataAdviseHolder* iface,
522 IDataObject* pDataObject,
523 FORMATETC* pFetc,
524 DWORD advf,
525 IAdviseSink* pAdvise,
526 DWORD* pdwConnection)
528 FIXME("(): stub\n");
529 return E_NOTIMPL;
532 static HRESULT WINAPI DataAdviseHolder_Unadvise(
533 IDataAdviseHolder* iface,
534 DWORD dwConnection)
536 FIXME("(): stub\n");
537 return E_NOTIMPL;
540 static HRESULT WINAPI DataAdviseHolder_EnumAdvise(
541 IDataAdviseHolder* iface,
542 IEnumSTATDATA** ppenumAdvise)
544 FIXME("(): stub\n");
545 return E_NOTIMPL;
548 static HRESULT WINAPI DataAdviseHolder_SendOnDataChange(
549 IDataAdviseHolder* iface,
550 IDataObject* pDataObject,
551 DWORD dwReserved,
552 DWORD advf)
554 FIXME("(): stub\n");
555 return E_NOTIMPL;
558 /***********************************************************************
559 * API functions
562 /***********************************************************************
563 * CreateOleAdviseHolder [OLE32.59]
565 HRESULT WINAPI CreateOleAdviseHolder(
566 LPOLEADVISEHOLDER *ppOAHolder)
568 TRACE("(%p)\n", ppOAHolder);
571 * Sanity check,
573 if (ppOAHolder==NULL)
574 return E_POINTER;
576 *ppOAHolder = OleAdviseHolderImpl_Constructor ();
578 if (*ppOAHolder != NULL)
579 return S_OK;
581 return E_OUTOFMEMORY;
584 /******************************************************************************
585 * CreateDataAdviseHolder [OLE32.53]
587 HRESULT WINAPI CreateDataAdviseHolder(
588 LPDATAADVISEHOLDER* ppDAHolder)
590 TRACE("(%p)\n", ppDAHolder);
593 * Sanity check,
595 if (ppDAHolder==NULL)
596 return E_POINTER;
598 *ppDAHolder = DataAdviseHolder_Constructor();
600 if (*ppDAHolder != NULL)
601 return S_OK;
603 return E_OUTOFMEMORY;