Added missing prototypes for StrRetToBuf(A|W).
[wine] / dlls / ole32 / defaulthandler.c
1 /*
2  *      OLE 2 default object handler
3  *
4  *      Copyright 1999  Francis Beaudet
5  *
6  * NOTES:
7  *    The OLE2 default object handler supports a whole whack of
8  *    interfaces including:
9  *       IOleObject, IDataObject, IPersistStorage, IViewObject2,
10  *       IRunnableObject, IOleCache2, IOleCacheControl and much more.
11  *
12  *    All the implementation details are taken from: Inside OLE
13  *    second edition by Kraig Brockschmidt,
14  *
15  * TODO
16  * - This implementation of the default handler does not launch the
17  *   server in the DoVerb, Update, GetData, GetDataHere and Run
18  *   methods. When it is fixed to do so, all the methods will have
19  *   to be  revisited to allow delegating to the running object
20  *
21  * - All methods in the class that use the class ID should be
22  *   aware that it is possible for a class to be treated as
23  *   another one and go into emulation mode. Nothing has been
24  *   done in this area.
25  *
26  * - Some functions still return E_NOTIMPL they have to be 
27  *   implemented. Most of those are related to the running of the
28  *   actual server.
29  *
30  * - All the methods related to notification and advise sinks are
31  *   in place but no notifications are sent to the sinks yet.
32  */
33 #include <assert.h>
34
35 #include "winbase.h"
36 #include "oleauto.h" /* for SysFreeString(BSTR) */
37 #include "winerror.h"
38 #include "ole2.h"
39 #include "wine/obj_oleview.h"
40 #include "debugtools.h"
41
42 DEFAULT_DEBUG_CHANNEL(ole)
43
44 /****************************************************************************
45  * DefaultHandler
46  *
47  */
48 struct DefaultHandler
49 {
50   /*
51    * List all interface VTables here
52    */
53   ICOM_VTABLE(IOleObject)*      lpvtbl1; 
54   ICOM_VTABLE(IUnknown)*        lpvtbl2;
55   ICOM_VTABLE(IDataObject)*     lpvtbl3;
56   ICOM_VTABLE(IRunnableObject)* lpvtbl4;
57
58   /*
59    * Reference count of this object
60    */
61   ULONG ref;
62
63   /*
64    * IUnknown implementation of the outer object.
65    */
66   IUnknown* outerUnknown;
67
68   /*
69    * Class Id that this handler object represents.
70    */
71   CLSID clsid;
72
73   /*
74    * IUnknown implementation of the datacache.
75    */
76   IUnknown* dataCache;
77
78   /*
79    * Client site for the embedded object.
80    */
81   IOleClientSite* clientSite;
82
83   /*
84    * The IOleAdviseHolder maintains the connections
85    * on behalf of the default handler.
86    */
87   IOleAdviseHolder* oleAdviseHolder;
88
89   /*
90    * The IDataAdviseHolder maintains the data 
91    * connections on behalf of the default handler.
92    */
93   IDataAdviseHolder* dataAdviseHolder;
94
95   /*
96    * Name of the container and object contained
97    */
98   BSTR containerApp; 
99   BSTR containerObj;
100
101 };
102
103 typedef struct DefaultHandler DefaultHandler;
104
105 /*
106  * Here, I define utility macros to help with the casting of the 
107  * "this" parameter.
108  * There is a version to accomodate all of the VTables implemented
109  * by this object.
110  */
111 #define _ICOM_THIS_From_IOleObject(class,name)       class* this = (class*)name;
112 #define _ICOM_THIS_From_NDIUnknown(class, name)      class* this = (class*)(((char*)name)-sizeof(void*)); 
113 #define _ICOM_THIS_From_IDataObject(class, name)     class* this = (class*)(((char*)name)-2*sizeof(void*)); 
114 #define _ICOM_THIS_From_IRunnableObject(class, name) class* this = (class*)(((char*)name)-3*sizeof(void*)); 
115
116 /*
117  * Prototypes for the methods of the DefaultHandler class.
118  */
119 static DefaultHandler* DefaultHandler_Construct(REFCLSID  clsid,
120                                                 LPUNKNOWN pUnkOuter);
121 static void            DefaultHandler_Destroy(DefaultHandler* ptrToDestroy);
122
123 /*
124  * Prototypes for the methods of the DefaultHandler class
125  * that implement non delegating IUnknown methods.
126  */
127 static HRESULT WINAPI DefaultHandler_NDIUnknown_QueryInterface(
128             IUnknown*      iface,
129             REFIID         riid,
130             void**         ppvObject);
131 static ULONG WINAPI DefaultHandler_NDIUnknown_AddRef( 
132             IUnknown*      iface);
133 static ULONG WINAPI DefaultHandler_NDIUnknown_Release( 
134             IUnknown*      iface);
135
136 /*
137  * Prototypes for the methods of the DefaultHandler class
138  * that implement IOleObject methods.
139  */
140 static HRESULT WINAPI DefaultHandler_QueryInterface(
141             IOleObject*      iface,
142             REFIID           riid,
143             void**           ppvObject);
144 static ULONG WINAPI DefaultHandler_AddRef( 
145             IOleObject*        iface);
146 static ULONG WINAPI DefaultHandler_Release( 
147             IOleObject*        iface);
148 static HRESULT WINAPI DefaultHandler_SetClientSite(
149             IOleObject*        iface,
150             IOleClientSite*    pClientSite);
151 static HRESULT WINAPI DefaultHandler_GetClientSite(
152             IOleObject*        iface,
153             IOleClientSite**   ppClientSite);
154 static HRESULT WINAPI DefaultHandler_SetHostNames(
155             IOleObject*        iface,
156             LPCOLESTR          szContainerApp, 
157             LPCOLESTR          szContainerObj);
158 static HRESULT WINAPI DefaultHandler_Close(
159             IOleObject*        iface, 
160             DWORD              dwSaveOption);
161 static HRESULT WINAPI DefaultHandler_SetMoniker(
162             IOleObject*        iface, 
163             DWORD              dwWhichMoniker,
164             IMoniker*          pmk);
165 static HRESULT WINAPI DefaultHandler_GetMoniker(
166             IOleObject*        iface,
167             DWORD              dwAssign,
168             DWORD              dwWhichMoniker,
169             IMoniker**         ppmk);
170 static HRESULT WINAPI DefaultHandler_InitFromData(
171             IOleObject*        iface, 
172             IDataObject*       pDataObject, 
173             BOOL               fCreation,
174             DWORD              dwReserved);
175 static HRESULT WINAPI DefaultHandler_GetClipboardData(
176             IOleObject*        iface, 
177             DWORD              dwReserved, 
178             IDataObject**      ppDataObject);
179 static HRESULT WINAPI DefaultHandler_DoVerb(
180             IOleObject*        iface, 
181             LONG               iVerb, 
182             struct tagMSG*     lpmsg, 
183             IOleClientSite*    pActiveSite, 
184             LONG               lindex, 
185             HWND               hwndParent, 
186             LPCRECT            lprcPosRect);
187 static HRESULT WINAPI DefaultHandler_EnumVerbs(
188             IOleObject*        iface, 
189             IEnumOLEVERB**     ppEnumOleVerb);
190 static HRESULT WINAPI DefaultHandler_Update(
191             IOleObject*        iface);
192 static HRESULT WINAPI DefaultHandler_IsUpToDate(
193             IOleObject*        iface);
194 static HRESULT WINAPI DefaultHandler_GetUserClassID(
195             IOleObject*        iface, 
196             CLSID*             pClsid);
197 static HRESULT WINAPI DefaultHandler_GetUserType(
198             IOleObject*        iface, 
199             DWORD              dwFormOfType, 
200             LPOLESTR*          pszUserType);
201 static HRESULT WINAPI DefaultHandler_SetExtent(
202             IOleObject*        iface, 
203             DWORD              dwDrawAspect, 
204             SIZEL*             psizel);
205 static HRESULT WINAPI DefaultHandler_GetExtent(
206             IOleObject*        iface, 
207             DWORD              dwDrawAspect, 
208             SIZEL*             psizel);
209 static HRESULT WINAPI DefaultHandler_Advise(
210             IOleObject*        iface, 
211             IAdviseSink*       pAdvSink, 
212             DWORD*             pdwConnection);
213 static HRESULT WINAPI DefaultHandler_Unadvise(
214             IOleObject*        iface, 
215             DWORD              dwConnection);
216 static HRESULT WINAPI DefaultHandler_EnumAdvise(
217             IOleObject*        iface, 
218             IEnumSTATDATA**    ppenumAdvise);
219 static HRESULT WINAPI DefaultHandler_GetMiscStatus(
220             IOleObject*        iface, 
221             DWORD              dwAspect, 
222             DWORD*             pdwStatus);
223 static HRESULT WINAPI DefaultHandler_SetColorScheme(
224             IOleObject*           iface,
225             struct tagLOGPALETTE* pLogpal);
226
227 /*
228  * Prototypes for the methods of the DefaultHandler class
229  * that implement IDataObject methods.
230  */
231 static HRESULT WINAPI DefaultHandler_IDataObject_QueryInterface(
232             IDataObject*     iface,
233             REFIID           riid,
234             void**           ppvObject);
235 static ULONG WINAPI DefaultHandler_IDataObject_AddRef( 
236             IDataObject*     iface);
237 static ULONG WINAPI DefaultHandler_IDataObject_Release( 
238             IDataObject*     iface);
239 static HRESULT WINAPI DefaultHandler_GetData(
240             IDataObject*     iface,
241             LPFORMATETC      pformatetcIn, 
242             STGMEDIUM*       pmedium);
243 static HRESULT WINAPI DefaultHandler_GetDataHere(
244             IDataObject*     iface, 
245             LPFORMATETC      pformatetc,
246             STGMEDIUM*       pmedium);
247 static HRESULT WINAPI DefaultHandler_QueryGetData(
248             IDataObject*     iface,
249             LPFORMATETC      pformatetc);
250 static HRESULT WINAPI DefaultHandler_GetCanonicalFormatEtc(
251             IDataObject*     iface, 
252             LPFORMATETC      pformatectIn, 
253             LPFORMATETC      pformatetcOut);
254 static HRESULT WINAPI DefaultHandler_SetData(
255             IDataObject*     iface,
256             LPFORMATETC      pformatetc, 
257             STGMEDIUM*       pmedium, 
258             BOOL             fRelease);
259 static HRESULT WINAPI DefaultHandler_EnumFormatEtc(
260             IDataObject*     iface,       
261             DWORD            dwDirection,
262             IEnumFORMATETC** ppenumFormatEtc);
263 static HRESULT WINAPI DefaultHandler_DAdvise(
264             IDataObject*     iface, 
265             FORMATETC*       pformatetc, 
266             DWORD            advf, 
267             IAdviseSink*     pAdvSink, 
268             DWORD*           pdwConnection);
269 static HRESULT WINAPI DefaultHandler_DUnadvise(
270             IDataObject*     iface,
271             DWORD            dwConnection);
272 static HRESULT WINAPI DefaultHandler_EnumDAdvise(
273             IDataObject*     iface,
274             IEnumSTATDATA**  ppenumAdvise);
275
276 /*
277  * Prototypes for the methods of the DefaultHandler class
278  * that implement IRunnableObject methods.
279  */
280 static HRESULT WINAPI DefaultHandler_IRunnableObject_QueryInterface(
281             IRunnableObject*     iface,
282             REFIID               riid,
283             void**               ppvObject);
284 static ULONG WINAPI DefaultHandler_IRunnableObject_AddRef( 
285             IRunnableObject*     iface);
286 static ULONG WINAPI DefaultHandler_IRunnableObject_Release( 
287             IRunnableObject*     iface);
288 static HRESULT WINAPI DefaultHandler_GetRunningClass( 
289             IRunnableObject*     iface,   
290             LPCLSID              lpClsid);
291 static HRESULT WINAPI DefaultHandler_Run( 
292             IRunnableObject*     iface,
293             IBindCtx*            pbc);
294 static BOOL    WINAPI DefaultHandler_IsRunning( 
295             IRunnableObject*     iface);
296 static HRESULT WINAPI DefaultHandler_LockRunning( 
297             IRunnableObject*     iface, 
298             BOOL                 fLock, 
299             BOOL                 fLastUnlockCloses);
300 static HRESULT WINAPI DefaultHandler_SetContainedObject( 
301             IRunnableObject*     iface, 
302             BOOL                 fContained);
303
304
305 /*
306  * Virtual function tables for the DefaultHandler class.
307  */
308 static ICOM_VTABLE(IOleObject) DefaultHandler_IOleObject_VTable =
309 {
310   ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
311   DefaultHandler_QueryInterface,
312   DefaultHandler_AddRef,
313   DefaultHandler_Release,
314   DefaultHandler_SetClientSite,
315   DefaultHandler_GetClientSite,
316   DefaultHandler_SetHostNames,
317   DefaultHandler_Close,
318   DefaultHandler_SetMoniker,
319   DefaultHandler_GetMoniker,
320   DefaultHandler_InitFromData,
321   DefaultHandler_GetClipboardData,
322   DefaultHandler_DoVerb,
323   DefaultHandler_EnumVerbs,
324   DefaultHandler_Update,
325   DefaultHandler_IsUpToDate,
326   DefaultHandler_GetUserClassID,
327   DefaultHandler_GetUserType,
328   DefaultHandler_SetExtent,
329   DefaultHandler_GetExtent,
330   DefaultHandler_Advise,
331   DefaultHandler_Unadvise,
332   DefaultHandler_EnumAdvise,
333   DefaultHandler_GetMiscStatus,
334   DefaultHandler_SetColorScheme
335 };
336
337 static ICOM_VTABLE(IUnknown) DefaultHandler_NDIUnknown_VTable =
338 {
339   ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
340   DefaultHandler_NDIUnknown_QueryInterface,
341   DefaultHandler_NDIUnknown_AddRef,
342   DefaultHandler_NDIUnknown_Release,
343 };
344
345 static ICOM_VTABLE(IDataObject) DefaultHandler_IDataObject_VTable =
346 {
347   ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
348   DefaultHandler_IDataObject_QueryInterface,
349   DefaultHandler_IDataObject_AddRef,
350   DefaultHandler_IDataObject_Release,
351   DefaultHandler_GetData,
352   DefaultHandler_GetDataHere,
353   DefaultHandler_QueryGetData,
354   DefaultHandler_GetCanonicalFormatEtc,
355   DefaultHandler_SetData,
356   DefaultHandler_EnumFormatEtc,
357   DefaultHandler_DAdvise,
358   DefaultHandler_DUnadvise,
359   DefaultHandler_EnumDAdvise
360 };
361
362 static ICOM_VTABLE(IRunnableObject) DefaultHandler_IRunnableObject_VTable =
363 {
364   ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
365   DefaultHandler_IRunnableObject_QueryInterface,
366   DefaultHandler_IRunnableObject_AddRef,
367   DefaultHandler_IRunnableObject_Release,
368   DefaultHandler_GetRunningClass,
369   DefaultHandler_Run,
370   DefaultHandler_IsRunning,
371   DefaultHandler_LockRunning,
372   DefaultHandler_SetContainedObject
373 };
374
375 /******************************************************************************
376  * OleCreateDefaultHandler [OLE32.90]
377  */
378 HRESULT WINAPI OleCreateDefaultHandler(
379   REFCLSID  clsid,
380   LPUNKNOWN pUnkOuter,
381   REFIID    riid,
382   LPVOID*   ppvObj)
383 {
384   DefaultHandler* newHandler = NULL;
385   HRESULT         hr         = S_OK;
386   char            xclsid[50];
387   char            xriid[50];
388
389   WINE_StringFromCLSID((LPCLSID)clsid,xclsid);
390   WINE_StringFromCLSID((LPCLSID)riid,xriid);
391
392   TRACE("(%s, %p, %s, %p)\n", xclsid, pUnkOuter, xriid, ppvObj);
393
394   /*
395    * Sanity check
396    */
397   if (ppvObj==0)
398     return E_POINTER;
399
400   *ppvObj = 0;
401
402   /*
403    * If this handler is constructed for aggregation, make sure
404    * the caller is requesting the IUnknown interface.
405    * This is necessary because it's the only time the non-delegating
406    * IUnknown pointer can be returned to the outside.
407    */
408   if ( (pUnkOuter!=NULL) && 
409        (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) != 0) )
410     return CLASS_E_NOAGGREGATION;
411
412   /*
413    * Try to construct a new instance of the class.
414    */
415   newHandler = DefaultHandler_Construct(clsid, 
416                                         pUnkOuter);
417
418   if (newHandler == 0)
419     return E_OUTOFMEMORY;
420
421   /*
422    * Make sure it supports the interface required by the caller.
423    */
424   hr = IUnknown_QueryInterface((IUnknown*)&(newHandler->lpvtbl2), riid, ppvObj);
425
426   /*
427    * Release the reference obtained in the constructor. If
428    * the QueryInterface was unsuccessful, it will free the class.
429    */
430   IUnknown_Release((IUnknown*)&(newHandler->lpvtbl2));
431
432   return hr;
433 }
434
435 /*********************************************************
436  * Methods implementation for the DefaultHandler class.
437  */
438 static DefaultHandler* DefaultHandler_Construct(
439   REFCLSID  clsid,
440   LPUNKNOWN pUnkOuter)
441 {
442   DefaultHandler* newObject = 0;
443
444   /*
445    * Allocate space for the object.
446    */
447   newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(DefaultHandler));
448
449   if (newObject==0)
450     return newObject;
451   
452   /*
453    * Initialize the virtual function table.
454    */
455   newObject->lpvtbl1 = &DefaultHandler_IOleObject_VTable;
456   newObject->lpvtbl2 = &DefaultHandler_NDIUnknown_VTable;
457   newObject->lpvtbl3 = &DefaultHandler_IDataObject_VTable;
458   newObject->lpvtbl4 = &DefaultHandler_IRunnableObject_VTable;
459
460   /*
461    * Start with one reference count. The caller of this function 
462    * must release the interface pointer when it is done.
463    */
464   newObject->ref = 1;
465
466   /*
467    * Initialize the outer unknown
468    * We don't keep a reference on the outer unknown since, the way 
469    * aggregation works, our lifetime is at least as large as it's
470    * lifetime.
471    */
472   if (pUnkOuter==NULL)
473     pUnkOuter = (IUnknown*)&(newObject->lpvtbl2);
474
475   newObject->outerUnknown = pUnkOuter;
476
477   /*
478    * Create a datacache object.
479    * We aggregate with the datacache. Make sure we pass our outer
480    * unknown as the datacache's outer unknown. 
481    */
482   CreateDataCache(newObject->outerUnknown,
483                   clsid,
484                   &IID_IUnknown,
485                   (void**)&newObject->dataCache);
486
487   /*
488    * Initialize the other data members of the class.
489    */
490   memcpy(&(newObject->clsid), clsid, sizeof(CLSID));
491   newObject->clientSite = NULL;
492   newObject->oleAdviseHolder = NULL;
493   newObject->dataAdviseHolder = NULL;
494   newObject->containerApp = NULL;
495   newObject->containerObj = NULL;
496
497   return newObject;
498 }
499
500 static void DefaultHandler_Destroy(
501   DefaultHandler* ptrToDestroy)
502 {
503   /*
504    * Free the strings idenfitying the object
505    */
506   if (ptrToDestroy->containerApp!=NULL)
507   {
508     SysFreeString(ptrToDestroy->containerApp);
509     ptrToDestroy->containerApp = NULL;
510   }
511
512   if (ptrToDestroy->containerObj!=NULL)
513   {
514     SysFreeString(ptrToDestroy->containerObj);
515     ptrToDestroy->containerObj = NULL;
516   }
517   
518   /*
519    * Release our reference to the data cache.
520    */
521   if (ptrToDestroy->dataCache!=NULL)
522   {
523     IUnknown_Release(ptrToDestroy->dataCache);
524     ptrToDestroy->dataCache = NULL;
525   }
526
527   /*
528    * Same thing for the client site.
529    */
530   if (ptrToDestroy->clientSite!=NULL)
531   {
532     IOleClientSite_Release(ptrToDestroy->clientSite);
533     ptrToDestroy->clientSite = NULL;
534   }
535
536   /*
537    * And the advise holder.
538    */
539   if (ptrToDestroy->oleAdviseHolder!=NULL)
540   {
541     IOleClientSite_Release(ptrToDestroy->oleAdviseHolder);
542     ptrToDestroy->oleAdviseHolder = NULL;
543   }
544
545   /*
546    * And the data advise holder.
547    */
548   if (ptrToDestroy->dataAdviseHolder!=NULL)
549   {
550     IOleClientSite_Release(ptrToDestroy->dataAdviseHolder);
551     ptrToDestroy->dataAdviseHolder = NULL;
552   }
553
554
555   /*
556    * Free the actual default handler structure.
557    */
558   HeapFree(GetProcessHeap(), 0, ptrToDestroy);
559 }
560
561 /*********************************************************
562  * Method implementation for the  non delegating IUnknown
563  * part of the DefaultHandler class.
564  */
565
566 /************************************************************************
567  * DefaultHandler_NDIUnknown_QueryInterface (IUnknown)
568  *
569  * See Windows documentation for more details on IUnknown methods.
570  *
571  * This version of QueryInterface will not delegate it's implementation
572  * to the outer unknown.
573  */
574 static HRESULT WINAPI DefaultHandler_NDIUnknown_QueryInterface(
575             IUnknown*      iface,
576             REFIID         riid,
577             void**         ppvObject)
578 {
579   _ICOM_THIS_From_NDIUnknown(DefaultHandler, iface);
580
581   /*
582    * Perform a sanity check on the parameters.
583    */
584   if ( (this==0) || (ppvObject==0) )
585     return E_INVALIDARG;
586   
587   /*
588    * Initialize the return parameter.
589    */
590   *ppvObject = 0;
591
592   /*
593    * Compare the riid with the interface IDs implemented by this object.
594    */
595   if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0) 
596   {
597     *ppvObject = iface;
598   }
599   else if (memcmp(&IID_IOleObject, riid, sizeof(IID_IOleObject)) == 0) 
600   {
601     *ppvObject = (IOleObject*)&(this->lpvtbl1);
602   }
603   else if (memcmp(&IID_IDataObject, riid, sizeof(IID_IDataObject)) == 0) 
604   {
605     *ppvObject = (IDataObject*)&(this->lpvtbl3);
606   }
607   else if (memcmp(&IID_IRunnableObject, riid, sizeof(IID_IRunnableObject)) == 0) 
608   {
609     *ppvObject = (IRunnableObject*)&(this->lpvtbl4);
610   }
611   else
612   {
613     /*
614      * Blind aggregate the data cache to "inherit" it's interfaces.
615      */
616     IUnknown_QueryInterface(this->dataCache, riid, ppvObject);
617   }
618   
619   /*
620    * Check that we obtained an interface.
621    */
622   if ((*ppvObject)==0)
623   {
624     char clsid[50];
625
626     WINE_StringFromCLSID((LPCLSID)riid,clsid);
627     
628     WARN(
629          "() : asking for un supported interface %s\n", 
630          clsid);
631
632     return E_NOINTERFACE;
633   }
634   
635   /*
636    * Query Interface always increases the reference count by one when it is
637    * successful. 
638    */
639   IUnknown_AddRef((IUnknown*)*ppvObject);
640
641   return S_OK;;  
642 }
643
644 /************************************************************************
645  * DefaultHandler_NDIUnknown_AddRef (IUnknown)
646  *
647  * See Windows documentation for more details on IUnknown methods.
648  *
649  * This version of QueryInterface will not delegate it's implementation
650  * to the outer unknown.
651  */
652 static ULONG WINAPI DefaultHandler_NDIUnknown_AddRef( 
653             IUnknown*      iface)
654 {
655   _ICOM_THIS_From_NDIUnknown(DefaultHandler, iface);
656
657   this->ref++;
658
659   return this->ref;
660 }
661
662 /************************************************************************
663  * DefaultHandler_NDIUnknown_Release (IUnknown)
664  *
665  * See Windows documentation for more details on IUnknown methods.
666  *
667  * This version of QueryInterface will not delegate it's implementation
668  * to the outer unknown.
669  */
670 static ULONG WINAPI DefaultHandler_NDIUnknown_Release( 
671             IUnknown*      iface)
672 {
673   _ICOM_THIS_From_NDIUnknown(DefaultHandler, iface);
674
675   /*
676    * Decrease the reference count on this object.
677    */
678   this->ref--;
679
680   /*
681    * If the reference count goes down to 0, perform suicide.
682    */
683   if (this->ref==0)
684   {
685     DefaultHandler_Destroy(this);
686
687     return 0;
688   }
689   
690   return this->ref;
691 }
692
693 /*********************************************************
694  * Methods implementation for the IOleObject part of
695  * the DefaultHandler class.
696  */
697
698 /************************************************************************
699  * DefaultHandler_QueryInterface (IUnknown)
700  *
701  * See Windows documentation for more details on IUnknown methods.
702  */
703 static HRESULT WINAPI DefaultHandler_QueryInterface(
704             IOleObject*      iface,
705             REFIID           riid,
706             void**           ppvObject)
707 {
708   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
709
710   return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject);  
711 }
712
713 /************************************************************************
714  * DefaultHandler_AddRef (IUnknown)
715  *
716  * See Windows documentation for more details on IUnknown methods.
717  */
718 static ULONG WINAPI DefaultHandler_AddRef( 
719             IOleObject*        iface)
720 {
721   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
722
723   return IUnknown_AddRef(this->outerUnknown);
724 }
725
726 /************************************************************************
727  * DefaultHandler_Release (IUnknown)
728  *
729  * See Windows documentation for more details on IUnknown methods.
730  */
731 static ULONG WINAPI DefaultHandler_Release( 
732             IOleObject*        iface)
733 {
734   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
735
736   return IUnknown_Release(this->outerUnknown);
737 }
738
739 /************************************************************************
740  * DefaultHandler_SetClientSite (IOleObject)
741  *
742  * The default handler's implementation of this method only keeps the
743  * client site pointer for future reference.
744  *
745  * See Windows documentation for more details on IOleObject methods.
746  */
747 static HRESULT WINAPI DefaultHandler_SetClientSite(
748             IOleObject*        iface,
749             IOleClientSite*    pClientSite)
750 {
751   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
752
753   TRACE("(%p, %p)\n", iface, pClientSite);
754
755   /*
756    * Make sure we release the previous client site if there
757    * was one.
758    */
759   if (this->clientSite!=NULL)
760   {
761     IOleClientSite_Release(this->clientSite);
762   }
763
764   this->clientSite = pClientSite;
765
766   if (this->clientSite!=NULL)
767   {
768     IOleClientSite_AddRef(this->clientSite);
769   }
770
771   return S_OK;
772 }
773
774 /************************************************************************
775  * DefaultHandler_GetClientSite (IOleObject)
776  *
777  * The default handler's implementation of this method returns the
778  * last pointer set in IOleObject_SetClientSite.
779  *
780  * See Windows documentation for more details on IOleObject methods.
781  */
782 static HRESULT WINAPI DefaultHandler_GetClientSite(
783             IOleObject*        iface,
784             IOleClientSite**   ppClientSite)
785 {
786   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
787
788   /*
789    * Sanity check.
790    */
791   if (ppClientSite == NULL)
792     return E_POINTER;
793
794   *ppClientSite = this->clientSite;
795
796   if (*ppClientSite!=NULL)
797   {
798     IOleClientSite_Release(*ppClientSite);
799   }
800
801   return S_OK;
802 }
803
804 /************************************************************************
805  * DefaultHandler_SetHostNames (IOleObject)
806  *
807  * The default handler's implementation of this method just stores
808  * the strings and returns S_OK.
809  *
810  * See Windows documentation for more details on IOleObject methods.
811  */
812 static HRESULT WINAPI DefaultHandler_SetHostNames(
813             IOleObject*        iface,
814             LPCOLESTR          szContainerApp, 
815             LPCOLESTR          szContainerObj)
816 {
817   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
818
819   TRACE("(%p, %s, %s)\n",
820         iface,
821         debugstr_w(szContainerApp), 
822         debugstr_w(szContainerObj));
823
824   /*
825    * Be sure to cleanup before re-assinging the strings.
826    */ 
827   if (this->containerApp!=NULL)
828   {
829     SysFreeString(this->containerApp);
830     this->containerApp = NULL;
831   }
832
833   if (this->containerObj!=NULL)
834   {
835     SysFreeString(this->containerObj);
836     this->containerObj = NULL;
837   }
838
839   /*
840    * Copy the string supplied.
841    */
842   if (szContainerApp != NULL)
843     this->containerApp = SysAllocString(szContainerApp);
844
845   if (szContainerObj != NULL)
846     this->containerObj = SysAllocString(szContainerObj);
847  
848   return S_OK;
849 }
850
851 /************************************************************************
852  * DefaultHandler_Close (IOleObject)
853  *
854  * The default handler's implementation of this method is meaningless
855  * without a running server so it does nothing.
856  *
857  * See Windows documentation for more details on IOleObject methods.
858  */
859 static HRESULT WINAPI DefaultHandler_Close(
860             IOleObject*        iface, 
861             DWORD              dwSaveOption)
862 {
863   TRACE("()\n");
864   return S_OK;
865 }
866
867 /************************************************************************
868  * DefaultHandler_SetMoniker (IOleObject)
869  *
870  * The default handler's implementation of this method does nothing.
871  *
872  * See Windows documentation for more details on IOleObject methods.
873  */
874 static HRESULT WINAPI DefaultHandler_SetMoniker(
875             IOleObject*        iface, 
876             DWORD              dwWhichMoniker,
877             IMoniker*          pmk)
878 {
879   TRACE("(%p, %ld, %p)\n",
880         iface, 
881         dwWhichMoniker, 
882         pmk);
883
884   return S_OK;
885 }
886
887 /************************************************************************
888  * DefaultHandler_GetMoniker (IOleObject)
889  *
890  * Delegate this request to the client site if we have one.
891  *
892  * See Windows documentation for more details on IOleObject methods.
893  */
894 static HRESULT WINAPI DefaultHandler_GetMoniker(
895             IOleObject*        iface,
896             DWORD              dwAssign,
897             DWORD              dwWhichMoniker,
898             IMoniker**         ppmk)
899 {
900   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
901
902   TRACE("(%p, %ld, %ld, %p)\n",
903         iface, dwAssign, dwWhichMoniker, ppmk);
904
905   if (this->clientSite)
906   {
907     return IOleClientSite_GetMoniker(this->clientSite,
908                                      dwAssign,
909                                      dwWhichMoniker,
910                                      ppmk);
911                               
912   }
913
914   return E_UNSPEC;
915 }
916
917 /************************************************************************
918  * DefaultHandler_InitFromData (IOleObject)
919  *
920  * This method is meaningless if the server is not running
921  * 
922  * See Windows documentation for more details on IOleObject methods.
923  */
924 static HRESULT WINAPI DefaultHandler_InitFromData(
925             IOleObject*        iface, 
926             IDataObject*       pDataObject, 
927             BOOL               fCreation,
928             DWORD              dwReserved)
929 {
930   TRACE("(%p, %p, %d, %ld)\n",
931         iface, pDataObject, fCreation, dwReserved);
932
933   return OLE_E_NOTRUNNING;
934 }
935
936 /************************************************************************
937  * DefaultHandler_GetClipboardData (IOleObject)
938  *
939  * This method is meaningless if the server is not running
940  * 
941  * See Windows documentation for more details on IOleObject methods.
942  */
943 static HRESULT WINAPI DefaultHandler_GetClipboardData(
944             IOleObject*        iface, 
945             DWORD              dwReserved, 
946             IDataObject**      ppDataObject)
947 {
948   TRACE("(%p, %ld, %p)\n",
949         iface, dwReserved, ppDataObject);
950
951   return OLE_E_NOTRUNNING;
952 }
953
954 static HRESULT WINAPI DefaultHandler_DoVerb(
955             IOleObject*        iface, 
956             LONG               iVerb, 
957             struct tagMSG*     lpmsg, 
958             IOleClientSite*    pActiveSite, 
959             LONG               lindex, 
960             HWND               hwndParent, 
961             LPCRECT            lprcPosRect)
962 {
963   FIXME(": Stub\n");
964   return E_NOTIMPL;
965 }
966
967 /************************************************************************
968  * DefaultHandler_EnumVerbs (IOleObject)
969  *
970  * The default handler implementation of this method simply delegates
971  * to OleRegEnumVerbs
972  * 
973  * See Windows documentation for more details on IOleObject methods.
974  */
975 static HRESULT WINAPI DefaultHandler_EnumVerbs(
976             IOleObject*        iface, 
977             IEnumOLEVERB**     ppEnumOleVerb)
978 {
979   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
980
981   TRACE("(%p, %p)\n", iface, ppEnumOleVerb);
982
983   return OleRegEnumVerbs(&this->clsid, ppEnumOleVerb);
984 }
985
986 static HRESULT WINAPI DefaultHandler_Update(
987             IOleObject*        iface)
988 {
989   FIXME(": Stub\n");
990   return E_NOTIMPL;
991 }
992
993 /************************************************************************
994  * DefaultHandler_IsUpToDate (IOleObject)
995  *
996  * This method is meaningless if the server is not running
997  * 
998  * See Windows documentation for more details on IOleObject methods.
999  */
1000 static HRESULT WINAPI DefaultHandler_IsUpToDate(
1001             IOleObject*        iface)
1002 {
1003   TRACE("(%p)\n", iface);
1004
1005   return OLE_E_NOTRUNNING;
1006 }
1007
1008 /************************************************************************
1009  * DefaultHandler_GetUserClassID (IOleObject)
1010  *
1011  * TODO: Map to a new class ID if emulation is active.
1012  * 
1013  * See Windows documentation for more details on IOleObject methods.
1014  */
1015 static HRESULT WINAPI DefaultHandler_GetUserClassID(
1016             IOleObject*        iface, 
1017             CLSID*             pClsid)
1018 {
1019   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
1020
1021   TRACE("(%p, %p)\n", iface, pClsid);
1022
1023   /*
1024    * Sanity check.
1025    */
1026   if (pClsid==NULL)
1027     return E_POINTER;
1028
1029   memcpy(pClsid, &this->clsid, sizeof(CLSID));
1030
1031   return S_OK;
1032 }
1033
1034 /************************************************************************
1035  * DefaultHandler_GetUserType (IOleObject)
1036  *
1037  * The default handler implementation of this method simply delegates
1038  * to OleRegGetUserType
1039  * 
1040  * See Windows documentation for more details on IOleObject methods.
1041  */
1042 static HRESULT WINAPI DefaultHandler_GetUserType(
1043             IOleObject*        iface, 
1044             DWORD              dwFormOfType, 
1045             LPOLESTR*          pszUserType)
1046 {
1047   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
1048
1049   TRACE("(%p, %ld, %p)\n", iface, dwFormOfType, pszUserType);
1050
1051   return OleRegGetUserType(&this->clsid, dwFormOfType, pszUserType);
1052 }
1053
1054 /************************************************************************
1055  * DefaultHandler_SetExtent (IOleObject)
1056  *
1057  * This method is meaningless if the server is not running
1058  *
1059  * See Windows documentation for more details on IOleObject methods.
1060  */
1061 static HRESULT WINAPI DefaultHandler_SetExtent(
1062             IOleObject*        iface, 
1063             DWORD              dwDrawAspect, 
1064             SIZEL*             psizel)
1065 {
1066   TRACE("(%p, %lx, (%d,%d))\n", iface, dwDrawAspect, psizel->cx, psizel->cy);
1067   return OLE_E_NOTRUNNING;
1068 }
1069
1070 /************************************************************************
1071  * DefaultHandler_GetExtent (IOleObject)
1072  *
1073  * The default handler's implementation of this method returns uses
1074  * the cache to locate the aspect and extract the extent from it.
1075  *
1076  * See Windows documentation for more details on IOleObject methods.
1077  */
1078 static HRESULT WINAPI DefaultHandler_GetExtent(
1079             IOleObject*        iface, 
1080             DWORD              dwDrawAspect, 
1081             SIZEL*             psizel)
1082 {
1083   DVTARGETDEVICE* targetDevice;
1084   IViewObject2*   cacheView = NULL;
1085   HRESULT         hres;
1086
1087   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);  
1088
1089   TRACE("(%p, %lx, %p)\n", iface, dwDrawAspect, psizel);
1090
1091   hres = IUnknown_QueryInterface(this->dataCache, &IID_IViewObject2, (void**)&cacheView);
1092
1093   if (FAILED(hres))
1094     return E_UNEXPECTED;
1095
1096   /*
1097    * Prepare the call to the cache's GetExtent method.
1098    *
1099    * Here we would build a valid DVTARGETDEVICE structure
1100    * but, since we are calling into the data cache, we 
1101    * know it's implementation and we'll skip this 
1102    * extra work until later.
1103    */
1104   targetDevice = NULL;
1105
1106   hres = IViewObject2_GetExtent(cacheView,
1107                                 dwDrawAspect,
1108                                 -1,
1109                                 targetDevice,
1110                                 psizel);
1111
1112   /*
1113    * Cleanup
1114    */
1115   IViewObject2_Release(cacheView);
1116
1117   return hres;
1118 }
1119
1120 /************************************************************************
1121  * DefaultHandler_Advise (IOleObject)
1122  *
1123  * The default handler's implementation of this method simply
1124  * delegates to the OleAdviseHolder.
1125  *
1126  * See Windows documentation for more details on IOleObject methods.
1127  */
1128 static HRESULT WINAPI DefaultHandler_Advise(
1129             IOleObject*        iface, 
1130             IAdviseSink*       pAdvSink, 
1131             DWORD*             pdwConnection)
1132 {
1133   HRESULT hres = S_OK;
1134   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);  
1135
1136   TRACE("(%p, %p, %p)\n", iface, pAdvSink, pdwConnection);
1137
1138   /*
1139    * Make sure we have an advise holder before we start.
1140    */
1141   if (this->oleAdviseHolder==NULL)
1142   {
1143     hres = CreateOleAdviseHolder(&this->oleAdviseHolder);
1144   }
1145
1146   if (SUCCEEDED(hres))
1147   {
1148     hres = IOleAdviseHolder_Advise(this->oleAdviseHolder, 
1149                                    pAdvSink, 
1150                                    pdwConnection);
1151   }
1152
1153   return hres;
1154 }
1155
1156 /************************************************************************
1157  * DefaultHandler_Unadvise (IOleObject)
1158  *
1159  * The default handler's implementation of this method simply
1160  * delegates to the OleAdviseHolder.
1161  *
1162  * See Windows documentation for more details on IOleObject methods.
1163  */
1164 static HRESULT WINAPI DefaultHandler_Unadvise(
1165             IOleObject*        iface, 
1166             DWORD              dwConnection)
1167 {
1168   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);  
1169
1170   TRACE("(%p, %ld)\n", iface, dwConnection);
1171
1172   /*
1173    * If we don't have an advise holder yet, it means we don't have
1174    * a connection.
1175    */
1176   if (this->oleAdviseHolder==NULL)
1177     return OLE_E_NOCONNECTION;
1178
1179   return IOleAdviseHolder_Unadvise(this->oleAdviseHolder,
1180                                    dwConnection);
1181 }
1182
1183 /************************************************************************
1184  * DefaultHandler_EnumAdvise (IOleObject)
1185  *
1186  * The default handler's implementation of this method simply
1187  * delegates to the OleAdviseHolder.
1188  *
1189  * See Windows documentation for more details on IOleObject methods.
1190  */
1191 static HRESULT WINAPI DefaultHandler_EnumAdvise(
1192             IOleObject*        iface, 
1193             IEnumSTATDATA**    ppenumAdvise)
1194 {
1195   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);  
1196
1197   TRACE("(%p, %p)\n", iface, ppenumAdvise);
1198
1199   /*
1200    * Sanity check
1201    */
1202   if (ppenumAdvise==NULL)
1203     return E_POINTER;
1204
1205   /*
1206    * Initialize the out parameter.
1207    */
1208   *ppenumAdvise = NULL;
1209
1210   if (this->oleAdviseHolder==NULL)
1211     return IOleAdviseHolder_EnumAdvise(this->oleAdviseHolder,
1212                                        ppenumAdvise);
1213
1214   return S_OK;
1215 }
1216
1217 /************************************************************************
1218  * DefaultHandler_GetMiscStatus (IOleObject)
1219  *
1220  * The default handler's implementation of this method simply delegates
1221  * to OleRegGetMiscStatus.
1222  *
1223  * See Windows documentation for more details on IOleObject methods.
1224  */
1225 static HRESULT WINAPI DefaultHandler_GetMiscStatus(
1226             IOleObject*        iface, 
1227             DWORD              dwAspect, 
1228             DWORD*             pdwStatus)
1229 {
1230   HRESULT hres;
1231   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
1232
1233   TRACE("(%p, %lx, %p)\n", iface, dwAspect, pdwStatus);
1234
1235   hres = OleRegGetMiscStatus(&(this->clsid), dwAspect, pdwStatus);
1236
1237   if (FAILED(hres))
1238     *pdwStatus = 0;
1239
1240   return S_OK;
1241 }
1242
1243 /************************************************************************
1244  * DefaultHandler_SetExtent (IOleObject)
1245  *
1246  * This method is meaningless if the server is not running
1247  *
1248  * See Windows documentation for more details on IOleObject methods.
1249  */
1250 static HRESULT WINAPI DefaultHandler_SetColorScheme(
1251             IOleObject*           iface,
1252             struct tagLOGPALETTE* pLogpal)
1253 {
1254   TRACE("(%p, %p))\n", iface, pLogpal);
1255   return OLE_E_NOTRUNNING;
1256 }
1257
1258 /*********************************************************
1259  * Methods implementation for the IDataObject part of
1260  * the DefaultHandler class.
1261  */
1262
1263 /************************************************************************
1264  * DefaultHandler_IDataObject_QueryInterface (IUnknown)
1265  *
1266  * See Windows documentation for more details on IUnknown methods.
1267  */
1268 static HRESULT WINAPI DefaultHandler_IDataObject_QueryInterface(
1269             IDataObject*     iface, 
1270            REFIID           riid,
1271             void**           ppvObject)
1272 {
1273   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);
1274
1275   return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject);  
1276 }
1277
1278 /************************************************************************
1279  * DefaultHandler_IDataObject_AddRef (IUnknown)
1280  *
1281  * See Windows documentation for more details on IUnknown methods.
1282  */
1283 static ULONG WINAPI DefaultHandler_IDataObject_AddRef( 
1284             IDataObject*     iface)
1285 {
1286   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);
1287
1288   return IUnknown_AddRef(this->outerUnknown);  
1289 }
1290
1291 /************************************************************************
1292  * DefaultHandler_IDataObject_Release (IUnknown)
1293  *
1294  * See Windows documentation for more details on IUnknown methods.
1295  */
1296 static ULONG WINAPI DefaultHandler_IDataObject_Release( 
1297             IDataObject*     iface)
1298 {
1299   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);
1300
1301   return IUnknown_Release(this->outerUnknown);  
1302 }
1303
1304 static HRESULT WINAPI DefaultHandler_GetData(
1305             IDataObject*     iface,
1306             LPFORMATETC      pformatetcIn, 
1307             STGMEDIUM*       pmedium)
1308 {
1309   FIXME(": Stub\n");
1310   return E_NOTIMPL;
1311 }
1312
1313 static HRESULT WINAPI DefaultHandler_GetDataHere(
1314             IDataObject*     iface, 
1315             LPFORMATETC      pformatetc,
1316             STGMEDIUM*       pmedium)
1317 {
1318   FIXME(": Stub\n");
1319   return E_NOTIMPL;
1320 }
1321
1322 /************************************************************************
1323  * DefaultHandler_QueryGetData (IDataObject)
1324  *
1325  * The default handler's implementation of this method delegates to 
1326  * the cache.
1327  *
1328  * See Windows documentation for more details on IDataObject methods.
1329  */
1330 static HRESULT WINAPI DefaultHandler_QueryGetData(
1331             IDataObject*     iface,
1332             LPFORMATETC      pformatetc)
1333 {
1334   IDataObject* cacheDataObject = NULL;
1335   HRESULT      hres;
1336
1337   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);
1338
1339   TRACE("(%p, %p)\n", iface, pformatetc);
1340
1341   hres = IUnknown_QueryInterface(this->dataCache, 
1342                                  &IID_IDataObject,
1343                                  (void**)&cacheDataObject);
1344
1345   if (FAILED(hres))
1346     return E_UNEXPECTED;
1347
1348   hres = IDataObject_QueryGetData(cacheDataObject,
1349                                   pformatetc);
1350
1351   IDataObject_Release(cacheDataObject);
1352   
1353   return hres;
1354 }
1355
1356 /************************************************************************
1357  * DefaultHandler_GetCanonicalFormatEtc (IDataObject)
1358  *
1359  * This method is meaningless if the server is not running
1360  *
1361  * See Windows documentation for more details on IDataObject methods.
1362  */
1363 static HRESULT WINAPI DefaultHandler_GetCanonicalFormatEtc(
1364             IDataObject*     iface, 
1365             LPFORMATETC      pformatectIn, 
1366             LPFORMATETC      pformatetcOut)
1367 {
1368   FIXME("(%p, %p, %p)\n", iface, pformatectIn, pformatetcOut);
1369
1370   return OLE_E_NOTRUNNING;
1371 }
1372
1373 /************************************************************************
1374  * DefaultHandler_SetData (IDataObject)
1375  *
1376  * The default handler's implementation of this method delegates to 
1377  * the cache.
1378  *
1379  * See Windows documentation for more details on IDataObject methods.
1380  */
1381 static HRESULT WINAPI DefaultHandler_SetData(
1382             IDataObject*     iface,
1383             LPFORMATETC      pformatetc, 
1384             STGMEDIUM*       pmedium, 
1385             BOOL             fRelease)
1386 {
1387   IDataObject* cacheDataObject = NULL;
1388   HRESULT      hres;
1389
1390   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);
1391
1392   TRACE("(%p, %p, %p, %d)\n", iface, pformatetc, pmedium, fRelease);
1393
1394   hres = IUnknown_QueryInterface(this->dataCache, 
1395                                  &IID_IDataObject,
1396                                  (void**)&cacheDataObject);
1397
1398   if (FAILED(hres))
1399     return E_UNEXPECTED;
1400
1401   hres = IDataObject_SetData(cacheDataObject,
1402                              pformatetc,
1403                              pmedium,
1404                              fRelease);
1405   
1406   IDataObject_Release(cacheDataObject);
1407   
1408   return hres;
1409 }
1410
1411 /************************************************************************
1412  * DefaultHandler_EnumFormatEtc (IDataObject)
1413  *
1414  * The default handler's implementation of this method simply delegates
1415  * to OleRegEnumFormatEtc.
1416  *
1417  * See Windows documentation for more details on IDataObject methods.
1418  */
1419 static HRESULT WINAPI DefaultHandler_EnumFormatEtc(
1420             IDataObject*     iface,       
1421             DWORD            dwDirection,
1422             IEnumFORMATETC** ppenumFormatEtc)
1423 {
1424   HRESULT hres;
1425   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);
1426
1427   TRACE("(%p, %lx, %p)\n", iface, dwDirection, ppenumFormatEtc);
1428
1429   hres = OleRegEnumFormatEtc(&(this->clsid), dwDirection, ppenumFormatEtc);
1430
1431   return hres;
1432 }
1433
1434 /************************************************************************
1435  * DefaultHandler_DAdvise (IDataObject)
1436  *
1437  * The default handler's implementation of this method simply
1438  * delegates to the DataAdviseHolder.
1439  *
1440  * See Windows documentation for more details on IDataObject methods.
1441  */
1442 static HRESULT WINAPI DefaultHandler_DAdvise(
1443             IDataObject*     iface, 
1444             FORMATETC*       pformatetc, 
1445             DWORD            advf, 
1446             IAdviseSink*     pAdvSink, 
1447             DWORD*           pdwConnection)
1448 {
1449   HRESULT hres = S_OK;
1450   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);  
1451
1452   TRACE("(%p, %p, %ld, %p, %p)\n", 
1453         iface, pformatetc, advf, pAdvSink, pdwConnection);
1454
1455   /*
1456    * Make sure we have a data advise holder before we start.
1457    */
1458   if (this->dataAdviseHolder==NULL)
1459   {
1460     hres = CreateDataAdviseHolder(&this->dataAdviseHolder);
1461   }
1462
1463   if (SUCCEEDED(hres))
1464   {
1465     hres = IDataAdviseHolder_Advise(this->dataAdviseHolder, 
1466                                     iface,
1467                                     pformatetc, 
1468                                     advf, 
1469                                     pAdvSink, 
1470                                     pdwConnection);
1471   }
1472
1473   return hres;
1474 }
1475
1476 /************************************************************************
1477  * DefaultHandler_DUnadvise (IDataObject)
1478  *
1479  * The default handler's implementation of this method simply
1480  * delegates to the DataAdviseHolder.
1481  *
1482  * See Windows documentation for more details on IDataObject methods.
1483  */
1484 static HRESULT WINAPI DefaultHandler_DUnadvise(
1485             IDataObject*     iface,
1486             DWORD            dwConnection)
1487 {
1488   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);  
1489
1490   TRACE("(%p, %ld)\n", iface, dwConnection);
1491
1492   /*
1493    * If we don't have a data advise holder yet, it means that
1494    * we don't have any connections..
1495    */
1496   if (this->dataAdviseHolder==NULL)
1497   {
1498     return OLE_E_NOCONNECTION;
1499   }
1500
1501   return IDataAdviseHolder_Unadvise(this->dataAdviseHolder, 
1502                                     dwConnection);
1503 }
1504
1505 /************************************************************************
1506  * DefaultHandler_EnumDAdvise (IDataObject)
1507  *
1508  * The default handler's implementation of this method simply
1509  * delegates to the DataAdviseHolder.
1510  *
1511  * See Windows documentation for more details on IDataObject methods.
1512  */
1513 static HRESULT WINAPI DefaultHandler_EnumDAdvise(
1514             IDataObject*     iface,
1515             IEnumSTATDATA**  ppenumAdvise)
1516 {
1517   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);  
1518
1519   TRACE("(%p, %p)\n", iface, ppenumAdvise);
1520
1521   /*
1522    * Sanity check
1523    */
1524   if (ppenumAdvise == NULL)
1525     return E_POINTER;
1526
1527   /*
1528    * Initialize the out parameter.
1529    */
1530   *ppenumAdvise = NULL;
1531
1532   /*
1533    * If we have a data advise holder object, delegate.
1534    */
1535   if (this->dataAdviseHolder!=NULL)
1536   {
1537     return IDataAdviseHolder_EnumAdvise(this->dataAdviseHolder, 
1538                                         ppenumAdvise);
1539   }
1540
1541   return S_OK;
1542 }
1543
1544 /*********************************************************
1545  * Methods implementation for the IRunnableObject part 
1546  * of the DefaultHandler class.
1547  */
1548
1549 /************************************************************************
1550  * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1551  *
1552  * See Windows documentation for more details on IUnknown methods.
1553  */
1554 static HRESULT WINAPI DefaultHandler_IRunnableObject_QueryInterface(
1555             IRunnableObject*     iface,
1556             REFIID               riid,
1557             void**               ppvObject)
1558 {
1559   _ICOM_THIS_From_IRunnableObject(DefaultHandler, iface);
1560
1561   return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject);  
1562 }
1563
1564 /************************************************************************
1565  * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1566  *
1567  * See Windows documentation for more details on IUnknown methods.
1568  */
1569 static ULONG WINAPI DefaultHandler_IRunnableObject_AddRef( 
1570             IRunnableObject*     iface)
1571 {
1572   _ICOM_THIS_From_IRunnableObject(DefaultHandler, iface);
1573
1574   return IUnknown_AddRef(this->outerUnknown);
1575 }
1576
1577 /************************************************************************
1578  * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1579  *
1580  * See Windows documentation for more details on IUnknown methods.
1581  */
1582 static ULONG WINAPI DefaultHandler_IRunnableObject_Release( 
1583             IRunnableObject*     iface)
1584 {
1585   _ICOM_THIS_From_IRunnableObject(DefaultHandler, iface);
1586
1587   return IUnknown_Release(this->outerUnknown);
1588 }
1589
1590 /************************************************************************
1591  * DefaultHandler_GetRunningClass (IRunnableObject)
1592  *
1593  * According to Brockscmidt, Chapter 19, the default handler's 
1594  * implementation of IRunnableobject does nothing until the object
1595  * is actually running.
1596  *
1597  * See Windows documentation for more details on IRunnableObject methods.
1598  */
1599 static HRESULT WINAPI DefaultHandler_GetRunningClass( 
1600             IRunnableObject*     iface,   
1601             LPCLSID              lpClsid)
1602 {
1603   TRACE("()\n");
1604   return S_OK;
1605 }
1606
1607 static HRESULT WINAPI DefaultHandler_Run( 
1608             IRunnableObject*     iface,
1609             IBindCtx*            pbc)
1610 {
1611   FIXME(": Stub\n");
1612   return E_NOTIMPL;
1613 }
1614
1615 /************************************************************************
1616  * DefaultHandler_IsRunning (IRunnableObject)
1617  *
1618  * According to Brockscmidt, Chapter 19, the default handler's 
1619  * implementation of IRunnableobject does nothing until the object
1620  * is actually running.
1621  *
1622  * See Windows documentation for more details on IRunnableObject methods.
1623  */
1624 static BOOL    WINAPI DefaultHandler_IsRunning( 
1625             IRunnableObject*     iface)
1626 {
1627   TRACE("()\n");
1628   return S_FALSE;
1629 }
1630
1631 /************************************************************************
1632  * DefaultHandler_LockRunning (IRunnableObject)
1633  *
1634  * According to Brockscmidt, Chapter 19, the default handler's 
1635  * implementation of IRunnableobject does nothing until the object
1636  * is actually running.
1637  *
1638  * See Windows documentation for more details on IRunnableObject methods.
1639  */
1640 static HRESULT WINAPI DefaultHandler_LockRunning( 
1641             IRunnableObject*     iface, 
1642             BOOL                 fLock, 
1643             BOOL                 fLastUnlockCloses)
1644 {
1645   TRACE("()\n");
1646   return S_OK;
1647 }
1648
1649 /************************************************************************
1650  * DefaultHandler_SetContainedObject (IRunnableObject)
1651  *
1652  * According to Brockscmidt, Chapter 19, the default handler's 
1653  * implementation of IRunnableobject does nothing until the object
1654  * is actually running.
1655  *
1656  * See Windows documentation for more details on IRunnableObject methods.
1657  */
1658 static HRESULT WINAPI DefaultHandler_SetContainedObject( 
1659             IRunnableObject*     iface, 
1660             BOOL                 fContained)
1661 {
1662   TRACE("()\n");
1663   return S_OK;
1664 }
1665