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