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