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);
67 /****************************************************************************
73 const IOleObjectVtbl* lpVtbl;
74 const IUnknownVtbl* lpvtblIUnknown;
75 const IDataObjectVtbl* lpvtblIDataObject;
76 const IRunnableObjectVtbl* lpvtblIRunnableObject;
77 const IAdviseSinkVtbl *lpvtblIAdviseSink;
78 const IPersistStorageVtbl *lpvtblIPersistStorage;
80 /* Reference count of this object */
83 /* IUnknown implementation of the outer object. */
84 IUnknown* outerUnknown;
86 /* Class Id that this handler object represents. */
89 /* IUnknown implementation of the datacache. */
91 /* IPersistStorage implementation of the datacache. */
92 IPersistStorage* dataCache_PersistStg;
94 /* Client site for the embedded object. */
95 IOleClientSite* clientSite;
98 * The IOleAdviseHolder maintains the connections
99 * on behalf of the default handler.
101 IOleAdviseHolder* oleAdviseHolder;
104 * The IDataAdviseHolder maintains the data
105 * connections on behalf of the default handler.
107 IDataAdviseHolder* dataAdviseHolder;
109 /* Name of the container and object contained */
113 /* IOleObject delegate */
114 IOleObject *pOleDelegate;
115 /* IPersistStorage delegate */
116 IPersistStorage *pPSDelegate;
117 /* IDataObject delegate */
118 IDataObject *pDataDelegate;
120 /* connection cookie for the advise on the delegate OLE object */
124 typedef struct DefaultHandler DefaultHandler;
127 * Here, I define utility functions to help with the casting of the
129 * There is a version to accommodate all of the VTables implemented
132 static inline DefaultHandler *impl_from_IOleObject( IOleObject *iface )
134 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpVtbl));
137 static inline DefaultHandler *impl_from_NDIUnknown( IUnknown *iface )
139 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIUnknown));
142 static inline DefaultHandler *impl_from_IDataObject( IDataObject *iface )
144 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIDataObject));
147 static inline DefaultHandler *impl_from_IRunnableObject( IRunnableObject *iface )
149 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIRunnableObject));
152 static inline DefaultHandler *impl_from_IAdviseSink( IAdviseSink *iface )
154 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIAdviseSink));
157 static inline DefaultHandler *impl_from_IPersistStorage( IPersistStorage *iface )
159 return (DefaultHandler *)((char*)iface - FIELD_OFFSET(DefaultHandler, lpvtblIPersistStorage));
162 static void DefaultHandler_Destroy(DefaultHandler* This);
164 static inline BOOL object_is_running(DefaultHandler *This)
166 return IRunnableObject_IsRunning((IRunnableObject*)&This->lpvtblIRunnableObject);
169 /*********************************************************
170 * Method implementation for the non delegating IUnknown
171 * part of the DefaultHandler class.
174 /************************************************************************
175 * DefaultHandler_NDIUnknown_QueryInterface (IUnknown)
177 * See Windows documentation for more details on IUnknown methods.
179 * This version of QueryInterface will not delegate its implementation
180 * to the outer unknown.
182 static HRESULT WINAPI DefaultHandler_NDIUnknown_QueryInterface(
187 DefaultHandler *This = impl_from_NDIUnknown(iface);
189 /* Perform a sanity check on the parameters. */
195 if (IsEqualIID(&IID_IUnknown, riid))
197 else if (IsEqualIID(&IID_IOleObject, riid))
198 *ppvObject = (IOleObject*)&This->lpVtbl;
199 else if (IsEqualIID(&IID_IDataObject, riid))
200 *ppvObject = (IDataObject*)&This->lpvtblIDataObject;
201 else if (IsEqualIID(&IID_IRunnableObject, riid))
202 *ppvObject = (IRunnableObject*)&This->lpvtblIRunnableObject;
203 else if (IsEqualIID(&IID_IPersist, riid) ||
204 IsEqualIID(&IID_IPersistStorage, riid))
205 *ppvObject = &This->lpvtblIPersistStorage;
206 else if (IsEqualIID(&IID_IViewObject, riid) ||
207 IsEqualIID(&IID_IViewObject2, riid) ||
208 IsEqualIID(&IID_IOleCache, riid) ||
209 IsEqualIID(&IID_IOleCache2, riid))
211 HRESULT hr = IUnknown_QueryInterface(This->dataCache, riid, ppvObject);
212 if (FAILED(hr)) FIXME("interface %s not implemented by data cache\n", debugstr_guid(riid));
216 /* Check that we obtained an interface. */
217 if (*ppvObject == NULL)
219 WARN( "() : asking for un supported interface %s\n", debugstr_guid(riid));
220 return E_NOINTERFACE;
224 * Query Interface always increases the reference count by one when it is
227 IUnknown_AddRef((IUnknown*)*ppvObject);
232 /************************************************************************
233 * DefaultHandler_NDIUnknown_AddRef (IUnknown)
235 * See Windows documentation for more details on IUnknown methods.
237 * This version of QueryInterface will not delegate its implementation
238 * to the outer unknown.
240 static ULONG WINAPI DefaultHandler_NDIUnknown_AddRef(
243 DefaultHandler *This = impl_from_NDIUnknown(iface);
244 return InterlockedIncrement(&This->ref);
247 /************************************************************************
248 * DefaultHandler_NDIUnknown_Release (IUnknown)
250 * See Windows documentation for more details on IUnknown methods.
252 * This version of QueryInterface will not delegate its implementation
253 * to the outer unknown.
255 static ULONG WINAPI DefaultHandler_NDIUnknown_Release(
258 DefaultHandler *This = impl_from_NDIUnknown(iface);
261 /* Decrease the reference count on this object. */
262 ref = InterlockedDecrement(&This->ref);
264 if (!ref) DefaultHandler_Destroy(This);
269 /*********************************************************
270 * Methods implementation for the IOleObject part of
271 * the DefaultHandler class.
274 /************************************************************************
275 * DefaultHandler_QueryInterface (IUnknown)
277 * See Windows documentation for more details on IUnknown methods.
279 static HRESULT WINAPI DefaultHandler_QueryInterface(
284 DefaultHandler *This = impl_from_IOleObject(iface);
286 return IUnknown_QueryInterface(This->outerUnknown, riid, ppvObject);
289 /************************************************************************
290 * DefaultHandler_AddRef (IUnknown)
292 * See Windows documentation for more details on IUnknown methods.
294 static ULONG WINAPI DefaultHandler_AddRef(
297 DefaultHandler *This = impl_from_IOleObject(iface);
299 return IUnknown_AddRef(This->outerUnknown);
302 /************************************************************************
303 * DefaultHandler_Release (IUnknown)
305 * See Windows documentation for more details on IUnknown methods.
307 static ULONG WINAPI DefaultHandler_Release(
310 DefaultHandler *This = impl_from_IOleObject(iface);
312 return IUnknown_Release(This->outerUnknown);
315 /************************************************************************
316 * DefaultHandler_SetClientSite (IOleObject)
318 * The default handler's implementation of this method only keeps the
319 * client site pointer for future reference.
321 * See Windows documentation for more details on IOleObject methods.
323 static HRESULT WINAPI DefaultHandler_SetClientSite(
325 IOleClientSite* pClientSite)
327 DefaultHandler *This = impl_from_IOleObject(iface);
330 TRACE("(%p, %p)\n", iface, pClientSite);
332 if (object_is_running(This))
333 hr = IOleObject_SetClientSite(This->pOleDelegate, pClientSite);
336 * Make sure we release the previous client site if there
339 if (This->clientSite)
340 IOleClientSite_Release(This->clientSite);
342 This->clientSite = pClientSite;
344 if (This->clientSite)
345 IOleClientSite_AddRef(This->clientSite);
350 /************************************************************************
351 * DefaultHandler_GetClientSite (IOleObject)
353 * The default handler's implementation of this method returns the
354 * last pointer set in IOleObject_SetClientSite.
356 * See Windows documentation for more details on IOleObject methods.
358 static HRESULT WINAPI DefaultHandler_GetClientSite(
360 IOleClientSite** ppClientSite)
362 DefaultHandler *This = impl_from_IOleObject(iface);
368 *ppClientSite = This->clientSite;
370 if (This->clientSite)
371 IOleClientSite_AddRef(This->clientSite);
376 /************************************************************************
377 * DefaultHandler_SetHostNames (IOleObject)
379 * The default handler's implementation of this method just stores
380 * the strings and returns S_OK.
382 * See Windows documentation for more details on IOleObject methods.
384 static HRESULT WINAPI DefaultHandler_SetHostNames(
386 LPCOLESTR szContainerApp,
387 LPCOLESTR szContainerObj)
389 DefaultHandler *This = impl_from_IOleObject(iface);
391 TRACE("(%p, %s, %s)\n",
393 debugstr_w(szContainerApp),
394 debugstr_w(szContainerObj));
396 if (object_is_running(This))
397 IOleObject_SetHostNames(This->pOleDelegate, szContainerApp, szContainerObj);
399 /* Be sure to cleanup before re-assigning the strings. */
400 HeapFree( GetProcessHeap(), 0, This->containerApp );
401 This->containerApp = NULL;
402 HeapFree( GetProcessHeap(), 0, This->containerObj );
403 This->containerObj = NULL;
405 /* Copy the string supplied. */
408 if ((This->containerApp = HeapAlloc( GetProcessHeap(), 0,
409 (lstrlenW(szContainerApp) + 1) * sizeof(WCHAR) )))
410 strcpyW( This->containerApp, szContainerApp );
415 if ((This->containerObj = HeapAlloc( GetProcessHeap(), 0,
416 (lstrlenW(szContainerObj) + 1) * sizeof(WCHAR) )))
417 strcpyW( This->containerObj, szContainerObj );
422 /* undos the work done by DefaultHandler_Run */
423 static void WINAPI DefaultHandler_Stop(DefaultHandler *This)
425 if (!object_is_running(This))
428 IOleObject_Unadvise(This->pOleDelegate, This->dwAdvConn);
430 /* FIXME: call IOleCache_OnStop */
432 if (This->dataAdviseHolder)
433 DataAdviseHolder_OnDisconnect(This->dataAdviseHolder);
434 if (This->pDataDelegate)
436 IDataObject_Release(This->pDataDelegate);
437 This->pDataDelegate = NULL;
439 if (This->pPSDelegate)
441 IPersistStorage_Release(This->pPSDelegate);
442 This->pPSDelegate = NULL;
444 IOleObject_Release(This->pOleDelegate);
445 This->pOleDelegate = NULL;
448 /************************************************************************
449 * DefaultHandler_Close (IOleObject)
451 * The default handler's implementation of this method is meaningless
452 * without a running server so it does nothing.
454 * See Windows documentation for more details on IOleObject methods.
456 static HRESULT WINAPI DefaultHandler_Close(
460 DefaultHandler *This = impl_from_IOleObject(iface);
463 TRACE("(%d)\n", dwSaveOption);
465 if (!object_is_running(This))
468 hr = IOleObject_Close(This->pOleDelegate, dwSaveOption);
470 DefaultHandler_Stop(This);
475 /************************************************************************
476 * DefaultHandler_SetMoniker (IOleObject)
478 * The default handler's implementation of this method does nothing.
480 * See Windows documentation for more details on IOleObject methods.
482 static HRESULT WINAPI DefaultHandler_SetMoniker(
484 DWORD dwWhichMoniker,
487 DefaultHandler *This = impl_from_IOleObject(iface);
489 TRACE("(%p, %d, %p)\n",
494 if (object_is_running(This))
495 return IOleObject_SetMoniker(This->pOleDelegate, dwWhichMoniker, pmk);
500 /************************************************************************
501 * DefaultHandler_GetMoniker (IOleObject)
503 * Delegate this request to the client site if we have one.
505 * See Windows documentation for more details on IOleObject methods.
507 static HRESULT WINAPI DefaultHandler_GetMoniker(
510 DWORD dwWhichMoniker,
513 DefaultHandler *This = impl_from_IOleObject(iface);
515 TRACE("(%p, %d, %d, %p)\n",
516 iface, dwAssign, dwWhichMoniker, ppmk);
518 if (object_is_running(This))
519 return IOleObject_GetMoniker(This->pOleDelegate, dwAssign, dwWhichMoniker,
522 /* FIXME: dwWhichMoniker == OLEWHICHMK_CONTAINER only? */
523 if (This->clientSite)
525 return IOleClientSite_GetMoniker(This->clientSite,
535 /************************************************************************
536 * DefaultHandler_InitFromData (IOleObject)
538 * This method is meaningless if the server is not running
540 * See Windows documentation for more details on IOleObject methods.
542 static HRESULT WINAPI DefaultHandler_InitFromData(
544 IDataObject* pDataObject,
548 DefaultHandler *This = impl_from_IOleObject(iface);
550 TRACE("(%p, %p, %d, %d)\n",
551 iface, pDataObject, fCreation, dwReserved);
553 if (object_is_running(This))
554 return IOleObject_InitFromData(This->pOleDelegate, pDataObject, fCreation,
556 return OLE_E_NOTRUNNING;
559 /************************************************************************
560 * DefaultHandler_GetClipboardData (IOleObject)
562 * This method is meaningless if the server is not running
564 * See Windows documentation for more details on IOleObject methods.
566 static HRESULT WINAPI DefaultHandler_GetClipboardData(
569 IDataObject** ppDataObject)
571 DefaultHandler *This = impl_from_IOleObject(iface);
573 TRACE("(%p, %d, %p)\n",
574 iface, dwReserved, ppDataObject);
576 if (object_is_running(This))
577 return IOleObject_GetClipboardData(This->pOleDelegate, dwReserved,
580 return OLE_E_NOTRUNNING;
583 static HRESULT WINAPI DefaultHandler_DoVerb(
586 struct tagMSG* lpmsg,
587 IOleClientSite* pActiveSite,
592 DefaultHandler *This = impl_from_IOleObject(iface);
593 IRunnableObject *pRunnableObj = (IRunnableObject *)&This->lpvtblIRunnableObject;
596 TRACE("(%d, %p, %p, %d, %p, %s)\n", iVerb, lpmsg, pActiveSite, lindex, hwndParent, wine_dbgstr_rect(lprcPosRect));
598 hr = IRunnableObject_Run(pRunnableObj, NULL);
599 if (FAILED(hr)) return hr;
601 return IOleObject_DoVerb(This->pOleDelegate, iVerb, lpmsg, pActiveSite,
602 lindex, hwndParent, lprcPosRect);
605 /************************************************************************
606 * DefaultHandler_EnumVerbs (IOleObject)
608 * The default handler implementation of this method simply delegates
611 * See Windows documentation for more details on IOleObject methods.
613 static HRESULT WINAPI DefaultHandler_EnumVerbs(
615 IEnumOLEVERB** ppEnumOleVerb)
617 DefaultHandler *This = impl_from_IOleObject(iface);
618 HRESULT hr = OLE_S_USEREG;
620 TRACE("(%p, %p)\n", iface, ppEnumOleVerb);
622 if (object_is_running(This))
623 hr = IOleObject_EnumVerbs(This->pOleDelegate, ppEnumOleVerb);
625 if (hr == OLE_S_USEREG)
626 return OleRegEnumVerbs(&This->clsid, ppEnumOleVerb);
631 static HRESULT WINAPI DefaultHandler_Update(
638 /************************************************************************
639 * DefaultHandler_IsUpToDate (IOleObject)
641 * This method is meaningless if the server is not running
643 * See Windows documentation for more details on IOleObject methods.
645 static HRESULT WINAPI DefaultHandler_IsUpToDate(
648 TRACE("(%p)\n", iface);
650 return OLE_E_NOTRUNNING;
653 /************************************************************************
654 * DefaultHandler_GetUserClassID (IOleObject)
656 * TODO: Map to a new class ID if emulation is active.
658 * See Windows documentation for more details on IOleObject methods.
660 static HRESULT WINAPI DefaultHandler_GetUserClassID(
664 DefaultHandler *This = impl_from_IOleObject(iface);
666 TRACE("(%p, %p)\n", iface, pClsid);
668 if (object_is_running(This))
669 return IOleObject_GetUserClassID(This->pOleDelegate, pClsid);
675 *pClsid = This->clsid;
680 /************************************************************************
681 * DefaultHandler_GetUserType (IOleObject)
683 * The default handler implementation of this method simply delegates
684 * to OleRegGetUserType
686 * See Windows documentation for more details on IOleObject methods.
688 static HRESULT WINAPI DefaultHandler_GetUserType(
691 LPOLESTR* pszUserType)
693 DefaultHandler *This = impl_from_IOleObject(iface);
695 TRACE("(%p, %d, %p)\n", iface, dwFormOfType, pszUserType);
697 return OleRegGetUserType(&This->clsid, dwFormOfType, pszUserType);
700 /************************************************************************
701 * DefaultHandler_SetExtent (IOleObject)
703 * This method is meaningless if the server is not running
705 * See Windows documentation for more details on IOleObject methods.
707 static HRESULT WINAPI DefaultHandler_SetExtent(
712 DefaultHandler *This = impl_from_IOleObject(iface);
714 TRACE("(%p, %x, (%d x %d))\n", iface,
715 dwDrawAspect, psizel->cx, psizel->cy);
717 if (object_is_running(This))
718 IOleObject_SetExtent(This->pOleDelegate, dwDrawAspect, psizel);
720 return OLE_E_NOTRUNNING;
723 /************************************************************************
724 * DefaultHandler_GetExtent (IOleObject)
726 * The default handler's implementation of this method returns uses
727 * the cache to locate the aspect and extract the extent from it.
729 * See Windows documentation for more details on IOleObject methods.
731 static HRESULT WINAPI DefaultHandler_GetExtent(
736 DVTARGETDEVICE* targetDevice;
737 IViewObject2* cacheView = NULL;
740 DefaultHandler *This = impl_from_IOleObject(iface);
742 TRACE("(%p, %x, %p)\n", iface, dwDrawAspect, psizel);
744 if (object_is_running(This))
745 return IOleObject_GetExtent(This->pOleDelegate, dwDrawAspect, psizel);
747 hres = IUnknown_QueryInterface(This->dataCache, &IID_IViewObject2, (void**)&cacheView);
752 * Prepare the call to the cache's GetExtent method.
754 * Here we would build a valid DVTARGETDEVICE structure
755 * but, since we are calling into the data cache, we
756 * know its implementation and we'll skip this
757 * extra work until later.
761 hres = IViewObject2_GetExtent(cacheView,
770 IViewObject2_Release(cacheView);
775 /************************************************************************
776 * DefaultHandler_Advise (IOleObject)
778 * The default handler's implementation of this method simply
779 * delegates to the OleAdviseHolder.
781 * See Windows documentation for more details on IOleObject methods.
783 static HRESULT WINAPI DefaultHandler_Advise(
785 IAdviseSink* pAdvSink,
786 DWORD* pdwConnection)
789 DefaultHandler *This = impl_from_IOleObject(iface);
791 TRACE("(%p, %p, %p)\n", iface, pAdvSink, pdwConnection);
793 /* Make sure we have an advise holder before we start. */
794 if (!This->oleAdviseHolder)
795 hres = CreateOleAdviseHolder(&This->oleAdviseHolder);
798 hres = IOleAdviseHolder_Advise(This->oleAdviseHolder,
805 /************************************************************************
806 * DefaultHandler_Unadvise (IOleObject)
808 * The default handler's implementation of this method simply
809 * delegates to the OleAdviseHolder.
811 * See Windows documentation for more details on IOleObject methods.
813 static HRESULT WINAPI DefaultHandler_Unadvise(
817 DefaultHandler *This = impl_from_IOleObject(iface);
819 TRACE("(%p, %d)\n", iface, dwConnection);
822 * If we don't have an advise holder yet, it means we don't have
825 if (!This->oleAdviseHolder)
826 return OLE_E_NOCONNECTION;
828 return IOleAdviseHolder_Unadvise(This->oleAdviseHolder,
832 /************************************************************************
833 * DefaultHandler_EnumAdvise (IOleObject)
835 * The default handler's implementation of this method simply
836 * delegates to the OleAdviseHolder.
838 * See Windows documentation for more details on IOleObject methods.
840 static HRESULT WINAPI DefaultHandler_EnumAdvise(
842 IEnumSTATDATA** ppenumAdvise)
844 DefaultHandler *This = impl_from_IOleObject(iface);
846 TRACE("(%p, %p)\n", iface, ppenumAdvise);
852 *ppenumAdvise = NULL;
854 if (!This->oleAdviseHolder)
857 return IOleAdviseHolder_EnumAdvise(This->oleAdviseHolder, ppenumAdvise);
860 /************************************************************************
861 * DefaultHandler_GetMiscStatus (IOleObject)
863 * The default handler's implementation of this method simply delegates
864 * to OleRegGetMiscStatus.
866 * See Windows documentation for more details on IOleObject methods.
868 static HRESULT WINAPI DefaultHandler_GetMiscStatus(
874 DefaultHandler *This = impl_from_IOleObject(iface);
876 TRACE("(%p, %x, %p)\n", iface, dwAspect, pdwStatus);
878 if (object_is_running(This))
879 return IOleObject_GetMiscStatus(This->pOleDelegate, dwAspect, pdwStatus);
881 hres = OleRegGetMiscStatus(&This->clsid, dwAspect, pdwStatus);
889 /************************************************************************
890 * DefaultHandler_SetColorScheme (IOleObject)
892 * This method is meaningless if the server is not running
894 * See Windows documentation for more details on IOleObject methods.
896 static HRESULT WINAPI DefaultHandler_SetColorScheme(
898 struct tagLOGPALETTE* pLogpal)
900 DefaultHandler *This = impl_from_IOleObject(iface);
902 TRACE("(%p, %p))\n", iface, pLogpal);
904 if (object_is_running(This))
905 return IOleObject_SetColorScheme(This->pOleDelegate, pLogpal);
907 return OLE_E_NOTRUNNING;
910 /*********************************************************
911 * Methods implementation for the IDataObject part of
912 * the DefaultHandler class.
915 /************************************************************************
916 * DefaultHandler_IDataObject_QueryInterface (IUnknown)
918 * See Windows documentation for more details on IUnknown methods.
920 static HRESULT WINAPI DefaultHandler_IDataObject_QueryInterface(
925 DefaultHandler *This = impl_from_IDataObject(iface);
927 return IUnknown_QueryInterface(This->outerUnknown, riid, ppvObject);
930 /************************************************************************
931 * DefaultHandler_IDataObject_AddRef (IUnknown)
933 * See Windows documentation for more details on IUnknown methods.
935 static ULONG WINAPI DefaultHandler_IDataObject_AddRef(
938 DefaultHandler *This = impl_from_IDataObject(iface);
940 return IUnknown_AddRef(This->outerUnknown);
943 /************************************************************************
944 * DefaultHandler_IDataObject_Release (IUnknown)
946 * See Windows documentation for more details on IUnknown methods.
948 static ULONG WINAPI DefaultHandler_IDataObject_Release(
951 DefaultHandler *This = impl_from_IDataObject(iface);
953 return IUnknown_Release(This->outerUnknown);
956 /************************************************************************
957 * DefaultHandler_GetData
959 * Get Data from a source dataobject using format pformatetcIn->cfFormat
960 * See Windows documentation for more details on GetData.
961 * Default handler's implementation of this method delegates to the cache.
963 static HRESULT WINAPI DefaultHandler_GetData(
965 LPFORMATETC pformatetcIn,
968 IDataObject* cacheDataObject = NULL;
971 DefaultHandler *This = impl_from_IDataObject(iface);
973 TRACE("(%p, %p, %p)\n", iface, pformatetcIn, pmedium);
975 hres = IUnknown_QueryInterface(This->dataCache,
977 (void**)&cacheDataObject);
982 hres = IDataObject_GetData(cacheDataObject,
986 IDataObject_Release(cacheDataObject);
988 if (FAILED(hres) && This->pDataDelegate)
989 hres = IDataObject_GetData(This->pDataDelegate, pformatetcIn, pmedium);
994 static HRESULT WINAPI DefaultHandler_GetDataHere(
996 LPFORMATETC pformatetc,
1003 /************************************************************************
1004 * DefaultHandler_QueryGetData (IDataObject)
1006 * The default handler's implementation of this method delegates to
1009 * See Windows documentation for more details on IDataObject methods.
1011 static HRESULT WINAPI DefaultHandler_QueryGetData(
1013 LPFORMATETC pformatetc)
1015 IDataObject* cacheDataObject = NULL;
1018 DefaultHandler *This = impl_from_IDataObject(iface);
1020 TRACE("(%p, %p)\n", iface, pformatetc);
1022 hres = IUnknown_QueryInterface(This->dataCache,
1024 (void**)&cacheDataObject);
1027 return E_UNEXPECTED;
1029 hres = IDataObject_QueryGetData(cacheDataObject,
1032 IDataObject_Release(cacheDataObject);
1034 if (FAILED(hres) && This->pDataDelegate)
1035 hres = IDataObject_QueryGetData(This->pDataDelegate, pformatetc);
1040 /************************************************************************
1041 * DefaultHandler_GetCanonicalFormatEtc (IDataObject)
1043 * This method is meaningless if the server is not running
1045 * See Windows documentation for more details on IDataObject methods.
1047 static HRESULT WINAPI DefaultHandler_GetCanonicalFormatEtc(
1049 LPFORMATETC pformatetcIn,
1050 LPFORMATETC pformatetcOut)
1052 DefaultHandler *This = impl_from_IDataObject(iface);
1054 TRACE("(%p, %p, %p)\n", iface, pformatetcIn, pformatetcOut);
1056 if (!This->pDataDelegate)
1057 return OLE_E_NOTRUNNING;
1059 return IDataObject_GetCanonicalFormatEtc(This->pDataDelegate, pformatetcIn, pformatetcOut);
1062 /************************************************************************
1063 * DefaultHandler_SetData (IDataObject)
1065 * The default handler's implementation of this method delegates to
1068 * See Windows documentation for more details on IDataObject methods.
1070 static HRESULT WINAPI DefaultHandler_SetData(
1072 LPFORMATETC pformatetc,
1076 DefaultHandler *This = impl_from_IDataObject(iface);
1077 IDataObject* cacheDataObject = NULL;
1080 TRACE("(%p, %p, %p, %d)\n", iface, pformatetc, pmedium, fRelease);
1082 hres = IUnknown_QueryInterface(This->dataCache,
1084 (void**)&cacheDataObject);
1087 return E_UNEXPECTED;
1089 hres = IDataObject_SetData(cacheDataObject,
1094 IDataObject_Release(cacheDataObject);
1099 /************************************************************************
1100 * DefaultHandler_EnumFormatEtc (IDataObject)
1102 * The default handler's implementation of This method simply delegates
1103 * to OleRegEnumFormatEtc.
1105 * See Windows documentation for more details on IDataObject methods.
1107 static HRESULT WINAPI DefaultHandler_EnumFormatEtc(
1110 IEnumFORMATETC** ppenumFormatEtc)
1113 DefaultHandler *This = impl_from_IDataObject(iface);
1115 TRACE("(%p, %x, %p)\n", iface, dwDirection, ppenumFormatEtc);
1117 hres = OleRegEnumFormatEtc(&This->clsid, dwDirection, ppenumFormatEtc);
1122 /************************************************************************
1123 * DefaultHandler_DAdvise (IDataObject)
1125 * The default handler's implementation of this method simply
1126 * delegates to the DataAdviseHolder.
1128 * See Windows documentation for more details on IDataObject methods.
1130 static HRESULT WINAPI DefaultHandler_DAdvise(
1132 FORMATETC* pformatetc,
1134 IAdviseSink* pAdvSink,
1135 DWORD* pdwConnection)
1137 HRESULT hres = S_OK;
1138 DefaultHandler *This = impl_from_IDataObject(iface);
1140 TRACE("(%p, %p, %d, %p, %p)\n",
1141 iface, pformatetc, advf, pAdvSink, pdwConnection);
1143 /* Make sure we have a data advise holder before we start. */
1144 if (!This->dataAdviseHolder)
1146 hres = CreateDataAdviseHolder(&This->dataAdviseHolder);
1147 if (SUCCEEDED(hres) && This->pDataDelegate)
1148 DataAdviseHolder_OnConnect(This->dataAdviseHolder, This->pDataDelegate);
1151 if (SUCCEEDED(hres))
1152 hres = IDataAdviseHolder_Advise(This->dataAdviseHolder,
1162 /************************************************************************
1163 * DefaultHandler_DUnadvise (IDataObject)
1165 * The default handler's implementation of this method simply
1166 * delegates to the DataAdviseHolder.
1168 * See Windows documentation for more details on IDataObject methods.
1170 static HRESULT WINAPI DefaultHandler_DUnadvise(
1174 DefaultHandler *This = impl_from_IDataObject(iface);
1176 TRACE("(%p, %d)\n", iface, dwConnection);
1179 * If we don't have a data advise holder yet, it means that
1180 * we don't have any connections..
1182 if (!This->dataAdviseHolder)
1183 return OLE_E_NOCONNECTION;
1185 return IDataAdviseHolder_Unadvise(This->dataAdviseHolder,
1189 /************************************************************************
1190 * DefaultHandler_EnumDAdvise (IDataObject)
1192 * The default handler's implementation of this method simply
1193 * delegates to the DataAdviseHolder.
1195 * See Windows documentation for more details on IDataObject methods.
1197 static HRESULT WINAPI DefaultHandler_EnumDAdvise(
1199 IEnumSTATDATA** ppenumAdvise)
1201 DefaultHandler *This = impl_from_IDataObject(iface);
1203 TRACE("(%p, %p)\n", iface, ppenumAdvise);
1209 *ppenumAdvise = NULL;
1211 /* If we have a data advise holder object, delegate. */
1212 if (This->dataAdviseHolder)
1213 return IDataAdviseHolder_EnumAdvise(This->dataAdviseHolder,
1219 /*********************************************************
1220 * Methods implementation for the IRunnableObject part
1221 * of the DefaultHandler class.
1224 /************************************************************************
1225 * DefaultHandler_IRunnableObject_QueryInterface (IUnknown)
1227 * See Windows documentation for more details on IUnknown methods.
1229 static HRESULT WINAPI DefaultHandler_IRunnableObject_QueryInterface(
1230 IRunnableObject* iface,
1234 DefaultHandler *This = impl_from_IRunnableObject(iface);
1236 return IUnknown_QueryInterface(This->outerUnknown, riid, ppvObject);
1239 /************************************************************************
1240 * DefaultHandler_IRunnableObject_AddRef (IUnknown)
1242 * See Windows documentation for more details on IUnknown methods.
1244 static ULONG WINAPI DefaultHandler_IRunnableObject_AddRef(
1245 IRunnableObject* iface)
1247 DefaultHandler *This = impl_from_IRunnableObject(iface);
1249 return IUnknown_AddRef(This->outerUnknown);
1252 /************************************************************************
1253 * DefaultHandler_IRunnableObject_Release (IUnknown)
1255 * See Windows documentation for more details on IUnknown methods.
1257 static ULONG WINAPI DefaultHandler_IRunnableObject_Release(
1258 IRunnableObject* iface)
1260 DefaultHandler *This = impl_from_IRunnableObject(iface);
1262 return IUnknown_Release(This->outerUnknown);
1265 /************************************************************************
1266 * DefaultHandler_GetRunningClass (IRunnableObject)
1268 * See Windows documentation for more details on IRunnableObject methods.
1270 static HRESULT WINAPI DefaultHandler_GetRunningClass(
1271 IRunnableObject* iface,
1278 static HRESULT WINAPI DefaultHandler_Run(
1279 IRunnableObject* iface,
1282 DefaultHandler *This = impl_from_IRunnableObject(iface);
1285 FIXME("(%p): semi-stub\n", pbc);
1287 /* already running? if so nothing to do */
1288 if (object_is_running(This))
1291 hr = CoCreateInstance(&This->clsid, NULL, CLSCTX_LOCAL_SERVER,
1292 &IID_IOleObject, (void **)&This->pOleDelegate);
1296 hr = IOleObject_Advise(This->pOleDelegate,
1297 (IAdviseSink *)&This->lpvtblIAdviseSink,
1300 if (SUCCEEDED(hr) && This->clientSite)
1301 hr = IOleObject_SetClientSite(This->pOleDelegate, This->clientSite);
1305 IOleObject_QueryInterface(This->pOleDelegate, &IID_IPersistStorage,
1306 (void **)&This->pPSDelegate);
1307 if (This->pPSDelegate)
1308 hr = IPersistStorage_InitNew(This->pPSDelegate, NULL);
1311 if (SUCCEEDED(hr) && This->containerApp)
1312 hr = IOleObject_SetHostNames(This->pOleDelegate, This->containerApp,
1313 This->containerObj);
1315 /* FIXME: do more stuff here:
1316 * - IOleObject_GetMiscStatus
1317 * - IOleObject_GetMoniker
1322 hr = IOleObject_QueryInterface(This->pOleDelegate, &IID_IDataObject,
1323 (void **)&This->pDataDelegate);
1325 if (SUCCEEDED(hr) && This->dataAdviseHolder)
1326 hr = DataAdviseHolder_OnConnect(This->dataAdviseHolder, This->pDataDelegate);
1329 DefaultHandler_Stop(This);
1334 /************************************************************************
1335 * DefaultHandler_IsRunning (IRunnableObject)
1337 * See Windows documentation for more details on IRunnableObject methods.
1339 static BOOL WINAPI DefaultHandler_IsRunning(
1340 IRunnableObject* iface)
1342 DefaultHandler *This = impl_from_IRunnableObject(iface);
1346 if (This->pOleDelegate)
1352 /************************************************************************
1353 * DefaultHandler_LockRunning (IRunnableObject)
1355 * See Windows documentation for more details on IRunnableObject methods.
1357 static HRESULT WINAPI DefaultHandler_LockRunning(
1358 IRunnableObject* iface,
1360 BOOL fLastUnlockCloses)
1366 /************************************************************************
1367 * DefaultHandler_SetContainedObject (IRunnableObject)
1369 * See Windows documentation for more details on IRunnableObject methods.
1371 static HRESULT WINAPI DefaultHandler_SetContainedObject(
1372 IRunnableObject* iface,
1379 static HRESULT WINAPI DefaultHandler_IAdviseSink_QueryInterface(
1384 if (IsEqualIID(riid, &IID_IUnknown) ||
1385 IsEqualIID(riid, &IID_IAdviseSink))
1388 IAdviseSink_AddRef(iface);
1392 return E_NOINTERFACE;
1395 static ULONG WINAPI DefaultHandler_IAdviseSink_AddRef(
1398 DefaultHandler *This = impl_from_IAdviseSink(iface);
1400 return IUnknown_AddRef((IUnknown *)&This->lpvtblIUnknown);
1403 static ULONG WINAPI DefaultHandler_IAdviseSink_Release(
1406 DefaultHandler *This = impl_from_IAdviseSink(iface);
1408 return IUnknown_Release((IUnknown *)&This->lpvtblIUnknown);
1411 static void WINAPI DefaultHandler_IAdviseSink_OnDataChange(
1413 FORMATETC *pFormatetc,
1419 static void WINAPI DefaultHandler_IAdviseSink_OnViewChange(
1427 static void WINAPI DefaultHandler_IAdviseSink_OnRename(
1431 DefaultHandler *This = impl_from_IAdviseSink(iface);
1433 TRACE("(%p)\n", pmk);
1435 if (This->oleAdviseHolder)
1436 IOleAdviseHolder_SendOnRename(This->oleAdviseHolder, pmk);
1439 static void WINAPI DefaultHandler_IAdviseSink_OnSave(
1442 DefaultHandler *This = impl_from_IAdviseSink(iface);
1446 if (This->oleAdviseHolder)
1447 IOleAdviseHolder_SendOnSave(This->oleAdviseHolder);
1450 static void WINAPI DefaultHandler_IAdviseSink_OnClose(
1453 DefaultHandler *This = impl_from_IAdviseSink(iface);
1457 if (This->oleAdviseHolder)
1458 IOleAdviseHolder_SendOnClose(This->oleAdviseHolder);
1460 DefaultHandler_Stop(This);
1464 /************************************************************************
1465 * DefaultHandler_IPersistStorage_QueryInterface
1468 static HRESULT WINAPI DefaultHandler_IPersistStorage_QueryInterface(
1469 IPersistStorage* iface,
1473 DefaultHandler *This = impl_from_IPersistStorage(iface);
1475 return IUnknown_QueryInterface(This->outerUnknown, riid, ppvObject);
1478 /************************************************************************
1479 * DefaultHandler_IPersistStorage_AddRef
1482 static ULONG WINAPI DefaultHandler_IPersistStorage_AddRef(
1483 IPersistStorage* iface)
1485 DefaultHandler *This = impl_from_IPersistStorage(iface);
1487 return IUnknown_AddRef(This->outerUnknown);
1490 /************************************************************************
1491 * DefaultHandler_IPersistStorage_Release
1494 static ULONG WINAPI DefaultHandler_IPersistStorage_Release(
1495 IPersistStorage* iface)
1497 DefaultHandler *This = impl_from_IPersistStorage(iface);
1499 return IUnknown_Release(This->outerUnknown);
1502 /************************************************************************
1503 * DefaultHandler_IPersistStorage_GetClassID
1506 static HRESULT WINAPI DefaultHandler_IPersistStorage_GetClassID(
1507 IPersistStorage* iface,
1510 DefaultHandler *This = impl_from_IPersistStorage(iface);
1512 return IPersistStorage_GetClassID(This->dataCache_PersistStg, clsid);
1515 /************************************************************************
1516 * DefaultHandler_IPersistStorage_IsDirty
1519 static HRESULT WINAPI DefaultHandler_IPersistStorage_IsDirty(
1520 IPersistStorage* iface)
1522 DefaultHandler *This = impl_from_IPersistStorage(iface);
1524 return IPersistStorage_IsDirty(This->dataCache_PersistStg);
1527 /************************************************************************
1528 * DefaultHandler_IPersistStorage_InitNew
1531 static HRESULT WINAPI DefaultHandler_IPersistStorage_InitNew(
1532 IPersistStorage* iface,
1535 DefaultHandler *This = impl_from_IPersistStorage(iface);
1537 return IPersistStorage_InitNew(This->dataCache_PersistStg, pStg);
1541 /************************************************************************
1542 * DefaultHandler_IPersistStorage_Load
1545 static HRESULT WINAPI DefaultHandler_IPersistStorage_Load(
1546 IPersistStorage* iface,
1549 DefaultHandler *This = impl_from_IPersistStorage(iface);
1551 return IPersistStorage_Load(This->dataCache_PersistStg, pStg);
1555 /************************************************************************
1556 * DefaultHandler_IPersistStorage_Save
1559 static HRESULT WINAPI DefaultHandler_IPersistStorage_Save(
1560 IPersistStorage* iface,
1564 DefaultHandler *This = impl_from_IPersistStorage(iface);
1566 return IPersistStorage_Save(This->dataCache_PersistStg, pStgSave, fSaveAsLoad);
1570 /************************************************************************
1571 * DefaultHandler_IPersistStorage_SaveCompleted
1574 static HRESULT WINAPI DefaultHandler_IPersistStorage_SaveCompleted(
1575 IPersistStorage* iface,
1578 DefaultHandler *This = impl_from_IPersistStorage(iface);
1580 return IPersistStorage_SaveCompleted(This->dataCache_PersistStg, pStgNew);
1584 /************************************************************************
1585 * DefaultHandler_IPersistStorage_HandsOffStorage
1588 static HRESULT WINAPI DefaultHandler_IPersistStorage_HandsOffStorage(
1589 IPersistStorage* iface)
1591 DefaultHandler *This = impl_from_IPersistStorage(iface);
1593 return IPersistStorage_HandsOffStorage(This->dataCache_PersistStg);
1598 * Virtual function tables for the DefaultHandler class.
1600 static const IOleObjectVtbl DefaultHandler_IOleObject_VTable =
1602 DefaultHandler_QueryInterface,
1603 DefaultHandler_AddRef,
1604 DefaultHandler_Release,
1605 DefaultHandler_SetClientSite,
1606 DefaultHandler_GetClientSite,
1607 DefaultHandler_SetHostNames,
1608 DefaultHandler_Close,
1609 DefaultHandler_SetMoniker,
1610 DefaultHandler_GetMoniker,
1611 DefaultHandler_InitFromData,
1612 DefaultHandler_GetClipboardData,
1613 DefaultHandler_DoVerb,
1614 DefaultHandler_EnumVerbs,
1615 DefaultHandler_Update,
1616 DefaultHandler_IsUpToDate,
1617 DefaultHandler_GetUserClassID,
1618 DefaultHandler_GetUserType,
1619 DefaultHandler_SetExtent,
1620 DefaultHandler_GetExtent,
1621 DefaultHandler_Advise,
1622 DefaultHandler_Unadvise,
1623 DefaultHandler_EnumAdvise,
1624 DefaultHandler_GetMiscStatus,
1625 DefaultHandler_SetColorScheme
1628 static const IUnknownVtbl DefaultHandler_NDIUnknown_VTable =
1630 DefaultHandler_NDIUnknown_QueryInterface,
1631 DefaultHandler_NDIUnknown_AddRef,
1632 DefaultHandler_NDIUnknown_Release,
1635 static const IDataObjectVtbl DefaultHandler_IDataObject_VTable =
1637 DefaultHandler_IDataObject_QueryInterface,
1638 DefaultHandler_IDataObject_AddRef,
1639 DefaultHandler_IDataObject_Release,
1640 DefaultHandler_GetData,
1641 DefaultHandler_GetDataHere,
1642 DefaultHandler_QueryGetData,
1643 DefaultHandler_GetCanonicalFormatEtc,
1644 DefaultHandler_SetData,
1645 DefaultHandler_EnumFormatEtc,
1646 DefaultHandler_DAdvise,
1647 DefaultHandler_DUnadvise,
1648 DefaultHandler_EnumDAdvise
1651 static const IRunnableObjectVtbl DefaultHandler_IRunnableObject_VTable =
1653 DefaultHandler_IRunnableObject_QueryInterface,
1654 DefaultHandler_IRunnableObject_AddRef,
1655 DefaultHandler_IRunnableObject_Release,
1656 DefaultHandler_GetRunningClass,
1658 DefaultHandler_IsRunning,
1659 DefaultHandler_LockRunning,
1660 DefaultHandler_SetContainedObject
1663 static const IAdviseSinkVtbl DefaultHandler_IAdviseSink_VTable =
1665 DefaultHandler_IAdviseSink_QueryInterface,
1666 DefaultHandler_IAdviseSink_AddRef,
1667 DefaultHandler_IAdviseSink_Release,
1668 DefaultHandler_IAdviseSink_OnDataChange,
1669 DefaultHandler_IAdviseSink_OnViewChange,
1670 DefaultHandler_IAdviseSink_OnRename,
1671 DefaultHandler_IAdviseSink_OnSave,
1672 DefaultHandler_IAdviseSink_OnClose
1675 static const IPersistStorageVtbl DefaultHandler_IPersistStorage_VTable =
1677 DefaultHandler_IPersistStorage_QueryInterface,
1678 DefaultHandler_IPersistStorage_AddRef,
1679 DefaultHandler_IPersistStorage_Release,
1680 DefaultHandler_IPersistStorage_GetClassID,
1681 DefaultHandler_IPersistStorage_IsDirty,
1682 DefaultHandler_IPersistStorage_InitNew,
1683 DefaultHandler_IPersistStorage_Load,
1684 DefaultHandler_IPersistStorage_Save,
1685 DefaultHandler_IPersistStorage_SaveCompleted,
1686 DefaultHandler_IPersistStorage_HandsOffStorage
1689 /*********************************************************
1690 * Methods implementation for the DefaultHandler class.
1692 static DefaultHandler* DefaultHandler_Construct(
1694 LPUNKNOWN pUnkOuter)
1696 DefaultHandler* This = NULL;
1700 * Allocate space for the object.
1702 This = HeapAlloc(GetProcessHeap(), 0, sizeof(DefaultHandler));
1707 This->lpVtbl = &DefaultHandler_IOleObject_VTable;
1708 This->lpvtblIUnknown = &DefaultHandler_NDIUnknown_VTable;
1709 This->lpvtblIDataObject = &DefaultHandler_IDataObject_VTable;
1710 This->lpvtblIRunnableObject = &DefaultHandler_IRunnableObject_VTable;
1711 This->lpvtblIAdviseSink = &DefaultHandler_IAdviseSink_VTable;
1712 This->lpvtblIPersistStorage = &DefaultHandler_IPersistStorage_VTable;
1715 * Start with one reference count. The caller of this function
1716 * must release the interface pointer when it is done.
1721 * Initialize the outer unknown
1722 * We don't keep a reference on the outer unknown since, the way
1723 * aggregation works, our lifetime is at least as large as its
1727 pUnkOuter = (IUnknown*)&This->lpvtblIUnknown;
1729 This->outerUnknown = pUnkOuter;
1732 * Create a datacache object.
1733 * We aggregate with the datacache. Make sure we pass our outer
1734 * unknown as the datacache's outer unknown.
1736 hr = CreateDataCache(This->outerUnknown,
1739 (void**)&This->dataCache);
1741 hr = IUnknown_QueryInterface(This->dataCache, &IID_IPersistStorage, (void**)&This->dataCache_PersistStg);
1743 ERR("Unexpected error creating data cache\n");
1745 * Initialize the other data members of the class.
1747 This->clsid = *clsid;
1748 This->clientSite = NULL;
1749 This->oleAdviseHolder = NULL;
1750 This->dataAdviseHolder = NULL;
1751 This->containerApp = NULL;
1752 This->containerObj = NULL;
1753 This->pOleDelegate = NULL;
1754 This->pPSDelegate = NULL;
1755 This->pDataDelegate = NULL;
1757 This->dwAdvConn = 0;
1762 static void DefaultHandler_Destroy(
1763 DefaultHandler* This)
1765 /* release delegates */
1766 DefaultHandler_Stop(This);
1768 /* Free the strings idenfitying the object */
1769 HeapFree( GetProcessHeap(), 0, This->containerApp );
1770 This->containerApp = NULL;
1771 HeapFree( GetProcessHeap(), 0, This->containerObj );
1772 This->containerObj = NULL;
1774 /* Release our reference to the data cache. */
1775 if (This->dataCache)
1777 IPersistStorage_Release(This->dataCache_PersistStg);
1778 IUnknown_Release(This->dataCache);
1779 This->dataCache_PersistStg = NULL;
1780 This->dataCache = NULL;
1783 /* Same thing for the client site. */
1784 if (This->clientSite)
1786 IOleClientSite_Release(This->clientSite);
1787 This->clientSite = NULL;
1790 /* And the advise holder. */
1791 if (This->oleAdviseHolder)
1793 IOleAdviseHolder_Release(This->oleAdviseHolder);
1794 This->oleAdviseHolder = NULL;
1797 /* And the data advise holder. */
1798 if (This->dataAdviseHolder)
1800 IDataAdviseHolder_Release(This->dataAdviseHolder);
1801 This->dataAdviseHolder = NULL;
1804 /* Free the actual default handler structure. */
1805 HeapFree(GetProcessHeap(), 0, This);
1808 /******************************************************************************
1809 * OleCreateDefaultHandler [OLE32.@]
1811 HRESULT WINAPI OleCreateDefaultHandler(
1813 LPUNKNOWN pUnkOuter,
1817 DefaultHandler* newHandler = NULL;
1820 TRACE("(%s, %p, %s, %p)\n", debugstr_guid(clsid), pUnkOuter, debugstr_guid(riid), ppvObj);
1831 * If This handler is constructed for aggregation, make sure
1832 * the caller is requesting the IUnknown interface.
1833 * This is necessary because it's the only time the non-delegating
1834 * IUnknown pointer can be returned to the outside.
1836 if (pUnkOuter && !IsEqualIID(&IID_IUnknown, riid))
1837 return CLASS_E_NOAGGREGATION;
1840 * Try to construct a new instance of the class.
1842 newHandler = DefaultHandler_Construct(clsid, pUnkOuter);
1845 return E_OUTOFMEMORY;
1848 * Make sure it supports the interface required by the caller.
1850 hr = IUnknown_QueryInterface((IUnknown*)&newHandler->lpvtblIUnknown, riid, ppvObj);
1853 * Release the reference obtained in the constructor. If
1854 * the QueryInterface was unsuccessful, it will free the class.
1856 IUnknown_Release((IUnknown*)&newHandler->lpvtblIUnknown);