2 * OLE 2 default object handler
4 * Copyright 1999 Francis Beaudet
5 * Copyright 2000 Abey George
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
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.
27 * All the implementation details are taken from: Inside OLE
28 * second edition by Kraig Brockschmidt,
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
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
41 * - Some functions still return E_NOTIMPL they have to be
42 * implemented. Most of those are related to the running of the
45 * - All the methods related to notification and advise sinks are
46 * in place but no notifications are sent to the sinks yet.
60 #include "compobj_private.h"
62 #include "wine/unicode.h"
63 #include "wine/debug.h"
65 WINE_DEFAULT_DEBUG_CHANNEL(ole);
69 storage_state_uninitialised,
70 storage_state_initialised,
74 /****************************************************************************
80 const IOleObjectVtbl* lpVtbl;
81 const IUnknownVtbl* lpvtblIUnknown;
82 const IDataObjectVtbl* lpvtblIDataObject;
83 const IRunnableObjectVtbl* lpvtblIRunnableObject;
84 const IAdviseSinkVtbl *lpvtblIAdviseSink;
85 const IPersistStorageVtbl *lpvtblIPersistStorage;
87 /* Reference count of this object */
90 /* IUnknown implementation of the outer object. */
91 IUnknown* outerUnknown;
93 /* Class Id that this handler object represents. */
96 /* IUnknown implementation of the datacache. */
98 /* IPersistStorage implementation of the datacache. */
99 IPersistStorage* dataCache_PersistStg;
101 /* Client site for the embedded object. */
102 IOleClientSite* clientSite;
105 * The IOleAdviseHolder maintains the connections
106 * on behalf of the default handler.
108 IOleAdviseHolder* oleAdviseHolder;
111 * The IDataAdviseHolder maintains the data
112 * connections on behalf of the default handler.
114 IDataAdviseHolder* dataAdviseHolder;
116 /* Name of the container and object contained */
120 /* IOleObject delegate */
121 IOleObject *pOleDelegate;
122 /* IPersistStorage delegate */
123 IPersistStorage *pPSDelegate;
124 /* IDataObject delegate */
125 IDataObject *pDataDelegate;
127 /* connection cookie for the advise on the delegate OLE object */
130 /* storage passed to Load or InitNew */
132 enum storage_state storage_state;
135 typedef struct DefaultHandler DefaultHandler;
137 static inline DefaultHandler *impl_from_IOleObject( IOleObject *iface )
139 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpVtbl));
142 static inline DefaultHandler *impl_from_NDIUnknown( IUnknown *iface )
144 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIUnknown));
147 static inline DefaultHandler *impl_from_IDataObject( IDataObject *iface )
149 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIDataObject));
152 static inline DefaultHandler *impl_from_IRunnableObject( IRunnableObject *iface )
154 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIRunnableObject));
157 static inline DefaultHandler *impl_from_IAdviseSink( IAdviseSink *iface )
159 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIAdviseSink));
162 static inline DefaultHandler *impl_from_IPersistStorage( IPersistStorage *iface )
164 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIPersistStorage));
167 static void DefaultHandler_Destroy(DefaultHandler* This);
169 static inline BOOL object_is_running(DefaultHandler *This)
171 return IRunnableObject_IsRunning((IRunnableObject*)&This->lpvtblIRunnableObject);
174 /*********************************************************
175 * Method implementation for the non delegating IUnknown
176 * part of the DefaultHandler class.
179 /************************************************************************
180 * DefaultHandler_NDIUnknown_QueryInterface (IUnknown)
182 * See Windows documentation for more details on IUnknown methods.
184 * This version of QueryInterface will not delegate its implementation
185 * to the outer unknown.
187 static HRESULT WINAPI DefaultHandler_NDIUnknown_QueryInterface(
192 DefaultHandler *This = impl_from_NDIUnknown(iface);
199 if (IsEqualIID(&IID_IUnknown, riid))
201 else if (IsEqualIID(&IID_IOleObject, riid))
202 *ppvObject = (IOleObject*)&This->lpVtbl;
203 else if (IsEqualIID(&IID_IDataObject, riid))
204 *ppvObject = (IDataObject*)&This->lpvtblIDataObject;
205 else if (IsEqualIID(&IID_IRunnableObject, riid))
206 *ppvObject = (IRunnableObject*)&This->lpvtblIRunnableObject;
207 else if (IsEqualIID(&IID_IPersist, riid) ||
208 IsEqualIID(&IID_IPersistStorage, riid))
209 *ppvObject = &This->lpvtblIPersistStorage;
210 else if (IsEqualIID(&IID_IViewObject, riid) ||
211 IsEqualIID(&IID_IViewObject2, riid) ||
212 IsEqualIID(&IID_IOleCache, riid) ||
213 IsEqualIID(&IID_IOleCache2, riid))
215 HRESULT hr = IUnknown_QueryInterface(This->dataCache, riid, ppvObject);
216 if (FAILED(hr)) FIXME("interface %s not implemented by data cache\n", debugstr_guid(riid));
220 /* Check that we obtained an interface. */
221 if (*ppvObject == NULL)
223 WARN( "() : asking for un supported interface %s\n", debugstr_guid(riid));
224 return E_NOINTERFACE;
228 * Query Interface always increases the reference count by one when it is
231 IUnknown_AddRef((IUnknown*)*ppvObject);
236 /************************************************************************
237 * DefaultHandler_NDIUnknown_AddRef (IUnknown)
239 * See Windows documentation for more details on IUnknown methods.
241 * This version of QueryInterface will not delegate its implementation
242 * to the outer unknown.
244 static ULONG WINAPI DefaultHandler_NDIUnknown_AddRef(
247 DefaultHandler *This = impl_from_NDIUnknown(iface);
248 return InterlockedIncrement(&This->ref);
251 /************************************************************************
252 * DefaultHandler_NDIUnknown_Release (IUnknown)
254 * See Windows documentation for more details on IUnknown methods.
256 * This version of QueryInterface will not delegate its implementation
257 * to the outer unknown.
259 static ULONG WINAPI DefaultHandler_NDIUnknown_Release(
262 DefaultHandler *This = impl_from_NDIUnknown(iface);
265 ref = InterlockedDecrement(&This->ref);
267 if (!ref) DefaultHandler_Destroy(This);
272 /*********************************************************
273 * Methods implementation for the IOleObject part of
274 * the DefaultHandler class.
277 /************************************************************************
278 * DefaultHandler_QueryInterface (IUnknown)
280 * See Windows documentation for more details on IUnknown methods.
282 static HRESULT WINAPI DefaultHandler_QueryInterface(
287 DefaultHandler *This = impl_from_IOleObject(iface);
289 return IUnknown_QueryInterface(This->outerUnknown, riid, ppvObject);
292 /************************************************************************
293 * DefaultHandler_AddRef (IUnknown)
295 * See Windows documentation for more details on IUnknown methods.
297 static ULONG WINAPI DefaultHandler_AddRef(
300 DefaultHandler *This = impl_from_IOleObject(iface);
302 return IUnknown_AddRef(This->outerUnknown);
305 /************************************************************************
306 * DefaultHandler_Release (IUnknown)
308 * See Windows documentation for more details on IUnknown methods.
310 static ULONG WINAPI DefaultHandler_Release(
313 DefaultHandler *This = impl_from_IOleObject(iface);
315 return IUnknown_Release(This->outerUnknown);
318 /************************************************************************
319 * DefaultHandler_SetClientSite (IOleObject)
321 * The default handler's implementation of this method only keeps the
322 * client site pointer for future reference.
324 * See Windows documentation for more details on IOleObject methods.
326 static HRESULT WINAPI DefaultHandler_SetClientSite(
328 IOleClientSite* pClientSite)
330 DefaultHandler *This = impl_from_IOleObject(iface);
333 TRACE("(%p, %p)\n", iface, pClientSite);
335 if (object_is_running(This))
336 hr = IOleObject_SetClientSite(This->pOleDelegate, pClientSite);
339 * Make sure we release the previous client site if there
342 if (This->clientSite)
343 IOleClientSite_Release(This->clientSite);
345 This->clientSite = pClientSite;
347 if (This->clientSite)
348 IOleClientSite_AddRef(This->clientSite);
353 /************************************************************************
354 * DefaultHandler_GetClientSite (IOleObject)
356 * The default handler's implementation of this method returns the
357 * last pointer set in IOleObject_SetClientSite.
359 * See Windows documentation for more details on IOleObject methods.
361 static HRESULT WINAPI DefaultHandler_GetClientSite(
363 IOleClientSite** ppClientSite)
365 DefaultHandler *This = impl_from_IOleObject(iface);
370 *ppClientSite = This->clientSite;
372 if (This->clientSite)
373 IOleClientSite_AddRef(This->clientSite);
378 /************************************************************************
379 * DefaultHandler_SetHostNames (IOleObject)
381 * The default handler's implementation of this method just stores
382 * the strings and returns S_OK.
384 * See Windows documentation for more details on IOleObject methods.
386 static HRESULT WINAPI DefaultHandler_SetHostNames(
388 LPCOLESTR szContainerApp,
389 LPCOLESTR szContainerObj)
391 DefaultHandler *This = impl_from_IOleObject(iface);
393 TRACE("(%p, %s, %s)\n",
395 debugstr_w(szContainerApp),
396 debugstr_w(szContainerObj));
398 if (object_is_running(This))
399 IOleObject_SetHostNames(This->pOleDelegate, szContainerApp, szContainerObj);
401 /* Be sure to cleanup before re-assigning the strings. */
402 HeapFree( GetProcessHeap(), 0, This->containerApp );
403 This->containerApp = NULL;
404 HeapFree( GetProcessHeap(), 0, This->containerObj );
405 This->containerObj = NULL;
409 if ((This->containerApp = HeapAlloc( GetProcessHeap(), 0,
410 (lstrlenW(szContainerApp) + 1) * sizeof(WCHAR) )))
411 strcpyW( This->containerApp, szContainerApp );
416 if ((This->containerObj = HeapAlloc( GetProcessHeap(), 0,
417 (lstrlenW(szContainerObj) + 1) * sizeof(WCHAR) )))
418 strcpyW( This->containerObj, szContainerObj );
423 /* undoes the work done by DefaultHandler_Run */
424 static void DefaultHandler_Stop(DefaultHandler *This)
426 if (!object_is_running(This))
429 IOleObject_Unadvise(This->pOleDelegate, This->dwAdvConn);
431 /* FIXME: call IOleCache_OnStop */
433 if (This->dataAdviseHolder)
434 DataAdviseHolder_OnDisconnect(This->dataAdviseHolder);
435 if (This->pDataDelegate)
437 IDataObject_Release(This->pDataDelegate);
438 This->pDataDelegate = NULL;
440 if (This->pPSDelegate)
442 IPersistStorage_Release(This->pPSDelegate);
443 This->pPSDelegate = NULL;
445 IOleObject_Release(This->pOleDelegate);
446 This->pOleDelegate = NULL;
449 /************************************************************************
450 * DefaultHandler_Close (IOleObject)
452 * The default handler's implementation of this method is meaningless
453 * without a running server so it does nothing.
455 * See Windows documentation for more details on IOleObject methods.
457 static HRESULT WINAPI DefaultHandler_Close(
461 DefaultHandler *This = impl_from_IOleObject(iface);
464 TRACE("(%d)\n", dwSaveOption);
466 if (!object_is_running(This))
469 hr = IOleObject_Close(This->pOleDelegate, dwSaveOption);
471 DefaultHandler_Stop(This);
476 /************************************************************************
477 * DefaultHandler_SetMoniker (IOleObject)
479 * The default handler's implementation of this method does nothing.
481 * See Windows documentation for more details on IOleObject methods.
483 static HRESULT WINAPI DefaultHandler_SetMoniker(
485 DWORD dwWhichMoniker,
488 DefaultHandler *This = impl_from_IOleObject(iface);
490 TRACE("(%p, %d, %p)\n",
495 if (object_is_running(This))
496 return IOleObject_SetMoniker(This->pOleDelegate, dwWhichMoniker, pmk);
501 /************************************************************************
502 * DefaultHandler_GetMoniker (IOleObject)
504 * Delegate this request to the client site if we have one.
506 * See Windows documentation for more details on IOleObject methods.
508 static HRESULT WINAPI DefaultHandler_GetMoniker(
511 DWORD dwWhichMoniker,
514 DefaultHandler *This = impl_from_IOleObject(iface);
516 TRACE("(%p, %d, %d, %p)\n",
517 iface, dwAssign, dwWhichMoniker, ppmk);
519 if (object_is_running(This))
520 return IOleObject_GetMoniker(This->pOleDelegate, dwAssign, dwWhichMoniker,
523 /* FIXME: dwWhichMoniker == OLEWHICHMK_CONTAINER only? */
524 if (This->clientSite)
526 return IOleClientSite_GetMoniker(This->clientSite,
536 /************************************************************************
537 * DefaultHandler_InitFromData (IOleObject)
539 * This method is meaningless if the server is not running
541 * See Windows documentation for more details on IOleObject methods.
543 static HRESULT WINAPI DefaultHandler_InitFromData(
545 IDataObject* pDataObject,
549 DefaultHandler *This = impl_from_IOleObject(iface);
551 TRACE("(%p, %p, %d, %d)\n",
552 iface, pDataObject, fCreation, dwReserved);
554 if (object_is_running(This))
555 return IOleObject_InitFromData(This->pOleDelegate, pDataObject, fCreation,
557 return OLE_E_NOTRUNNING;
560 /************************************************************************
561 * DefaultHandler_GetClipboardData (IOleObject)
563 * This method is meaningless if the server is not running
565 * See Windows documentation for more details on IOleObject methods.
567 static HRESULT WINAPI DefaultHandler_GetClipboardData(
570 IDataObject** ppDataObject)
572 DefaultHandler *This = impl_from_IOleObject(iface);
574 TRACE("(%p, %d, %p)\n",
575 iface, dwReserved, ppDataObject);
577 if (object_is_running(This))
578 return IOleObject_GetClipboardData(This->pOleDelegate, dwReserved,
581 return OLE_E_NOTRUNNING;
584 static HRESULT WINAPI DefaultHandler_DoVerb(
587 struct tagMSG* lpmsg,
588 IOleClientSite* pActiveSite,
593 DefaultHandler *This = impl_from_IOleObject(iface);
594 IRunnableObject *pRunnableObj = (IRunnableObject *)&This->lpvtblIRunnableObject;
597 TRACE("(%d, %p, %p, %d, %p, %s)\n", iVerb, lpmsg, pActiveSite, lindex, hwndParent, wine_dbgstr_rect(lprcPosRect));
599 hr = IRunnableObject_Run(pRunnableObj, NULL);
600 if (FAILED(hr)) return hr;
602 return IOleObject_DoVerb(This->pOleDelegate, iVerb, lpmsg, pActiveSite,
603 lindex, hwndParent, lprcPosRect);
606 /************************************************************************
607 * DefaultHandler_EnumVerbs (IOleObject)
609 * The default handler implementation of this method simply delegates
612 * See Windows documentation for more details on IOleObject methods.
614 static HRESULT WINAPI DefaultHandler_EnumVerbs(
616 IEnumOLEVERB** ppEnumOleVerb)
618 DefaultHandler *This = impl_from_IOleObject(iface);
619 HRESULT hr = OLE_S_USEREG;
621 TRACE("(%p, %p)\n", iface, ppEnumOleVerb);
623 if (object_is_running(This))
624 hr = IOleObject_EnumVerbs(This->pOleDelegate, ppEnumOleVerb);
626 if (hr == OLE_S_USEREG)
627 return OleRegEnumVerbs(&This->clsid, ppEnumOleVerb);
632 static HRESULT WINAPI DefaultHandler_Update(
635 DefaultHandler *This = impl_from_IOleObject(iface);
636 TRACE("(%p)\n", iface);
638 if (!object_is_running(This))
640 FIXME("Should run object\n");
643 return IOleObject_Update(This->pOleDelegate);
646 /************************************************************************
647 * DefaultHandler_IsUpToDate (IOleObject)
649 * This method is meaningless if the server is not running
651 * See Windows documentation for more details on IOleObject methods.
653 static HRESULT WINAPI DefaultHandler_IsUpToDate(
656 DefaultHandler *This = impl_from_IOleObject(iface);
657 TRACE("(%p)\n", iface);
659 if (object_is_running(This))
660 return IOleObject_IsUpToDate(This->pOleDelegate);
662 return OLE_E_NOTRUNNING;
665 /************************************************************************
666 * DefaultHandler_GetUserClassID (IOleObject)
668 * TODO: Map to a new class ID if emulation is active.
670 * See Windows documentation for more details on IOleObject methods.
672 static HRESULT WINAPI DefaultHandler_GetUserClassID(
676 DefaultHandler *This = impl_from_IOleObject(iface);
678 TRACE("(%p, %p)\n", iface, pClsid);
680 if (object_is_running(This))
681 return IOleObject_GetUserClassID(This->pOleDelegate, pClsid);
686 *pClsid = This->clsid;
691 /************************************************************************
692 * DefaultHandler_GetUserType (IOleObject)
694 * The default handler implementation of this method simply delegates
695 * to OleRegGetUserType
697 * See Windows documentation for more details on IOleObject methods.
699 static HRESULT WINAPI DefaultHandler_GetUserType(
702 LPOLESTR* pszUserType)
704 DefaultHandler *This = impl_from_IOleObject(iface);
706 TRACE("(%p, %d, %p)\n", iface, dwFormOfType, pszUserType);
707 if (object_is_running(This))
708 return IOleObject_GetUserType(This->pOleDelegate, dwFormOfType, pszUserType);
710 return OleRegGetUserType(&This->clsid, dwFormOfType, pszUserType);
713 /************************************************************************
714 * DefaultHandler_SetExtent (IOleObject)
716 * This method is meaningless if the server is not running
718 * See Windows documentation for more details on IOleObject methods.
720 static HRESULT WINAPI DefaultHandler_SetExtent(
725 DefaultHandler *This = impl_from_IOleObject(iface);
727 TRACE("(%p, %x, (%d x %d))\n", iface,
728 dwDrawAspect, psizel->cx, psizel->cy);
730 if (object_is_running(This))
731 return IOleObject_SetExtent(This->pOleDelegate, dwDrawAspect, psizel);
733 return OLE_E_NOTRUNNING;
736 /************************************************************************
737 * DefaultHandler_GetExtent (IOleObject)
739 * The default handler's implementation of this method returns uses
740 * the cache to locate the aspect and extract the extent from it.
742 * See Windows documentation for more details on IOleObject methods.
744 static HRESULT WINAPI DefaultHandler_GetExtent(
749 DVTARGETDEVICE* targetDevice;
750 IViewObject2* cacheView = NULL;
753 DefaultHandler *This = impl_from_IOleObject(iface);
755 TRACE("(%p, %x, %p)\n", iface, dwDrawAspect, psizel);
757 if (object_is_running(This))
758 return IOleObject_GetExtent(This->pOleDelegate, dwDrawAspect, psizel);
760 hres = IUnknown_QueryInterface(This->dataCache, &IID_IViewObject2, (void**)&cacheView);
765 * Prepare the call to the cache's GetExtent method.
767 * Here we would build a valid DVTARGETDEVICE structure
768 * but, since we are calling into the data cache, we
769 * know its implementation and we'll skip this
770 * extra work until later.
774 hres = IViewObject2_GetExtent(cacheView,
780 IViewObject2_Release(cacheView);
785 /************************************************************************
786 * DefaultHandler_Advise (IOleObject)
788 * The default handler's implementation of this method simply
789 * delegates to the OleAdviseHolder.
791 * See Windows documentation for more details on IOleObject methods.
793 static HRESULT WINAPI DefaultHandler_Advise(
795 IAdviseSink* pAdvSink,
796 DWORD* pdwConnection)
799 DefaultHandler *This = impl_from_IOleObject(iface);
801 TRACE("(%p, %p, %p)\n", iface, pAdvSink, pdwConnection);
803 /* Make sure we have an advise holder before we start. */
804 if (!This->oleAdviseHolder)
805 hres = CreateOleAdviseHolder(&This->oleAdviseHolder);
808 hres = IOleAdviseHolder_Advise(This->oleAdviseHolder,
815 /************************************************************************
816 * DefaultHandler_Unadvise (IOleObject)
818 * The default handler's implementation of this method simply
819 * delegates to the OleAdviseHolder.
821 * See Windows documentation for more details on IOleObject methods.
823 static HRESULT WINAPI DefaultHandler_Unadvise(
827 DefaultHandler *This = impl_from_IOleObject(iface);
829 TRACE("(%p, %d)\n", iface, dwConnection);
832 * If we don't have an advise holder yet, it means we don't have
835 if (!This->oleAdviseHolder)
836 return OLE_E_NOCONNECTION;
838 return IOleAdviseHolder_Unadvise(This->oleAdviseHolder,
842 /************************************************************************
843 * DefaultHandler_EnumAdvise (IOleObject)
845 * The default handler's implementation of this method simply
846 * delegates to the OleAdviseHolder.
848 * See Windows documentation for more details on IOleObject methods.
850 static HRESULT WINAPI DefaultHandler_EnumAdvise(
852 IEnumSTATDATA** ppenumAdvise)
854 DefaultHandler *This = impl_from_IOleObject(iface);
856 TRACE("(%p, %p)\n", iface, ppenumAdvise);
861 *ppenumAdvise = NULL;
863 if (!This->oleAdviseHolder)
866 return IOleAdviseHolder_EnumAdvise(This->oleAdviseHolder, ppenumAdvise);
869 /************************************************************************
870 * DefaultHandler_GetMiscStatus (IOleObject)
872 * The default handler's implementation of this method simply delegates
873 * to OleRegGetMiscStatus.
875 * See Windows documentation for more details on IOleObject methods.
877 static HRESULT WINAPI DefaultHandler_GetMiscStatus(
883 DefaultHandler *This = impl_from_IOleObject(iface);
885 TRACE("(%p, %x, %p)\n", iface, dwAspect, pdwStatus);
887 if (object_is_running(This))
888 return IOleObject_GetMiscStatus(This->pOleDelegate, dwAspect, pdwStatus);
890 hres = OleRegGetMiscStatus(&This->clsid, dwAspect, pdwStatus);
898 /************************************************************************
899 * DefaultHandler_SetColorScheme (IOleObject)
901 * This method is meaningless if the server is not running
903 * See Windows documentation for more details on IOleObject methods.
905 static HRESULT WINAPI DefaultHandler_SetColorScheme(
907 struct tagLOGPALETTE* pLogpal)
909 DefaultHandler *This = impl_from_IOleObject(iface);
911 TRACE("(%p, %p))\n", iface, pLogpal);
913 if (object_is_running(This))
914 return IOleObject_SetColorScheme(This->pOleDelegate, pLogpal);
916 return OLE_E_NOTRUNNING;
919 /*********************************************************
920 * Methods implementation for the IDataObject part of
921 * the DefaultHandler class.
924 /************************************************************************
925 * DefaultHandler_IDataObject_QueryInterface (IUnknown)
927 * See Windows documentation for more details on IUnknown methods.
929 static HRESULT WINAPI DefaultHandler_IDataObject_QueryInterface(
934 DefaultHandler *This = impl_from_IDataObject(iface);
936 return IUnknown_QueryInterface(This->outerUnknown, riid, ppvObject);
939 /************************************************************************
940 * DefaultHandler_IDataObject_AddRef (IUnknown)
942 * See Windows documentation for more details on IUnknown methods.
944 static ULONG WINAPI DefaultHandler_IDataObject_AddRef(
947 DefaultHandler *This = impl_from_IDataObject(iface);
949 return IUnknown_AddRef(This->outerUnknown);
952 /************************************************************************
953 * DefaultHandler_IDataObject_Release (IUnknown)
955 * See Windows documentation for more details on IUnknown methods.
957 static ULONG WINAPI DefaultHandler_IDataObject_Release(
960 DefaultHandler *This = impl_from_IDataObject(iface);
962 return IUnknown_Release(This->outerUnknown);
965 /************************************************************************
966 * DefaultHandler_GetData
968 * Get Data from a source dataobject using format pformatetcIn->cfFormat
969 * See Windows documentation for more details on GetData.
970 * Default handler's implementation of this method delegates to the cache.
972 static HRESULT WINAPI DefaultHandler_GetData(
974 LPFORMATETC pformatetcIn,
977 IDataObject* cacheDataObject = NULL;
980 DefaultHandler *This = impl_from_IDataObject(iface);
982 TRACE("(%p, %p, %p)\n", iface, pformatetcIn, pmedium);
984 hres = IUnknown_QueryInterface(This->dataCache,
986 (void**)&cacheDataObject);
991 hres = IDataObject_GetData(cacheDataObject,
995 IDataObject_Release(cacheDataObject);
997 if (FAILED(hres) && This->pDataDelegate)
998 hres = IDataObject_GetData(This->pDataDelegate, pformatetcIn, pmedium);
1003 static HRESULT WINAPI DefaultHandler_GetDataHere(
1005 LPFORMATETC pformatetc,
1012 /************************************************************************
1013 * DefaultHandler_QueryGetData (IDataObject)
1015 * The default handler's implementation of this method delegates to
1018 * See Windows documentation for more details on IDataObject methods.
1020 static HRESULT WINAPI DefaultHandler_QueryGetData(
1022 LPFORMATETC pformatetc)
1024 IDataObject* cacheDataObject = NULL;
1027 DefaultHandler *This = impl_from_IDataObject(iface);
1029 TRACE("(%p, %p)\n", iface, pformatetc);
1031 hres = IUnknown_QueryInterface(This->dataCache,
1033 (void**)&cacheDataObject);
1036 return E_UNEXPECTED;
1038 hres = IDataObject_QueryGetData(cacheDataObject,
1041 IDataObject_Release(cacheDataObject);
1043 if (FAILED(hres) && This->pDataDelegate)
1044 hres = IDataObject_QueryGetData(This->pDataDelegate, pformatetc);
1049 /************************************************************************
1050 * DefaultHandler_GetCanonicalFormatEtc (IDataObject)
1052 * This method is meaningless if the server is not running
1054 * See Windows documentation for more details on IDataObject methods.
1056 static HRESULT WINAPI DefaultHandler_GetCanonicalFormatEtc(
1058 LPFORMATETC pformatetcIn,
1059 LPFORMATETC pformatetcOut)
1061 DefaultHandler *This = impl_from_IDataObject(iface);
1063 TRACE("(%p, %p, %p)\n", iface, pformatetcIn, pformatetcOut);
1065 if (!This->pDataDelegate)
1066 return OLE_E_NOTRUNNING;
1068 return IDataObject_GetCanonicalFormatEtc(This->pDataDelegate, pformatetcIn, pformatetcOut);
1071 /************************************************************************
1072 * DefaultHandler_SetData (IDataObject)
1074 * The default handler's implementation of this method delegates to
1077 * See Windows documentation for more details on IDataObject methods.
1079 static HRESULT WINAPI DefaultHandler_SetData(
1081 LPFORMATETC pformatetc,
1085 DefaultHandler *This = impl_from_IDataObject(iface);
1086 IDataObject* cacheDataObject = NULL;
1089 TRACE("(%p, %p, %p, %d)\n", iface, pformatetc, pmedium, fRelease);
1091 hres = IUnknown_QueryInterface(This->dataCache,
1093 (void**)&cacheDataObject);
1096 return E_UNEXPECTED;
1098 hres = IDataObject_SetData(cacheDataObject,
1103 IDataObject_Release(cacheDataObject);
1108 /************************************************************************
1109 * DefaultHandler_EnumFormatEtc (IDataObject)
1111 * The default handler's implementation of This method simply delegates
1112 * to OleRegEnumFormatEtc.
1114 * See Windows documentation for more details on IDataObject methods.
1116 static HRESULT WINAPI DefaultHandler_EnumFormatEtc(
1119 IEnumFORMATETC** ppenumFormatEtc)
1122 DefaultHandler *This = impl_from_IDataObject(iface);
1124 TRACE("(%p, %x, %p)\n", iface, dwDirection, ppenumFormatEtc);
1126 hres = OleRegEnumFormatEtc(&This->clsid, dwDirection, ppenumFormatEtc);
1131 /************************************************************************
1132 * DefaultHandler_DAdvise (IDataObject)
1134 * The default handler's implementation of this method simply
1135 * delegates to the DataAdviseHolder.
1137 * See Windows documentation for more details on IDataObject methods.
1139 static HRESULT WINAPI DefaultHandler_DAdvise(
1141 FORMATETC* pformatetc,
1143 IAdviseSink* pAdvSink,
1144 DWORD* pdwConnection)
1146 HRESULT hres = S_OK;
1147 DefaultHandler *This = impl_from_IDataObject(iface);
1149 TRACE("(%p, %p, %d, %p, %p)\n",
1150 iface, pformatetc, advf, pAdvSink, pdwConnection);
1152 /* Make sure we have a data advise holder before we start. */
1153 if (!This->dataAdviseHolder)
1155 hres = CreateDataAdviseHolder(&This->dataAdviseHolder);
1156 if (SUCCEEDED(hres) && This->pDataDelegate)
1157 DataAdviseHolder_OnConnect(This->dataAdviseHolder, This->pDataDelegate);
1160 if (SUCCEEDED(hres))
1161 hres = IDataAdviseHolder_Advise(This->dataAdviseHolder,
1171 /************************************************************************
1172 * DefaultHandler_DUnadvise (IDataObject)
1174 * The default handler's implementation of this method simply
1175 * delegates to the DataAdviseHolder.
1177 * See Windows documentation for more details on IDataObject methods.
1179 static HRESULT WINAPI DefaultHandler_DUnadvise(
1183 DefaultHandler *This = impl_from_IDataObject(iface);
1185 TRACE("(%p, %d)\n", iface, dwConnection);
1188 * If we don't have a data advise holder yet, it means that
1189 * we don't have any connections..
1191 if (!This->dataAdviseHolder)
1192 return OLE_E_NOCONNECTION;
1194 return IDataAdviseHolder_Unadvise(This->dataAdviseHolder,
1198 /************************************************************************
1199 * DefaultHandler_EnumDAdvise (IDataObject)
1201 * The default handler's implementation of this method simply
1202 * delegates to the DataAdviseHolder.
1204 * See Windows documentation for more details on IDataObject methods.
1206 static HRESULT WINAPI DefaultHandler_EnumDAdvise(
1208 IEnumSTATDATA** ppenumAdvise)
1210 DefaultHandler *This = impl_from_IDataObject(iface);
1212 TRACE("(%p, %p)\n", iface, ppenumAdvise);
1217 *ppenumAdvise = NULL;
1219 /* If we have a data advise holder object, delegate. */
1220 if (This->dataAdviseHolder)
1221 return IDataAdviseHolder_EnumAdvise(This->dataAdviseHolder,
1227 /*********************************************************
1228 * Methods implementation for the IRunnableObject part
1229 * of the DefaultHandler class.
1232 /************************************************************************
1233 * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1235 * See Windows documentation for more details on IUnknown methods.
1237 static HRESULT WINAPI DefaultHandler_IRunnableObject_QueryInterface(
1238 IRunnableObject* iface,
1242 DefaultHandler *This = impl_from_IRunnableObject(iface);
1244 return IUnknown_QueryInterface(This->outerUnknown, riid, ppvObject);
1247 /************************************************************************
1248 * DefaultHandler_IRunnableObject_AddRef (IUnknown)
1250 * See Windows documentation for more details on IUnknown methods.
1252 static ULONG WINAPI DefaultHandler_IRunnableObject_AddRef(
1253 IRunnableObject* iface)
1255 DefaultHandler *This = impl_from_IRunnableObject(iface);
1257 return IUnknown_AddRef(This->outerUnknown);
1260 /************************************************************************
1261 * DefaultHandler_IRunnableObject_Release (IUnknown)
1263 * See Windows documentation for more details on IUnknown methods.
1265 static ULONG WINAPI DefaultHandler_IRunnableObject_Release(
1266 IRunnableObject* iface)
1268 DefaultHandler *This = impl_from_IRunnableObject(iface);
1270 return IUnknown_Release(This->outerUnknown);
1273 /************************************************************************
1274 * DefaultHandler_GetRunningClass (IRunnableObject)
1276 * See Windows documentation for more details on IRunnableObject methods.
1278 static HRESULT WINAPI DefaultHandler_GetRunningClass(
1279 IRunnableObject* iface,
1286 static HRESULT WINAPI DefaultHandler_Run(
1287 IRunnableObject* iface,
1290 DefaultHandler *This = impl_from_IRunnableObject(iface);
1293 FIXME("(%p): semi-stub\n", pbc);
1295 /* already running? if so nothing to do */
1296 if (object_is_running(This))
1299 hr = CoCreateInstance(&This->clsid, NULL, CLSCTX_LOCAL_SERVER,
1300 &IID_IOleObject, (void **)&This->pOleDelegate);
1304 hr = IOleObject_Advise(This->pOleDelegate,
1305 (IAdviseSink *)&This->lpvtblIAdviseSink,
1308 if (SUCCEEDED(hr) && This->clientSite)
1309 hr = IOleObject_SetClientSite(This->pOleDelegate, This->clientSite);
1313 IOleObject_QueryInterface(This->pOleDelegate, &IID_IPersistStorage,
1314 (void **)&This->pPSDelegate);
1315 if (This->pPSDelegate)
1317 if(This->storage_state == storage_state_initialised)
1318 hr = IPersistStorage_InitNew(This->pPSDelegate, This->storage);
1319 else if(This->storage_state == storage_state_loaded)
1320 hr = IPersistStorage_Load(This->pPSDelegate, This->storage);
1324 if (SUCCEEDED(hr) && This->containerApp)
1325 hr = IOleObject_SetHostNames(This->pOleDelegate, This->containerApp,
1326 This->containerObj);
1328 /* FIXME: do more stuff here:
1329 * - IOleObject_GetMiscStatus
1330 * - IOleObject_GetMoniker
1335 hr = IOleObject_QueryInterface(This->pOleDelegate, &IID_IDataObject,
1336 (void **)&This->pDataDelegate);
1338 if (SUCCEEDED(hr) && This->dataAdviseHolder)
1339 hr = DataAdviseHolder_OnConnect(This->dataAdviseHolder, This->pDataDelegate);
1342 DefaultHandler_Stop(This);
1347 /************************************************************************
1348 * DefaultHandler_IsRunning (IRunnableObject)
1350 * See Windows documentation for more details on IRunnableObject methods.
1352 static BOOL WINAPI DefaultHandler_IsRunning(
1353 IRunnableObject* iface)
1355 DefaultHandler *This = impl_from_IRunnableObject(iface);
1359 if (This->pOleDelegate)
1365 /************************************************************************
1366 * DefaultHandler_LockRunning (IRunnableObject)
1368 * See Windows documentation for more details on IRunnableObject methods.
1370 static HRESULT WINAPI DefaultHandler_LockRunning(
1371 IRunnableObject* iface,
1373 BOOL fLastUnlockCloses)
1379 /************************************************************************
1380 * DefaultHandler_SetContainedObject (IRunnableObject)
1382 * See Windows documentation for more details on IRunnableObject methods.
1384 static HRESULT WINAPI DefaultHandler_SetContainedObject(
1385 IRunnableObject* iface,
1392 static HRESULT WINAPI DefaultHandler_IAdviseSink_QueryInterface(
1397 if (IsEqualIID(riid, &IID_IUnknown) ||
1398 IsEqualIID(riid, &IID_IAdviseSink))
1401 IAdviseSink_AddRef(iface);
1405 return E_NOINTERFACE;
1408 static ULONG WINAPI DefaultHandler_IAdviseSink_AddRef(
1411 DefaultHandler *This = impl_from_IAdviseSink(iface);
1413 return IUnknown_AddRef((IUnknown *)&This->lpvtblIUnknown);
1416 static ULONG WINAPI DefaultHandler_IAdviseSink_Release(
1419 DefaultHandler *This = impl_from_IAdviseSink(iface);
1421 return IUnknown_Release((IUnknown *)&This->lpvtblIUnknown);
1424 static void WINAPI DefaultHandler_IAdviseSink_OnDataChange(
1426 FORMATETC *pFormatetc,
1432 static void WINAPI DefaultHandler_IAdviseSink_OnViewChange(
1440 static void WINAPI DefaultHandler_IAdviseSink_OnRename(
1444 DefaultHandler *This = impl_from_IAdviseSink(iface);
1446 TRACE("(%p)\n", pmk);
1448 if (This->oleAdviseHolder)
1449 IOleAdviseHolder_SendOnRename(This->oleAdviseHolder, pmk);
1452 static void WINAPI DefaultHandler_IAdviseSink_OnSave(
1455 DefaultHandler *This = impl_from_IAdviseSink(iface);
1459 if (This->oleAdviseHolder)
1460 IOleAdviseHolder_SendOnSave(This->oleAdviseHolder);
1463 static void WINAPI DefaultHandler_IAdviseSink_OnClose(
1466 DefaultHandler *This = impl_from_IAdviseSink(iface);
1470 if (This->oleAdviseHolder)
1471 IOleAdviseHolder_SendOnClose(This->oleAdviseHolder);
1473 DefaultHandler_Stop(This);
1477 /************************************************************************
1478 * DefaultHandler_IPersistStorage_QueryInterface
1481 static HRESULT WINAPI DefaultHandler_IPersistStorage_QueryInterface(
1482 IPersistStorage* iface,
1486 DefaultHandler *This = impl_from_IPersistStorage(iface);
1488 return IUnknown_QueryInterface(This->outerUnknown, riid, ppvObject);
1491 /************************************************************************
1492 * DefaultHandler_IPersistStorage_AddRef
1495 static ULONG WINAPI DefaultHandler_IPersistStorage_AddRef(
1496 IPersistStorage* iface)
1498 DefaultHandler *This = impl_from_IPersistStorage(iface);
1500 return IUnknown_AddRef(This->outerUnknown);
1503 /************************************************************************
1504 * DefaultHandler_IPersistStorage_Release
1507 static ULONG WINAPI DefaultHandler_IPersistStorage_Release(
1508 IPersistStorage* iface)
1510 DefaultHandler *This = impl_from_IPersistStorage(iface);
1512 return IUnknown_Release(This->outerUnknown);
1515 /************************************************************************
1516 * DefaultHandler_IPersistStorage_GetClassID
1519 static HRESULT WINAPI DefaultHandler_IPersistStorage_GetClassID(
1520 IPersistStorage* iface,
1523 DefaultHandler *This = impl_from_IPersistStorage(iface);
1526 TRACE("(%p)->(%p)\n", iface, clsid);
1528 if(object_is_running(This))
1529 hr = IPersistStorage_GetClassID(This->pPSDelegate, clsid);
1531 hr = IPersistStorage_GetClassID(This->dataCache_PersistStg, clsid);
1536 /************************************************************************
1537 * DefaultHandler_IPersistStorage_IsDirty
1540 static HRESULT WINAPI DefaultHandler_IPersistStorage_IsDirty(
1541 IPersistStorage* iface)
1543 DefaultHandler *This = impl_from_IPersistStorage(iface);
1546 TRACE("(%p)\n", iface);
1548 hr = IPersistStorage_IsDirty(This->dataCache_PersistStg);
1549 if(hr != S_FALSE) return hr;
1551 if(object_is_running(This))
1552 hr = IPersistStorage_IsDirty(This->pPSDelegate);
1557 /***********************************************************************
1560 * Creates the '\1Ole' stream.
1561 * The format of this stream is as follows:
1563 * DWORD Version == 0x02000001
1564 * DWORD Flags - low bit set indicates the object is a link otherwise it's embedded.
1565 * DWORD LinkupdateOption - [MS-OLEDS describes this as an implementation specific hint
1566 * supplied by the app that creates the data structure. May be
1567 * ignored on processing].
1569 * DWORD Reserved == 0
1570 * DWORD MonikerStreamSize - size of the rest of the data (ie CLSID + moniker stream data).
1571 * CLSID clsid - class id of object capable of processing the moniker
1572 * BYTE data[] - moniker data for a link
1575 static const WCHAR OleStream[] = {1,'O','l','e',0};
1580 DWORD link_update_opt;
1583 } ole_stream_header_t;
1584 static const DWORD ole_stream_version = 0x02000001;
1586 static void init_ole_stream(IStorage *storage)
1591 hr = IStorage_CreateStream(storage, OleStream, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stream);
1595 ole_stream_header_t header;
1597 header.version = ole_stream_version;
1599 header.link_update_opt = 0;
1601 header.moniker_size = 0;
1603 IStream_Write(stream, &header, sizeof(header), &written);
1604 IStream_Release(stream);
1609 static HRESULT load_ole_stream(DefaultHandler *This, IStorage *storage)
1614 hr = IStorage_OpenStream(storage, OleStream, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stream);
1619 ole_stream_header_t header;
1621 hr = IStream_Read(stream, &header, sizeof(header), &read);
1622 if(hr == S_OK && read == sizeof(header) && header.version == ole_stream_version)
1624 if(header.flags & 1)
1626 /* FIXME: Read the moniker and deal with the link */
1627 FIXME("Linked objects are not supported yet\n");
1632 WARN("Incorrect OleStream header\n");
1633 hr = DV_E_CLIPFORMAT;
1635 IStream_Release(stream);
1639 init_ole_stream(storage);
1645 /************************************************************************
1646 * DefaultHandler_IPersistStorage_InitNew
1649 static HRESULT WINAPI DefaultHandler_IPersistStorage_InitNew(
1650 IPersistStorage* iface,
1653 DefaultHandler *This = impl_from_IPersistStorage(iface);
1656 TRACE("(%p)->(%p)\n", iface, pStg);
1657 init_ole_stream(pStg);
1659 hr = IPersistStorage_InitNew(This->dataCache_PersistStg, pStg);
1661 if(SUCCEEDED(hr) && object_is_running(This))
1662 hr = IPersistStorage_InitNew(This->pPSDelegate, pStg);
1666 IStorage_AddRef(pStg);
1667 This->storage = pStg;
1668 This->storage_state = storage_state_initialised;
1675 /************************************************************************
1676 * DefaultHandler_IPersistStorage_Load
1679 static HRESULT WINAPI DefaultHandler_IPersistStorage_Load(
1680 IPersistStorage* iface,
1683 DefaultHandler *This = impl_from_IPersistStorage(iface);
1686 TRACE("(%p)->(%p)\n", iface, pStg);
1688 hr = load_ole_stream(This, pStg);
1691 hr = IPersistStorage_Load(This->dataCache_PersistStg, pStg);
1693 if(SUCCEEDED(hr) && object_is_running(This))
1694 hr = IPersistStorage_Load(This->pPSDelegate, pStg);
1698 IStorage_AddRef(pStg);
1699 This->storage = pStg;
1700 This->storage_state = storage_state_loaded;
1706 /************************************************************************
1707 * DefaultHandler_IPersistStorage_Save
1710 static HRESULT WINAPI DefaultHandler_IPersistStorage_Save(
1711 IPersistStorage* iface,
1715 DefaultHandler *This = impl_from_IPersistStorage(iface);
1718 TRACE("(%p)->(%p, %d)\n", iface, pStgSave, fSameAsLoad);
1720 hr = IPersistStorage_Save(This->dataCache_PersistStg, pStgSave, fSameAsLoad);
1721 if(SUCCEEDED(hr) && object_is_running(This))
1722 hr = IPersistStorage_Save(This->pPSDelegate, pStgSave, fSameAsLoad);
1728 /************************************************************************
1729 * DefaultHandler_IPersistStorage_SaveCompleted
1732 static HRESULT WINAPI DefaultHandler_IPersistStorage_SaveCompleted(
1733 IPersistStorage* iface,
1736 DefaultHandler *This = impl_from_IPersistStorage(iface);
1739 TRACE("(%p)->(%p)\n", iface, pStgNew);
1741 hr = IPersistStorage_SaveCompleted(This->dataCache_PersistStg, pStgNew);
1743 if(SUCCEEDED(hr) && object_is_running(This))
1744 hr = IPersistStorage_SaveCompleted(This->pPSDelegate, pStgNew);
1748 IStorage_AddRef(pStgNew);
1749 if(This->storage) IStorage_Release(This->storage);
1750 This->storage = pStgNew;
1751 This->storage_state = storage_state_loaded;
1758 /************************************************************************
1759 * DefaultHandler_IPersistStorage_HandsOffStorage
1762 static HRESULT WINAPI DefaultHandler_IPersistStorage_HandsOffStorage(
1763 IPersistStorage* iface)
1765 DefaultHandler *This = impl_from_IPersistStorage(iface);
1768 TRACE("(%p)\n", iface);
1770 hr = IPersistStorage_HandsOffStorage(This->dataCache_PersistStg);
1772 if(SUCCEEDED(hr) && object_is_running(This))
1773 hr = IPersistStorage_HandsOffStorage(This->pPSDelegate);
1775 if(This->storage) IStorage_Release(This->storage);
1776 This->storage = NULL;
1777 This->storage_state = storage_state_uninitialised;
1784 * Virtual function tables for the DefaultHandler class.
1786 static const IOleObjectVtbl DefaultHandler_IOleObject_VTable =
1788 DefaultHandler_QueryInterface,
1789 DefaultHandler_AddRef,
1790 DefaultHandler_Release,
1791 DefaultHandler_SetClientSite,
1792 DefaultHandler_GetClientSite,
1793 DefaultHandler_SetHostNames,
1794 DefaultHandler_Close,
1795 DefaultHandler_SetMoniker,
1796 DefaultHandler_GetMoniker,
1797 DefaultHandler_InitFromData,
1798 DefaultHandler_GetClipboardData,
1799 DefaultHandler_DoVerb,
1800 DefaultHandler_EnumVerbs,
1801 DefaultHandler_Update,
1802 DefaultHandler_IsUpToDate,
1803 DefaultHandler_GetUserClassID,
1804 DefaultHandler_GetUserType,
1805 DefaultHandler_SetExtent,
1806 DefaultHandler_GetExtent,
1807 DefaultHandler_Advise,
1808 DefaultHandler_Unadvise,
1809 DefaultHandler_EnumAdvise,
1810 DefaultHandler_GetMiscStatus,
1811 DefaultHandler_SetColorScheme
1814 static const IUnknownVtbl DefaultHandler_NDIUnknown_VTable =
1816 DefaultHandler_NDIUnknown_QueryInterface,
1817 DefaultHandler_NDIUnknown_AddRef,
1818 DefaultHandler_NDIUnknown_Release,
1821 static const IDataObjectVtbl DefaultHandler_IDataObject_VTable =
1823 DefaultHandler_IDataObject_QueryInterface,
1824 DefaultHandler_IDataObject_AddRef,
1825 DefaultHandler_IDataObject_Release,
1826 DefaultHandler_GetData,
1827 DefaultHandler_GetDataHere,
1828 DefaultHandler_QueryGetData,
1829 DefaultHandler_GetCanonicalFormatEtc,
1830 DefaultHandler_SetData,
1831 DefaultHandler_EnumFormatEtc,
1832 DefaultHandler_DAdvise,
1833 DefaultHandler_DUnadvise,
1834 DefaultHandler_EnumDAdvise
1837 static const IRunnableObjectVtbl DefaultHandler_IRunnableObject_VTable =
1839 DefaultHandler_IRunnableObject_QueryInterface,
1840 DefaultHandler_IRunnableObject_AddRef,
1841 DefaultHandler_IRunnableObject_Release,
1842 DefaultHandler_GetRunningClass,
1844 DefaultHandler_IsRunning,
1845 DefaultHandler_LockRunning,
1846 DefaultHandler_SetContainedObject
1849 static const IAdviseSinkVtbl DefaultHandler_IAdviseSink_VTable =
1851 DefaultHandler_IAdviseSink_QueryInterface,
1852 DefaultHandler_IAdviseSink_AddRef,
1853 DefaultHandler_IAdviseSink_Release,
1854 DefaultHandler_IAdviseSink_OnDataChange,
1855 DefaultHandler_IAdviseSink_OnViewChange,
1856 DefaultHandler_IAdviseSink_OnRename,
1857 DefaultHandler_IAdviseSink_OnSave,
1858 DefaultHandler_IAdviseSink_OnClose
1861 static const IPersistStorageVtbl DefaultHandler_IPersistStorage_VTable =
1863 DefaultHandler_IPersistStorage_QueryInterface,
1864 DefaultHandler_IPersistStorage_AddRef,
1865 DefaultHandler_IPersistStorage_Release,
1866 DefaultHandler_IPersistStorage_GetClassID,
1867 DefaultHandler_IPersistStorage_IsDirty,
1868 DefaultHandler_IPersistStorage_InitNew,
1869 DefaultHandler_IPersistStorage_Load,
1870 DefaultHandler_IPersistStorage_Save,
1871 DefaultHandler_IPersistStorage_SaveCompleted,
1872 DefaultHandler_IPersistStorage_HandsOffStorage
1875 /*********************************************************
1876 * Methods implementation for the DefaultHandler class.
1878 static DefaultHandler* DefaultHandler_Construct(
1880 LPUNKNOWN pUnkOuter)
1882 DefaultHandler* This = NULL;
1885 This = HeapAlloc(GetProcessHeap(), 0, sizeof(DefaultHandler));
1890 This->lpVtbl = &DefaultHandler_IOleObject_VTable;
1891 This->lpvtblIUnknown = &DefaultHandler_NDIUnknown_VTable;
1892 This->lpvtblIDataObject = &DefaultHandler_IDataObject_VTable;
1893 This->lpvtblIRunnableObject = &DefaultHandler_IRunnableObject_VTable;
1894 This->lpvtblIAdviseSink = &DefaultHandler_IAdviseSink_VTable;
1895 This->lpvtblIPersistStorage = &DefaultHandler_IPersistStorage_VTable;
1898 * Start with one reference count. The caller of this function
1899 * must release the interface pointer when it is done.
1904 * Initialize the outer unknown
1905 * We don't keep a reference on the outer unknown since, the way
1906 * aggregation works, our lifetime is at least as large as its
1910 pUnkOuter = (IUnknown*)&This->lpvtblIUnknown;
1912 This->outerUnknown = pUnkOuter;
1915 * Create a datacache object.
1916 * We aggregate with the datacache. Make sure we pass our outer
1917 * unknown as the datacache's outer unknown.
1919 hr = CreateDataCache(This->outerUnknown,
1922 (void**)&This->dataCache);
1924 hr = IUnknown_QueryInterface(This->dataCache, &IID_IPersistStorage, (void**)&This->dataCache_PersistStg);
1926 ERR("Unexpected error creating data cache\n");
1928 This->clsid = *clsid;
1929 This->clientSite = NULL;
1930 This->oleAdviseHolder = NULL;
1931 This->dataAdviseHolder = NULL;
1932 This->containerApp = NULL;
1933 This->containerObj = NULL;
1934 This->pOleDelegate = NULL;
1935 This->pPSDelegate = NULL;
1936 This->pDataDelegate = NULL;
1938 This->dwAdvConn = 0;
1939 This->storage = NULL;
1940 This->storage_state = storage_state_uninitialised;
1945 static void DefaultHandler_Destroy(
1946 DefaultHandler* This)
1948 /* release delegates */
1949 DefaultHandler_Stop(This);
1951 HeapFree( GetProcessHeap(), 0, This->containerApp );
1952 This->containerApp = NULL;
1953 HeapFree( GetProcessHeap(), 0, This->containerObj );
1954 This->containerObj = NULL;
1956 if (This->dataCache)
1958 IPersistStorage_Release(This->dataCache_PersistStg);
1959 IUnknown_Release(This->dataCache);
1960 This->dataCache_PersistStg = NULL;
1961 This->dataCache = NULL;
1964 if (This->clientSite)
1966 IOleClientSite_Release(This->clientSite);
1967 This->clientSite = NULL;
1970 if (This->oleAdviseHolder)
1972 IOleAdviseHolder_Release(This->oleAdviseHolder);
1973 This->oleAdviseHolder = NULL;
1976 if (This->dataAdviseHolder)
1978 IDataAdviseHolder_Release(This->dataAdviseHolder);
1979 This->dataAdviseHolder = NULL;
1984 IStorage_Release(This->storage);
1985 This->storage = NULL;
1988 HeapFree(GetProcessHeap(), 0, This);
1991 /******************************************************************************
1992 * OleCreateDefaultHandler [OLE32.@]
1994 HRESULT WINAPI OleCreateDefaultHandler(
1996 LPUNKNOWN pUnkOuter,
2000 DefaultHandler* newHandler = NULL;
2003 TRACE("(%s, %p, %s, %p)\n", debugstr_guid(clsid), pUnkOuter, debugstr_guid(riid), ppvObj);
2011 * If This handler is constructed for aggregation, make sure
2012 * the caller is requesting the IUnknown interface.
2013 * This is necessary because it's the only time the non-delegating
2014 * IUnknown pointer can be returned to the outside.
2016 if (pUnkOuter && !IsEqualIID(&IID_IUnknown, riid))
2017 return CLASS_E_NOAGGREGATION;
2020 * Try to construct a new instance of the class.
2022 newHandler = DefaultHandler_Construct(clsid, pUnkOuter);
2025 return E_OUTOFMEMORY;
2028 * Make sure it supports the interface required by the caller.
2030 hr = IUnknown_QueryInterface((IUnknown*)&newHandler->lpvtblIUnknown, riid, ppvObj);
2033 * Release the reference obtained in the constructor. If
2034 * the QueryInterface was unsuccessful, it will free the class.
2036 IUnknown_Release((IUnknown*)&newHandler->lpvtblIUnknown);