- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
[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
387   TRACE("(%s, %p, %s, %p)\n", debugstr_guid(clsid), pUnkOuter, debugstr_guid(riid), ppvObj);
388
389   /*
390    * Sanity check
391    */
392   if (ppvObj==0)
393     return E_POINTER;
394
395   *ppvObj = 0;
396
397   /*
398    * If this handler is constructed for aggregation, make sure
399    * the caller is requesting the IUnknown interface.
400    * This is necessary because it's the only time the non-delegating
401    * IUnknown pointer can be returned to the outside.
402    */
403   if ( (pUnkOuter!=NULL) && 
404        (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) != 0) )
405     return CLASS_E_NOAGGREGATION;
406
407   /*
408    * Try to construct a new instance of the class.
409    */
410   newHandler = DefaultHandler_Construct(clsid, 
411                                         pUnkOuter);
412
413   if (newHandler == 0)
414     return E_OUTOFMEMORY;
415
416   /*
417    * Make sure it supports the interface required by the caller.
418    */
419   hr = IUnknown_QueryInterface((IUnknown*)&(newHandler->lpvtbl2), riid, ppvObj);
420
421   /*
422    * Release the reference obtained in the constructor. If
423    * the QueryInterface was unsuccessful, it will free the class.
424    */
425   IUnknown_Release((IUnknown*)&(newHandler->lpvtbl2));
426
427   return hr;
428 }
429
430 /*********************************************************
431  * Methods implementation for the DefaultHandler class.
432  */
433 static DefaultHandler* DefaultHandler_Construct(
434   REFCLSID  clsid,
435   LPUNKNOWN pUnkOuter)
436 {
437   DefaultHandler* newObject = 0;
438
439   /*
440    * Allocate space for the object.
441    */
442   newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(DefaultHandler));
443
444   if (newObject==0)
445     return newObject;
446   
447   /*
448    * Initialize the virtual function table.
449    */
450   newObject->lpvtbl1 = &DefaultHandler_IOleObject_VTable;
451   newObject->lpvtbl2 = &DefaultHandler_NDIUnknown_VTable;
452   newObject->lpvtbl3 = &DefaultHandler_IDataObject_VTable;
453   newObject->lpvtbl4 = &DefaultHandler_IRunnableObject_VTable;
454
455   /*
456    * Start with one reference count. The caller of this function 
457    * must release the interface pointer when it is done.
458    */
459   newObject->ref = 1;
460
461   /*
462    * Initialize the outer unknown
463    * We don't keep a reference on the outer unknown since, the way 
464    * aggregation works, our lifetime is at least as large as it's
465    * lifetime.
466    */
467   if (pUnkOuter==NULL)
468     pUnkOuter = (IUnknown*)&(newObject->lpvtbl2);
469
470   newObject->outerUnknown = pUnkOuter;
471
472   /*
473    * Create a datacache object.
474    * We aggregate with the datacache. Make sure we pass our outer
475    * unknown as the datacache's outer unknown. 
476    */
477   CreateDataCache(newObject->outerUnknown,
478                   clsid,
479                   &IID_IUnknown,
480                   (void**)&newObject->dataCache);
481
482   /*
483    * Initialize the other data members of the class.
484    */
485   memcpy(&(newObject->clsid), clsid, sizeof(CLSID));
486   newObject->clientSite = NULL;
487   newObject->oleAdviseHolder = NULL;
488   newObject->dataAdviseHolder = NULL;
489   newObject->containerApp = NULL;
490   newObject->containerObj = NULL;
491
492   return newObject;
493 }
494
495 static void DefaultHandler_Destroy(
496   DefaultHandler* ptrToDestroy)
497 {
498   /*
499    * Free the strings idenfitying the object
500    */
501   if (ptrToDestroy->containerApp!=NULL)
502   {
503     SysFreeString(ptrToDestroy->containerApp);
504     ptrToDestroy->containerApp = NULL;
505   }
506
507   if (ptrToDestroy->containerObj!=NULL)
508   {
509     SysFreeString(ptrToDestroy->containerObj);
510     ptrToDestroy->containerObj = NULL;
511   }
512   
513   /*
514    * Release our reference to the data cache.
515    */
516   if (ptrToDestroy->dataCache!=NULL)
517   {
518     IUnknown_Release(ptrToDestroy->dataCache);
519     ptrToDestroy->dataCache = NULL;
520   }
521
522   /*
523    * Same thing for the client site.
524    */
525   if (ptrToDestroy->clientSite!=NULL)
526   {
527     IOleClientSite_Release(ptrToDestroy->clientSite);
528     ptrToDestroy->clientSite = NULL;
529   }
530
531   /*
532    * And the advise holder.
533    */
534   if (ptrToDestroy->oleAdviseHolder!=NULL)
535   {
536     IOleClientSite_Release(ptrToDestroy->oleAdviseHolder);
537     ptrToDestroy->oleAdviseHolder = NULL;
538   }
539
540   /*
541    * And the data advise holder.
542    */
543   if (ptrToDestroy->dataAdviseHolder!=NULL)
544   {
545     IOleClientSite_Release(ptrToDestroy->dataAdviseHolder);
546     ptrToDestroy->dataAdviseHolder = NULL;
547   }
548
549
550   /*
551    * Free the actual default handler structure.
552    */
553   HeapFree(GetProcessHeap(), 0, ptrToDestroy);
554 }
555
556 /*********************************************************
557  * Method implementation for the  non delegating IUnknown
558  * part of the DefaultHandler class.
559  */
560
561 /************************************************************************
562  * DefaultHandler_NDIUnknown_QueryInterface (IUnknown)
563  *
564  * See Windows documentation for more details on IUnknown methods.
565  *
566  * This version of QueryInterface will not delegate it's implementation
567  * to the outer unknown.
568  */
569 static HRESULT WINAPI DefaultHandler_NDIUnknown_QueryInterface(
570             IUnknown*      iface,
571             REFIID         riid,
572             void**         ppvObject)
573 {
574   _ICOM_THIS_From_NDIUnknown(DefaultHandler, iface);
575
576   /*
577    * Perform a sanity check on the parameters.
578    */
579   if ( (this==0) || (ppvObject==0) )
580     return E_INVALIDARG;
581   
582   /*
583    * Initialize the return parameter.
584    */
585   *ppvObject = 0;
586
587   /*
588    * Compare the riid with the interface IDs implemented by this object.
589    */
590   if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0) 
591   {
592     *ppvObject = iface;
593   }
594   else if (memcmp(&IID_IOleObject, riid, sizeof(IID_IOleObject)) == 0) 
595   {
596     *ppvObject = (IOleObject*)&(this->lpvtbl1);
597   }
598   else if (memcmp(&IID_IDataObject, riid, sizeof(IID_IDataObject)) == 0) 
599   {
600     *ppvObject = (IDataObject*)&(this->lpvtbl3);
601   }
602   else if (memcmp(&IID_IRunnableObject, riid, sizeof(IID_IRunnableObject)) == 0) 
603   {
604     *ppvObject = (IRunnableObject*)&(this->lpvtbl4);
605   }
606   else
607   {
608     /*
609      * Blind aggregate the data cache to "inherit" it's interfaces.
610      */
611     IUnknown_QueryInterface(this->dataCache, riid, ppvObject);
612   }
613   
614   /*
615    * Check that we obtained an interface.
616    */
617   if ((*ppvObject)==0)
618   {
619     WARN( "() : asking for un supported interface %s\n", debugstr_guid(riid));
620     return E_NOINTERFACE;
621   }
622   
623   /*
624    * Query Interface always increases the reference count by one when it is
625    * successful. 
626    */
627   IUnknown_AddRef((IUnknown*)*ppvObject);
628
629   return S_OK;;  
630 }
631
632 /************************************************************************
633  * DefaultHandler_NDIUnknown_AddRef (IUnknown)
634  *
635  * See Windows documentation for more details on IUnknown methods.
636  *
637  * This version of QueryInterface will not delegate it's implementation
638  * to the outer unknown.
639  */
640 static ULONG WINAPI DefaultHandler_NDIUnknown_AddRef( 
641             IUnknown*      iface)
642 {
643   _ICOM_THIS_From_NDIUnknown(DefaultHandler, iface);
644
645   this->ref++;
646
647   return this->ref;
648 }
649
650 /************************************************************************
651  * DefaultHandler_NDIUnknown_Release (IUnknown)
652  *
653  * See Windows documentation for more details on IUnknown methods.
654  *
655  * This version of QueryInterface will not delegate it's implementation
656  * to the outer unknown.
657  */
658 static ULONG WINAPI DefaultHandler_NDIUnknown_Release( 
659             IUnknown*      iface)
660 {
661   _ICOM_THIS_From_NDIUnknown(DefaultHandler, iface);
662
663   /*
664    * Decrease the reference count on this object.
665    */
666   this->ref--;
667
668   /*
669    * If the reference count goes down to 0, perform suicide.
670    */
671   if (this->ref==0)
672   {
673     DefaultHandler_Destroy(this);
674
675     return 0;
676   }
677   
678   return this->ref;
679 }
680
681 /*********************************************************
682  * Methods implementation for the IOleObject part of
683  * the DefaultHandler class.
684  */
685
686 /************************************************************************
687  * DefaultHandler_QueryInterface (IUnknown)
688  *
689  * See Windows documentation for more details on IUnknown methods.
690  */
691 static HRESULT WINAPI DefaultHandler_QueryInterface(
692             IOleObject*      iface,
693             REFIID           riid,
694             void**           ppvObject)
695 {
696   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
697
698   return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject);  
699 }
700
701 /************************************************************************
702  * DefaultHandler_AddRef (IUnknown)
703  *
704  * See Windows documentation for more details on IUnknown methods.
705  */
706 static ULONG WINAPI DefaultHandler_AddRef( 
707             IOleObject*        iface)
708 {
709   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
710
711   return IUnknown_AddRef(this->outerUnknown);
712 }
713
714 /************************************************************************
715  * DefaultHandler_Release (IUnknown)
716  *
717  * See Windows documentation for more details on IUnknown methods.
718  */
719 static ULONG WINAPI DefaultHandler_Release( 
720             IOleObject*        iface)
721 {
722   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
723
724   return IUnknown_Release(this->outerUnknown);
725 }
726
727 /************************************************************************
728  * DefaultHandler_SetClientSite (IOleObject)
729  *
730  * The default handler's implementation of this method only keeps the
731  * client site pointer for future reference.
732  *
733  * See Windows documentation for more details on IOleObject methods.
734  */
735 static HRESULT WINAPI DefaultHandler_SetClientSite(
736             IOleObject*        iface,
737             IOleClientSite*    pClientSite)
738 {
739   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
740
741   TRACE("(%p, %p)\n", iface, pClientSite);
742
743   /*
744    * Make sure we release the previous client site if there
745    * was one.
746    */
747   if (this->clientSite!=NULL)
748   {
749     IOleClientSite_Release(this->clientSite);
750   }
751
752   this->clientSite = pClientSite;
753
754   if (this->clientSite!=NULL)
755   {
756     IOleClientSite_AddRef(this->clientSite);
757   }
758
759   return S_OK;
760 }
761
762 /************************************************************************
763  * DefaultHandler_GetClientSite (IOleObject)
764  *
765  * The default handler's implementation of this method returns the
766  * last pointer set in IOleObject_SetClientSite.
767  *
768  * See Windows documentation for more details on IOleObject methods.
769  */
770 static HRESULT WINAPI DefaultHandler_GetClientSite(
771             IOleObject*        iface,
772             IOleClientSite**   ppClientSite)
773 {
774   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
775
776   /*
777    * Sanity check.
778    */
779   if (ppClientSite == NULL)
780     return E_POINTER;
781
782   *ppClientSite = this->clientSite;
783
784   if (*ppClientSite!=NULL)
785   {
786     IOleClientSite_Release(*ppClientSite);
787   }
788
789   return S_OK;
790 }
791
792 /************************************************************************
793  * DefaultHandler_SetHostNames (IOleObject)
794  *
795  * The default handler's implementation of this method just stores
796  * the strings and returns S_OK.
797  *
798  * See Windows documentation for more details on IOleObject methods.
799  */
800 static HRESULT WINAPI DefaultHandler_SetHostNames(
801             IOleObject*        iface,
802             LPCOLESTR          szContainerApp, 
803             LPCOLESTR          szContainerObj)
804 {
805   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
806
807   TRACE("(%p, %s, %s)\n",
808         iface,
809         debugstr_w(szContainerApp), 
810         debugstr_w(szContainerObj));
811
812   /*
813    * Be sure to cleanup before re-assinging the strings.
814    */ 
815   if (this->containerApp!=NULL)
816   {
817     SysFreeString(this->containerApp);
818     this->containerApp = NULL;
819   }
820
821   if (this->containerObj!=NULL)
822   {
823     SysFreeString(this->containerObj);
824     this->containerObj = NULL;
825   }
826
827   /*
828    * Copy the string supplied.
829    */
830   if (szContainerApp != NULL)
831     this->containerApp = SysAllocString(szContainerApp);
832
833   if (szContainerObj != NULL)
834     this->containerObj = SysAllocString(szContainerObj);
835  
836   return S_OK;
837 }
838
839 /************************************************************************
840  * DefaultHandler_Close (IOleObject)
841  *
842  * The default handler's implementation of this method is meaningless
843  * without a running server so it does nothing.
844  *
845  * See Windows documentation for more details on IOleObject methods.
846  */
847 static HRESULT WINAPI DefaultHandler_Close(
848             IOleObject*        iface, 
849             DWORD              dwSaveOption)
850 {
851   TRACE("()\n");
852   return S_OK;
853 }
854
855 /************************************************************************
856  * DefaultHandler_SetMoniker (IOleObject)
857  *
858  * The default handler's implementation of this method does nothing.
859  *
860  * See Windows documentation for more details on IOleObject methods.
861  */
862 static HRESULT WINAPI DefaultHandler_SetMoniker(
863             IOleObject*        iface, 
864             DWORD              dwWhichMoniker,
865             IMoniker*          pmk)
866 {
867   TRACE("(%p, %ld, %p)\n",
868         iface, 
869         dwWhichMoniker, 
870         pmk);
871
872   return S_OK;
873 }
874
875 /************************************************************************
876  * DefaultHandler_GetMoniker (IOleObject)
877  *
878  * Delegate this request to the client site if we have one.
879  *
880  * See Windows documentation for more details on IOleObject methods.
881  */
882 static HRESULT WINAPI DefaultHandler_GetMoniker(
883             IOleObject*        iface,
884             DWORD              dwAssign,
885             DWORD              dwWhichMoniker,
886             IMoniker**         ppmk)
887 {
888   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
889
890   TRACE("(%p, %ld, %ld, %p)\n",
891         iface, dwAssign, dwWhichMoniker, ppmk);
892
893   if (this->clientSite)
894   {
895     return IOleClientSite_GetMoniker(this->clientSite,
896                                      dwAssign,
897                                      dwWhichMoniker,
898                                      ppmk);
899                               
900   }
901
902   return E_UNSPEC;
903 }
904
905 /************************************************************************
906  * DefaultHandler_InitFromData (IOleObject)
907  *
908  * This method is meaningless if the server is not running
909  * 
910  * See Windows documentation for more details on IOleObject methods.
911  */
912 static HRESULT WINAPI DefaultHandler_InitFromData(
913             IOleObject*        iface, 
914             IDataObject*       pDataObject, 
915             BOOL               fCreation,
916             DWORD              dwReserved)
917 {
918   TRACE("(%p, %p, %d, %ld)\n",
919         iface, pDataObject, fCreation, dwReserved);
920
921   return OLE_E_NOTRUNNING;
922 }
923
924 /************************************************************************
925  * DefaultHandler_GetClipboardData (IOleObject)
926  *
927  * This method is meaningless if the server is not running
928  * 
929  * See Windows documentation for more details on IOleObject methods.
930  */
931 static HRESULT WINAPI DefaultHandler_GetClipboardData(
932             IOleObject*        iface, 
933             DWORD              dwReserved, 
934             IDataObject**      ppDataObject)
935 {
936   TRACE("(%p, %ld, %p)\n",
937         iface, dwReserved, ppDataObject);
938
939   return OLE_E_NOTRUNNING;
940 }
941
942 static HRESULT WINAPI DefaultHandler_DoVerb(
943             IOleObject*        iface, 
944             LONG               iVerb, 
945             struct tagMSG*     lpmsg, 
946             IOleClientSite*    pActiveSite, 
947             LONG               lindex, 
948             HWND               hwndParent, 
949             LPCRECT            lprcPosRect)
950 {
951   FIXME(": Stub\n");
952   return E_NOTIMPL;
953 }
954
955 /************************************************************************
956  * DefaultHandler_EnumVerbs (IOleObject)
957  *
958  * The default handler implementation of this method simply delegates
959  * to OleRegEnumVerbs
960  * 
961  * See Windows documentation for more details on IOleObject methods.
962  */
963 static HRESULT WINAPI DefaultHandler_EnumVerbs(
964             IOleObject*        iface, 
965             IEnumOLEVERB**     ppEnumOleVerb)
966 {
967   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
968
969   TRACE("(%p, %p)\n", iface, ppEnumOleVerb);
970
971   return OleRegEnumVerbs(&this->clsid, ppEnumOleVerb);
972 }
973
974 static HRESULT WINAPI DefaultHandler_Update(
975             IOleObject*        iface)
976 {
977   FIXME(": Stub\n");
978   return E_NOTIMPL;
979 }
980
981 /************************************************************************
982  * DefaultHandler_IsUpToDate (IOleObject)
983  *
984  * This method is meaningless if the server is not running
985  * 
986  * See Windows documentation for more details on IOleObject methods.
987  */
988 static HRESULT WINAPI DefaultHandler_IsUpToDate(
989             IOleObject*        iface)
990 {
991   TRACE("(%p)\n", iface);
992
993   return OLE_E_NOTRUNNING;
994 }
995
996 /************************************************************************
997  * DefaultHandler_GetUserClassID (IOleObject)
998  *
999  * TODO: Map to a new class ID if emulation is active.
1000  * 
1001  * See Windows documentation for more details on IOleObject methods.
1002  */
1003 static HRESULT WINAPI DefaultHandler_GetUserClassID(
1004             IOleObject*        iface, 
1005             CLSID*             pClsid)
1006 {
1007   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
1008
1009   TRACE("(%p, %p)\n", iface, pClsid);
1010
1011   /*
1012    * Sanity check.
1013    */
1014   if (pClsid==NULL)
1015     return E_POINTER;
1016
1017   memcpy(pClsid, &this->clsid, sizeof(CLSID));
1018
1019   return S_OK;
1020 }
1021
1022 /************************************************************************
1023  * DefaultHandler_GetUserType (IOleObject)
1024  *
1025  * The default handler implementation of this method simply delegates
1026  * to OleRegGetUserType
1027  * 
1028  * See Windows documentation for more details on IOleObject methods.
1029  */
1030 static HRESULT WINAPI DefaultHandler_GetUserType(
1031             IOleObject*        iface, 
1032             DWORD              dwFormOfType, 
1033             LPOLESTR*          pszUserType)
1034 {
1035   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
1036
1037   TRACE("(%p, %ld, %p)\n", iface, dwFormOfType, pszUserType);
1038
1039   return OleRegGetUserType(&this->clsid, dwFormOfType, pszUserType);
1040 }
1041
1042 /************************************************************************
1043  * DefaultHandler_SetExtent (IOleObject)
1044  *
1045  * This method is meaningless if the server is not running
1046  *
1047  * See Windows documentation for more details on IOleObject methods.
1048  */
1049 static HRESULT WINAPI DefaultHandler_SetExtent(
1050             IOleObject*        iface, 
1051             DWORD              dwDrawAspect, 
1052             SIZEL*             psizel)
1053 {
1054   TRACE("(%p, %lx, (%d,%d))\n", iface, dwDrawAspect, psizel->cx, psizel->cy);
1055   return OLE_E_NOTRUNNING;
1056 }
1057
1058 /************************************************************************
1059  * DefaultHandler_GetExtent (IOleObject)
1060  *
1061  * The default handler's implementation of this method returns uses
1062  * the cache to locate the aspect and extract the extent from it.
1063  *
1064  * See Windows documentation for more details on IOleObject methods.
1065  */
1066 static HRESULT WINAPI DefaultHandler_GetExtent(
1067             IOleObject*        iface, 
1068             DWORD              dwDrawAspect, 
1069             SIZEL*             psizel)
1070 {
1071   DVTARGETDEVICE* targetDevice;
1072   IViewObject2*   cacheView = NULL;
1073   HRESULT         hres;
1074
1075   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);  
1076
1077   TRACE("(%p, %lx, %p)\n", iface, dwDrawAspect, psizel);
1078
1079   hres = IUnknown_QueryInterface(this->dataCache, &IID_IViewObject2, (void**)&cacheView);
1080
1081   if (FAILED(hres))
1082     return E_UNEXPECTED;
1083
1084   /*
1085    * Prepare the call to the cache's GetExtent method.
1086    *
1087    * Here we would build a valid DVTARGETDEVICE structure
1088    * but, since we are calling into the data cache, we 
1089    * know it's implementation and we'll skip this 
1090    * extra work until later.
1091    */
1092   targetDevice = NULL;
1093
1094   hres = IViewObject2_GetExtent(cacheView,
1095                                 dwDrawAspect,
1096                                 -1,
1097                                 targetDevice,
1098                                 psizel);
1099
1100   /*
1101    * Cleanup
1102    */
1103   IViewObject2_Release(cacheView);
1104
1105   return hres;
1106 }
1107
1108 /************************************************************************
1109  * DefaultHandler_Advise (IOleObject)
1110  *
1111  * The default handler's implementation of this method simply
1112  * delegates to the OleAdviseHolder.
1113  *
1114  * See Windows documentation for more details on IOleObject methods.
1115  */
1116 static HRESULT WINAPI DefaultHandler_Advise(
1117             IOleObject*        iface, 
1118             IAdviseSink*       pAdvSink, 
1119             DWORD*             pdwConnection)
1120 {
1121   HRESULT hres = S_OK;
1122   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);  
1123
1124   TRACE("(%p, %p, %p)\n", iface, pAdvSink, pdwConnection);
1125
1126   /*
1127    * Make sure we have an advise holder before we start.
1128    */
1129   if (this->oleAdviseHolder==NULL)
1130   {
1131     hres = CreateOleAdviseHolder(&this->oleAdviseHolder);
1132   }
1133
1134   if (SUCCEEDED(hres))
1135   {
1136     hres = IOleAdviseHolder_Advise(this->oleAdviseHolder, 
1137                                    pAdvSink, 
1138                                    pdwConnection);
1139   }
1140
1141   return hres;
1142 }
1143
1144 /************************************************************************
1145  * DefaultHandler_Unadvise (IOleObject)
1146  *
1147  * The default handler's implementation of this method simply
1148  * delegates to the OleAdviseHolder.
1149  *
1150  * See Windows documentation for more details on IOleObject methods.
1151  */
1152 static HRESULT WINAPI DefaultHandler_Unadvise(
1153             IOleObject*        iface, 
1154             DWORD              dwConnection)
1155 {
1156   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);  
1157
1158   TRACE("(%p, %ld)\n", iface, dwConnection);
1159
1160   /*
1161    * If we don't have an advise holder yet, it means we don't have
1162    * a connection.
1163    */
1164   if (this->oleAdviseHolder==NULL)
1165     return OLE_E_NOCONNECTION;
1166
1167   return IOleAdviseHolder_Unadvise(this->oleAdviseHolder,
1168                                    dwConnection);
1169 }
1170
1171 /************************************************************************
1172  * DefaultHandler_EnumAdvise (IOleObject)
1173  *
1174  * The default handler's implementation of this method simply
1175  * delegates to the OleAdviseHolder.
1176  *
1177  * See Windows documentation for more details on IOleObject methods.
1178  */
1179 static HRESULT WINAPI DefaultHandler_EnumAdvise(
1180             IOleObject*        iface, 
1181             IEnumSTATDATA**    ppenumAdvise)
1182 {
1183   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);  
1184
1185   TRACE("(%p, %p)\n", iface, ppenumAdvise);
1186
1187   /*
1188    * Sanity check
1189    */
1190   if (ppenumAdvise==NULL)
1191     return E_POINTER;
1192
1193   /*
1194    * Initialize the out parameter.
1195    */
1196   *ppenumAdvise = NULL;
1197
1198   if (this->oleAdviseHolder==NULL)
1199     return IOleAdviseHolder_EnumAdvise(this->oleAdviseHolder,
1200                                        ppenumAdvise);
1201
1202   return S_OK;
1203 }
1204
1205 /************************************************************************
1206  * DefaultHandler_GetMiscStatus (IOleObject)
1207  *
1208  * The default handler's implementation of this method simply delegates
1209  * to OleRegGetMiscStatus.
1210  *
1211  * See Windows documentation for more details on IOleObject methods.
1212  */
1213 static HRESULT WINAPI DefaultHandler_GetMiscStatus(
1214             IOleObject*        iface, 
1215             DWORD              dwAspect, 
1216             DWORD*             pdwStatus)
1217 {
1218   HRESULT hres;
1219   _ICOM_THIS_From_IOleObject(DefaultHandler, iface);
1220
1221   TRACE("(%p, %lx, %p)\n", iface, dwAspect, pdwStatus);
1222
1223   hres = OleRegGetMiscStatus(&(this->clsid), dwAspect, pdwStatus);
1224
1225   if (FAILED(hres))
1226     *pdwStatus = 0;
1227
1228   return S_OK;
1229 }
1230
1231 /************************************************************************
1232  * DefaultHandler_SetExtent (IOleObject)
1233  *
1234  * This method is meaningless if the server is not running
1235  *
1236  * See Windows documentation for more details on IOleObject methods.
1237  */
1238 static HRESULT WINAPI DefaultHandler_SetColorScheme(
1239             IOleObject*           iface,
1240             struct tagLOGPALETTE* pLogpal)
1241 {
1242   TRACE("(%p, %p))\n", iface, pLogpal);
1243   return OLE_E_NOTRUNNING;
1244 }
1245
1246 /*********************************************************
1247  * Methods implementation for the IDataObject part of
1248  * the DefaultHandler class.
1249  */
1250
1251 /************************************************************************
1252  * DefaultHandler_IDataObject_QueryInterface (IUnknown)
1253  *
1254  * See Windows documentation for more details on IUnknown methods.
1255  */
1256 static HRESULT WINAPI DefaultHandler_IDataObject_QueryInterface(
1257             IDataObject*     iface, 
1258            REFIID           riid,
1259             void**           ppvObject)
1260 {
1261   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);
1262
1263   return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject);  
1264 }
1265
1266 /************************************************************************
1267  * DefaultHandler_IDataObject_AddRef (IUnknown)
1268  *
1269  * See Windows documentation for more details on IUnknown methods.
1270  */
1271 static ULONG WINAPI DefaultHandler_IDataObject_AddRef( 
1272             IDataObject*     iface)
1273 {
1274   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);
1275
1276   return IUnknown_AddRef(this->outerUnknown);  
1277 }
1278
1279 /************************************************************************
1280  * DefaultHandler_IDataObject_Release (IUnknown)
1281  *
1282  * See Windows documentation for more details on IUnknown methods.
1283  */
1284 static ULONG WINAPI DefaultHandler_IDataObject_Release( 
1285             IDataObject*     iface)
1286 {
1287   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);
1288
1289   return IUnknown_Release(this->outerUnknown);  
1290 }
1291
1292 static HRESULT WINAPI DefaultHandler_GetData(
1293             IDataObject*     iface,
1294             LPFORMATETC      pformatetcIn, 
1295             STGMEDIUM*       pmedium)
1296 {
1297   FIXME(": Stub\n");
1298   return E_NOTIMPL;
1299 }
1300
1301 static HRESULT WINAPI DefaultHandler_GetDataHere(
1302             IDataObject*     iface, 
1303             LPFORMATETC      pformatetc,
1304             STGMEDIUM*       pmedium)
1305 {
1306   FIXME(": Stub\n");
1307   return E_NOTIMPL;
1308 }
1309
1310 /************************************************************************
1311  * DefaultHandler_QueryGetData (IDataObject)
1312  *
1313  * The default handler's implementation of this method delegates to 
1314  * the cache.
1315  *
1316  * See Windows documentation for more details on IDataObject methods.
1317  */
1318 static HRESULT WINAPI DefaultHandler_QueryGetData(
1319             IDataObject*     iface,
1320             LPFORMATETC      pformatetc)
1321 {
1322   IDataObject* cacheDataObject = NULL;
1323   HRESULT      hres;
1324
1325   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);
1326
1327   TRACE("(%p, %p)\n", iface, pformatetc);
1328
1329   hres = IUnknown_QueryInterface(this->dataCache, 
1330                                  &IID_IDataObject,
1331                                  (void**)&cacheDataObject);
1332
1333   if (FAILED(hres))
1334     return E_UNEXPECTED;
1335
1336   hres = IDataObject_QueryGetData(cacheDataObject,
1337                                   pformatetc);
1338
1339   IDataObject_Release(cacheDataObject);
1340   
1341   return hres;
1342 }
1343
1344 /************************************************************************
1345  * DefaultHandler_GetCanonicalFormatEtc (IDataObject)
1346  *
1347  * This method is meaningless if the server is not running
1348  *
1349  * See Windows documentation for more details on IDataObject methods.
1350  */
1351 static HRESULT WINAPI DefaultHandler_GetCanonicalFormatEtc(
1352             IDataObject*     iface, 
1353             LPFORMATETC      pformatectIn, 
1354             LPFORMATETC      pformatetcOut)
1355 {
1356   FIXME("(%p, %p, %p)\n", iface, pformatectIn, pformatetcOut);
1357
1358   return OLE_E_NOTRUNNING;
1359 }
1360
1361 /************************************************************************
1362  * DefaultHandler_SetData (IDataObject)
1363  *
1364  * The default handler's implementation of this method delegates to 
1365  * the cache.
1366  *
1367  * See Windows documentation for more details on IDataObject methods.
1368  */
1369 static HRESULT WINAPI DefaultHandler_SetData(
1370             IDataObject*     iface,
1371             LPFORMATETC      pformatetc, 
1372             STGMEDIUM*       pmedium, 
1373             BOOL             fRelease)
1374 {
1375   IDataObject* cacheDataObject = NULL;
1376   HRESULT      hres;
1377
1378   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);
1379
1380   TRACE("(%p, %p, %p, %d)\n", iface, pformatetc, pmedium, fRelease);
1381
1382   hres = IUnknown_QueryInterface(this->dataCache, 
1383                                  &IID_IDataObject,
1384                                  (void**)&cacheDataObject);
1385
1386   if (FAILED(hres))
1387     return E_UNEXPECTED;
1388
1389   hres = IDataObject_SetData(cacheDataObject,
1390                              pformatetc,
1391                              pmedium,
1392                              fRelease);
1393   
1394   IDataObject_Release(cacheDataObject);
1395   
1396   return hres;
1397 }
1398
1399 /************************************************************************
1400  * DefaultHandler_EnumFormatEtc (IDataObject)
1401  *
1402  * The default handler's implementation of this method simply delegates
1403  * to OleRegEnumFormatEtc.
1404  *
1405  * See Windows documentation for more details on IDataObject methods.
1406  */
1407 static HRESULT WINAPI DefaultHandler_EnumFormatEtc(
1408             IDataObject*     iface,       
1409             DWORD            dwDirection,
1410             IEnumFORMATETC** ppenumFormatEtc)
1411 {
1412   HRESULT hres;
1413   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);
1414
1415   TRACE("(%p, %lx, %p)\n", iface, dwDirection, ppenumFormatEtc);
1416
1417   hres = OleRegEnumFormatEtc(&(this->clsid), dwDirection, ppenumFormatEtc);
1418
1419   return hres;
1420 }
1421
1422 /************************************************************************
1423  * DefaultHandler_DAdvise (IDataObject)
1424  *
1425  * The default handler's implementation of this method simply
1426  * delegates to the DataAdviseHolder.
1427  *
1428  * See Windows documentation for more details on IDataObject methods.
1429  */
1430 static HRESULT WINAPI DefaultHandler_DAdvise(
1431             IDataObject*     iface, 
1432             FORMATETC*       pformatetc, 
1433             DWORD            advf, 
1434             IAdviseSink*     pAdvSink, 
1435             DWORD*           pdwConnection)
1436 {
1437   HRESULT hres = S_OK;
1438   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);  
1439
1440   TRACE("(%p, %p, %ld, %p, %p)\n", 
1441         iface, pformatetc, advf, pAdvSink, pdwConnection);
1442
1443   /*
1444    * Make sure we have a data advise holder before we start.
1445    */
1446   if (this->dataAdviseHolder==NULL)
1447   {
1448     hres = CreateDataAdviseHolder(&this->dataAdviseHolder);
1449   }
1450
1451   if (SUCCEEDED(hres))
1452   {
1453     hres = IDataAdviseHolder_Advise(this->dataAdviseHolder, 
1454                                     iface,
1455                                     pformatetc, 
1456                                     advf, 
1457                                     pAdvSink, 
1458                                     pdwConnection);
1459   }
1460
1461   return hres;
1462 }
1463
1464 /************************************************************************
1465  * DefaultHandler_DUnadvise (IDataObject)
1466  *
1467  * The default handler's implementation of this method simply
1468  * delegates to the DataAdviseHolder.
1469  *
1470  * See Windows documentation for more details on IDataObject methods.
1471  */
1472 static HRESULT WINAPI DefaultHandler_DUnadvise(
1473             IDataObject*     iface,
1474             DWORD            dwConnection)
1475 {
1476   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);  
1477
1478   TRACE("(%p, %ld)\n", iface, dwConnection);
1479
1480   /*
1481    * If we don't have a data advise holder yet, it means that
1482    * we don't have any connections..
1483    */
1484   if (this->dataAdviseHolder==NULL)
1485   {
1486     return OLE_E_NOCONNECTION;
1487   }
1488
1489   return IDataAdviseHolder_Unadvise(this->dataAdviseHolder, 
1490                                     dwConnection);
1491 }
1492
1493 /************************************************************************
1494  * DefaultHandler_EnumDAdvise (IDataObject)
1495  *
1496  * The default handler's implementation of this method simply
1497  * delegates to the DataAdviseHolder.
1498  *
1499  * See Windows documentation for more details on IDataObject methods.
1500  */
1501 static HRESULT WINAPI DefaultHandler_EnumDAdvise(
1502             IDataObject*     iface,
1503             IEnumSTATDATA**  ppenumAdvise)
1504 {
1505   _ICOM_THIS_From_IDataObject(DefaultHandler, iface);  
1506
1507   TRACE("(%p, %p)\n", iface, ppenumAdvise);
1508
1509   /*
1510    * Sanity check
1511    */
1512   if (ppenumAdvise == NULL)
1513     return E_POINTER;
1514
1515   /*
1516    * Initialize the out parameter.
1517    */
1518   *ppenumAdvise = NULL;
1519
1520   /*
1521    * If we have a data advise holder object, delegate.
1522    */
1523   if (this->dataAdviseHolder!=NULL)
1524   {
1525     return IDataAdviseHolder_EnumAdvise(this->dataAdviseHolder, 
1526                                         ppenumAdvise);
1527   }
1528
1529   return S_OK;
1530 }
1531
1532 /*********************************************************
1533  * Methods implementation for the IRunnableObject part 
1534  * of the DefaultHandler class.
1535  */
1536
1537 /************************************************************************
1538  * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1539  *
1540  * See Windows documentation for more details on IUnknown methods.
1541  */
1542 static HRESULT WINAPI DefaultHandler_IRunnableObject_QueryInterface(
1543             IRunnableObject*     iface,
1544             REFIID               riid,
1545             void**               ppvObject)
1546 {
1547   _ICOM_THIS_From_IRunnableObject(DefaultHandler, iface);
1548
1549   return IUnknown_QueryInterface(this->outerUnknown, riid, ppvObject);  
1550 }
1551
1552 /************************************************************************
1553  * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1554  *
1555  * See Windows documentation for more details on IUnknown methods.
1556  */
1557 static ULONG WINAPI DefaultHandler_IRunnableObject_AddRef( 
1558             IRunnableObject*     iface)
1559 {
1560   _ICOM_THIS_From_IRunnableObject(DefaultHandler, iface);
1561
1562   return IUnknown_AddRef(this->outerUnknown);
1563 }
1564
1565 /************************************************************************
1566  * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1567  *
1568  * See Windows documentation for more details on IUnknown methods.
1569  */
1570 static ULONG WINAPI DefaultHandler_IRunnableObject_Release( 
1571             IRunnableObject*     iface)
1572 {
1573   _ICOM_THIS_From_IRunnableObject(DefaultHandler, iface);
1574
1575   return IUnknown_Release(this->outerUnknown);
1576 }
1577
1578 /************************************************************************
1579  * DefaultHandler_GetRunningClass (IRunnableObject)
1580  *
1581  * According to Brockscmidt, Chapter 19, the default handler's 
1582  * implementation of IRunnableobject does nothing until the object
1583  * is actually running.
1584  *
1585  * See Windows documentation for more details on IRunnableObject methods.
1586  */
1587 static HRESULT WINAPI DefaultHandler_GetRunningClass( 
1588             IRunnableObject*     iface,   
1589             LPCLSID              lpClsid)
1590 {
1591   TRACE("()\n");
1592   return S_OK;
1593 }
1594
1595 static HRESULT WINAPI DefaultHandler_Run( 
1596             IRunnableObject*     iface,
1597             IBindCtx*            pbc)
1598 {
1599   FIXME(": Stub\n");
1600   return E_NOTIMPL;
1601 }
1602
1603 /************************************************************************
1604  * DefaultHandler_IsRunning (IRunnableObject)
1605  *
1606  * According to Brockscmidt, Chapter 19, the default handler's 
1607  * implementation of IRunnableobject does nothing until the object
1608  * is actually running.
1609  *
1610  * See Windows documentation for more details on IRunnableObject methods.
1611  */
1612 static BOOL    WINAPI DefaultHandler_IsRunning( 
1613             IRunnableObject*     iface)
1614 {
1615   TRACE("()\n");
1616   return S_FALSE;
1617 }
1618
1619 /************************************************************************
1620  * DefaultHandler_LockRunning (IRunnableObject)
1621  *
1622  * According to Brockscmidt, Chapter 19, the default handler's 
1623  * implementation of IRunnableobject does nothing until the object
1624  * is actually running.
1625  *
1626  * See Windows documentation for more details on IRunnableObject methods.
1627  */
1628 static HRESULT WINAPI DefaultHandler_LockRunning( 
1629             IRunnableObject*     iface, 
1630             BOOL                 fLock, 
1631             BOOL                 fLastUnlockCloses)
1632 {
1633   TRACE("()\n");
1634   return S_OK;
1635 }
1636
1637 /************************************************************************
1638  * DefaultHandler_SetContainedObject (IRunnableObject)
1639  *
1640  * According to Brockscmidt, Chapter 19, the default handler's 
1641  * implementation of IRunnableobject does nothing until the object
1642  * is actually running.
1643  *
1644  * See Windows documentation for more details on IRunnableObject methods.
1645  */
1646 static HRESULT WINAPI DefaultHandler_SetContainedObject( 
1647             IRunnableObject*     iface, 
1648             BOOL                 fContained)
1649 {
1650   TRACE("()\n");
1651   return S_OK;
1652 }
1653