2 * Implementation of hyperlinking (hlink.dll)
4 * Copyright 2005 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "hlink_private.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(hlink);
30 #define HLINK_SAVE_MAGIC 0x00000002
31 #define HLINK_SAVE_MONIKER_PRESENT 0x01
32 #define HLINK_SAVE_MONIKER_IS_ABSOLUTE 0x02
33 #define HLINK_SAVE_LOCATION_PRESENT 0x08
34 #define HLINK_SAVE_FRIENDLY_PRESENT 0x10
35 /* 0x20, 0x40 unknown */
36 #define HLINK_SAVE_TARGET_FRAME_PRESENT 0x80
38 #define HLINK_SAVE_ALL (HLINK_SAVE_TARGET_FRAME_PRESENT|HLINK_SAVE_FRIENDLY_PRESENT|HLINK_SAVE_LOCATION_PRESENT|0x04|HLINK_SAVE_MONIKER_IS_ABSOLUTE|HLINK_SAVE_MONIKER_PRESENT)
45 IPersistStream IPersistStream_iface;
46 IDataObject IDataObject_iface;
50 LPWSTR TargetFrameName;
57 static inline HlinkImpl *impl_from_IHlink(IHlink *iface)
59 return CONTAINING_RECORD(iface, HlinkImpl, IHlink_iface);
63 static inline HlinkImpl* impl_from_IPersistStream( IPersistStream* iface)
65 return CONTAINING_RECORD(iface, HlinkImpl, IPersistStream_iface);
68 static inline HlinkImpl* impl_from_IDataObject( IDataObject* iface)
70 return CONTAINING_RECORD(iface, HlinkImpl, IDataObject_iface);
73 static HRESULT __GetMoniker(HlinkImpl* This, IMoniker** moniker,
78 if (ref_type == HLINKGETREF_DEFAULT)
79 ref_type = HLINKGETREF_RELATIVE;
83 DWORD mktype = MKSYS_NONE;
85 hres = IMoniker_IsSystemMoniker(This->Moniker, &mktype);
86 if (hres == S_OK && mktype != MKSYS_NONE)
88 *moniker = This->Moniker;
89 IMoniker_AddRef(*moniker);
94 if (ref_type == HLINKGETREF_ABSOLUTE && This->Site)
96 IMoniker *hls_moniker;
98 hres = IHlinkSite_GetMoniker(This->Site, This->SiteData,
99 OLEGETMONIKER_FORCEASSIGN, OLEWHICHMK_CONTAINER, &hls_moniker);
105 hres = IMoniker_ComposeWith(hls_moniker, This->Moniker, FALSE,
107 IMoniker_Release(hls_moniker);
111 *moniker = hls_moniker;
115 *moniker = This->Moniker;
117 IMoniker_AddRef(*moniker);
122 static HRESULT WINAPI IHlink_fnQueryInterface(IHlink* iface, REFIID riid,
125 HlinkImpl *This = impl_from_IHlink(iface);
127 TRACE ("(%p)->(%s,%p)\n", This, debugstr_guid (riid), ppvObj);
131 if (IsEqualIID(riid, &IID_IUnknown) || (IsEqualIID(riid, &IID_IHlink)))
133 else if (IsEqualIID(riid, &IID_IPersistStream))
134 *ppvObj = &This->IPersistStream_iface;
135 else if (IsEqualIID(riid, &IID_IDataObject))
136 *ppvObj = &This->IDataObject_iface;
140 IUnknown_AddRef((IUnknown*)(*ppvObj));
143 return E_NOINTERFACE;
146 static ULONG WINAPI IHlink_fnAddRef (IHlink* iface)
148 HlinkImpl *This = impl_from_IHlink(iface);
149 ULONG refCount = InterlockedIncrement(&This->ref);
151 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
156 static ULONG WINAPI IHlink_fnRelease (IHlink* iface)
158 HlinkImpl *This = impl_from_IHlink(iface);
159 ULONG refCount = InterlockedDecrement(&This->ref);
161 TRACE("(%p)->(count=%u)\n", This, refCount + 1);
165 TRACE("-- destroying IHlink (%p)\n", This);
166 heap_free(This->FriendlyName);
167 heap_free(This->TargetFrameName);
168 heap_free(This->Location);
170 IMoniker_Release(This->Moniker);
172 IHlinkSite_Release(This->Site);
177 static HRESULT WINAPI IHlink_fnSetHlinkSite( IHlink* iface,
178 IHlinkSite* pihlSite, DWORD dwSiteData)
180 HlinkImpl *This = impl_from_IHlink(iface);
182 TRACE("(%p)->(%p %i)\n", This, pihlSite, dwSiteData);
185 IHlinkSite_Release(This->Site);
187 This->Site = pihlSite;
189 IHlinkSite_AddRef(This->Site);
191 This->SiteData = dwSiteData;
196 static HRESULT WINAPI IHlink_fnGetHlinkSite( IHlink* iface,
197 IHlinkSite** ppihlSite, DWORD *pdwSiteData)
199 HlinkImpl *This = impl_from_IHlink(iface);
201 TRACE("(%p)->(%p %p)\n", This, ppihlSite, pdwSiteData);
203 *ppihlSite = This->Site;
206 IHlinkSite_AddRef(This->Site);
207 *pdwSiteData = This->SiteData;
213 static HRESULT WINAPI IHlink_fnSetMonikerReference( IHlink* iface,
214 DWORD rfHLSETF, IMoniker *pmkTarget, LPCWSTR pwzLocation)
216 HlinkImpl *This = impl_from_IHlink(iface);
218 TRACE("(%p)->(%i %p %s)\n", This, rfHLSETF, pmkTarget,
219 debugstr_w(pwzLocation));
223 if(!(rfHLSETF & (HLINKSETF_TARGET | HLINKSETF_LOCATION)))
226 if(rfHLSETF & HLINKSETF_TARGET){
228 IMoniker_Release(This->Moniker);
230 This->Moniker = pmkTarget;
234 LPOLESTR display_name;
235 IMoniker_AddRef(This->Moniker);
236 CreateBindCtx( 0, &pbc);
237 IMoniker_GetDisplayName(This->Moniker, pbc, NULL, &display_name);
238 IBindCtx_Release(pbc);
239 This->absolute = display_name && strchrW(display_name, ':');
240 CoTaskMemFree(display_name);
244 if(rfHLSETF & HLINKSETF_LOCATION){
245 heap_free(This->Location);
246 This->Location = hlink_strdupW( pwzLocation );
252 static HRESULT WINAPI IHlink_fnSetStringReference(IHlink* iface,
253 DWORD grfHLSETF, LPCWSTR pwzTarget, LPCWSTR pwzLocation)
255 HlinkImpl *This = impl_from_IHlink(iface);
257 TRACE("(%p)->(%i %s %s)\n", This, grfHLSETF, debugstr_w(pwzTarget),
258 debugstr_w(pwzLocation));
260 if(grfHLSETF > (HLINKSETF_TARGET | HLINKSETF_LOCATION) &&
261 grfHLSETF < -(HLINKSETF_TARGET | HLINKSETF_LOCATION))
264 if (grfHLSETF & HLINKSETF_TARGET)
268 IMoniker_Release(This->Moniker);
269 This->Moniker = NULL;
271 if (pwzTarget && *pwzTarget)
274 IBindCtx *pbc = NULL;
278 r = CreateBindCtx(0, &pbc);
280 return E_OUTOFMEMORY;
282 r = MkParseDisplayName(pbc, pwzTarget, &eaten, &pMon);
283 IBindCtx_Release(pbc);
287 LPCWSTR p = strchrW(pwzTarget, ':');
288 if (p && (p - pwzTarget > 1))
289 r = CreateURLMoniker(NULL, pwzTarget, &pMon);
291 r = CreateFileMoniker(pwzTarget, &pMon);
294 ERR("couldn't create moniker for %s, failed with error 0x%08x\n",
295 debugstr_w(pwzTarget), r);
300 IHlink_SetMonikerReference(iface, HLINKSETF_TARGET, pMon, NULL);
301 IMoniker_Release(pMon);
305 if (grfHLSETF & HLINKSETF_LOCATION)
307 heap_free(This->Location);
308 This->Location = NULL;
309 if (pwzLocation && *pwzLocation)
310 This->Location = hlink_strdupW( pwzLocation );
316 static HRESULT WINAPI IHlink_fnGetMonikerReference(IHlink* iface,
317 DWORD dwWhichRef, IMoniker **ppimkTarget, LPWSTR *ppwzLocation)
319 HlinkImpl *This = impl_from_IHlink(iface);
321 TRACE("(%p) -> (%i %p %p)\n", This, dwWhichRef, ppimkTarget,
326 HRESULT hres = __GetMoniker(This, ppimkTarget, dwWhichRef);
330 *ppwzLocation = NULL;
336 IHlink_GetStringReference(iface, dwWhichRef, NULL, ppwzLocation);
341 static HRESULT WINAPI IHlink_fnGetStringReference (IHlink* iface,
342 DWORD dwWhichRef, LPWSTR *ppwzTarget, LPWSTR *ppwzLocation)
344 HlinkImpl *This = impl_from_IHlink(iface);
346 TRACE("(%p) -> (%i %p %p)\n", This, dwWhichRef, ppwzTarget, ppwzLocation);
348 if(dwWhichRef != -1 && dwWhichRef & ~(HLINKGETREF_DEFAULT | HLINKGETREF_ABSOLUTE | HLINKGETREF_RELATIVE))
353 *ppwzLocation = NULL;
360 HRESULT hres = __GetMoniker(This, &mon, dwWhichRef);
364 *ppwzLocation = NULL;
371 CreateBindCtx( 0, &pbc);
372 IMoniker_GetDisplayName(mon, pbc, NULL, ppwzTarget);
373 IBindCtx_Release(pbc);
374 IMoniker_Release(mon);
380 *ppwzLocation = hlink_co_strdupW( This->Location );
382 TRACE("(Target: %s Location: %s)\n",
383 (ppwzTarget)?debugstr_w(*ppwzTarget):"<NULL>",
384 (ppwzLocation)?debugstr_w(*ppwzLocation):"<NULL>");
389 static HRESULT WINAPI IHlink_fnSetFriendlyName (IHlink *iface,
390 LPCWSTR pwzFriendlyName)
392 HlinkImpl *This = impl_from_IHlink(iface);
394 TRACE("(%p) -> (%s)\n", This, debugstr_w(pwzFriendlyName));
396 heap_free(This->FriendlyName);
397 This->FriendlyName = hlink_strdupW( pwzFriendlyName );
402 static HRESULT WINAPI IHlink_fnGetFriendlyName (IHlink* iface,
403 DWORD grfHLFNAMEF, LPWSTR* ppwzFriendlyName)
405 HlinkImpl *This = impl_from_IHlink(iface);
407 TRACE("(%p) -> (%i %p)\n", This, grfHLFNAMEF, ppwzFriendlyName);
409 /* FIXME: Only using explicitly set and cached friendly names */
411 if (This->FriendlyName)
412 *ppwzFriendlyName = hlink_co_strdupW( This->FriendlyName );
416 HRESULT hres = __GetMoniker(This, &moniker, HLINKGETREF_DEFAULT);
419 *ppwzFriendlyName = NULL;
425 CreateBindCtx(0, &bcxt);
427 IMoniker_GetDisplayName(moniker, bcxt, NULL, ppwzFriendlyName);
428 IBindCtx_Release(bcxt);
429 IMoniker_Release(moniker);
432 *ppwzFriendlyName = NULL;
438 static HRESULT WINAPI IHlink_fnSetTargetFrameName(IHlink* iface,
439 LPCWSTR pwzTargetFramename)
441 HlinkImpl *This = impl_from_IHlink(iface);
442 TRACE("(%p)->(%s)\n", This, debugstr_w(pwzTargetFramename));
444 heap_free(This->TargetFrameName);
445 This->TargetFrameName = hlink_strdupW( pwzTargetFramename );
450 static HRESULT WINAPI IHlink_fnGetTargetFrameName(IHlink* iface,
451 LPWSTR *ppwzTargetFrameName)
453 HlinkImpl *This = impl_from_IHlink(iface);
455 TRACE("(%p)->(%p)\n", This, ppwzTargetFrameName);
457 if(!This->TargetFrameName) {
458 *ppwzTargetFrameName = NULL;
462 *ppwzTargetFrameName = hlink_co_strdupW( This->TargetFrameName );
463 if(!*ppwzTargetFrameName)
464 return E_OUTOFMEMORY;
469 static HRESULT WINAPI IHlink_fnGetMiscStatus(IHlink* iface, DWORD* pdwStatus)
475 static HRESULT WINAPI IHlink_fnNavigate(IHlink* iface, DWORD grfHLNF, LPBC pbc,
476 IBindStatusCallback *pbsc, IHlinkBrowseContext *phbc)
478 HlinkImpl *This = impl_from_IHlink(iface);
479 IMoniker *mon = NULL;
482 FIXME("Semi-Stub:(%p)->(%i %p %p %p)\n", This, grfHLNF, pbc, pbsc, phbc);
484 r = __GetMoniker(This, &mon, HLINKGETREF_ABSOLUTE);
485 TRACE("Moniker %p\n", mon);
490 IUnknown *unk = NULL;
491 IHlinkTarget *target;
493 CreateBindCtx(0, &bcxt);
495 RegisterBindStatusCallback(bcxt, pbsc, NULL, 0);
497 r = IMoniker_BindToObject(mon, bcxt, NULL, &IID_IUnknown, (void**)&unk);
500 r = IUnknown_QueryInterface(unk, &IID_IHlinkTarget, (void**)&target);
501 IUnknown_Release(unk);
505 IHlinkTarget_SetBrowseContext(target, phbc);
506 r = IHlinkTarget_Navigate(target, grfHLNF, This->Location);
507 IHlinkTarget_Release(target);
511 static const WCHAR szOpen[] = {'o','p','e','n',0};
512 LPWSTR target = NULL;
514 r = IHlink_GetStringReference(iface, HLINKGETREF_DEFAULT, &target, NULL);
515 if (SUCCEEDED(r) && target)
517 ShellExecuteW(NULL, szOpen, target, NULL, NULL, SW_SHOW);
518 CoTaskMemFree(target);
522 RevokeBindStatusCallback(bcxt, pbsc);
524 IBindCtx_Release(bcxt);
525 IMoniker_Release(mon);
529 IHlinkSite_OnNavigationComplete(This->Site, This->SiteData, 0, r, NULL);
531 TRACE("Finished Navigation\n");
535 static HRESULT WINAPI IHlink_fnSetAdditionalParams(IHlink* iface,
536 LPCWSTR pwzAdditionalParams)
538 TRACE("Not implemented in native IHlink\n");
542 static HRESULT WINAPI IHlink_fnGetAdditionalParams(IHlink* iface,
543 LPWSTR* ppwzAdditionalParams)
545 TRACE("Not implemented in native IHlink\n");
549 static const IHlinkVtbl hlvt =
551 IHlink_fnQueryInterface,
554 IHlink_fnSetHlinkSite,
555 IHlink_fnGetHlinkSite,
556 IHlink_fnSetMonikerReference,
557 IHlink_fnGetMonikerReference,
558 IHlink_fnSetStringReference,
559 IHlink_fnGetStringReference,
560 IHlink_fnSetFriendlyName,
561 IHlink_fnGetFriendlyName,
562 IHlink_fnSetTargetFrameName,
563 IHlink_fnGetTargetFrameName,
564 IHlink_fnGetMiscStatus,
566 IHlink_fnSetAdditionalParams,
567 IHlink_fnGetAdditionalParams
570 static HRESULT WINAPI IDataObject_fnQueryInterface(IDataObject* iface,
571 REFIID riid, LPVOID *ppvObj)
573 HlinkImpl *This = impl_from_IDataObject(iface);
575 return IHlink_QueryInterface(&This->IHlink_iface, riid, ppvObj);
578 static ULONG WINAPI IDataObject_fnAddRef (IDataObject* iface)
580 HlinkImpl *This = impl_from_IDataObject(iface);
582 return IHlink_AddRef(&This->IHlink_iface);
585 static ULONG WINAPI IDataObject_fnRelease (IDataObject* iface)
587 HlinkImpl *This = impl_from_IDataObject(iface);
589 return IHlink_Release(&This->IHlink_iface);
592 static HRESULT WINAPI IDataObject_fnGetData(IDataObject* iface,
593 FORMATETC* pformatetcIn, STGMEDIUM* pmedium)
599 static HRESULT WINAPI IDataObject_fnGetDataHere(IDataObject* iface,
600 FORMATETC* pformatetc, STGMEDIUM* pmedium)
606 static HRESULT WINAPI IDataObject_fnQueryGetData(IDataObject* iface,
607 FORMATETC* pformatetc)
613 static HRESULT WINAPI IDataObject_fnGetConicalFormatEtc(IDataObject* iface,
614 FORMATETC* pformatetcIn, FORMATETC* pformatetcOut)
620 static HRESULT WINAPI IDataObject_fnSetData(IDataObject* iface,
621 FORMATETC* pformatetc, STGMEDIUM* pmedium, BOOL fRelease)
627 static HRESULT WINAPI IDataObject_fnEnumFormatEtc(IDataObject* iface,
628 DWORD dwDirection, IEnumFORMATETC** ppenumFormatEtc)
634 static HRESULT WINAPI IDataObject_fnDAdvise(IDataObject* iface,
635 FORMATETC* pformatetc, DWORD advf, IAdviseSink* pAdvSink,
636 DWORD* pdwConnection)
642 static HRESULT WINAPI IDataObject_fnDUnadvise(IDataObject* iface,
649 static HRESULT WINAPI IDataObject_fnEnumDAdvise(IDataObject* iface,
650 IEnumSTATDATA** ppenumAdvise)
656 static const IDataObjectVtbl dovt =
658 IDataObject_fnQueryInterface,
659 IDataObject_fnAddRef,
660 IDataObject_fnRelease,
661 IDataObject_fnGetData,
662 IDataObject_fnGetDataHere,
663 IDataObject_fnQueryGetData,
664 IDataObject_fnGetConicalFormatEtc,
665 IDataObject_fnSetData,
666 IDataObject_fnEnumFormatEtc,
667 IDataObject_fnDAdvise,
668 IDataObject_fnDUnadvise,
669 IDataObject_fnEnumDAdvise
672 static HRESULT WINAPI IPersistStream_fnQueryInterface(IPersistStream* iface,
673 REFIID riid, LPVOID *ppvObj)
675 HlinkImpl *This = impl_from_IPersistStream(iface);
676 TRACE("(%p)\n", This);
677 return IHlink_QueryInterface(&This->IHlink_iface, riid, ppvObj);
680 static ULONG WINAPI IPersistStream_fnAddRef (IPersistStream* iface)
682 HlinkImpl *This = impl_from_IPersistStream(iface);
683 TRACE("(%p)\n", This);
684 return IHlink_AddRef(&This->IHlink_iface);
687 static ULONG WINAPI IPersistStream_fnRelease (IPersistStream* iface)
689 HlinkImpl *This = impl_from_IPersistStream(iface);
690 TRACE("(%p)\n", This);
691 return IHlink_Release(&This->IHlink_iface);
694 static HRESULT WINAPI IPersistStream_fnGetClassID(IPersistStream* iface,
697 HlinkImpl *This = impl_from_IPersistStream(iface);
698 TRACE("(%p)\n", This);
699 *pClassID = CLSID_StdHlink;
703 static HRESULT WINAPI IPersistStream_fnIsDirty(IPersistStream* iface)
709 static HRESULT write_hlink_string(IStream *pStm, LPCWSTR str)
714 TRACE("(%p, %s)\n", pStm, debugstr_w(str));
716 len = strlenW(str) + 1;
718 hr = IStream_Write(pStm, &len, sizeof(len), NULL);
719 if (FAILED(hr)) return hr;
721 hr = IStream_Write(pStm, str, len * sizeof(WCHAR), NULL);
722 if (FAILED(hr)) return hr;
727 static inline ULONG size_hlink_string(LPCWSTR str)
729 return sizeof(DWORD) + (strlenW(str) + 1) * sizeof(WCHAR);
732 static HRESULT read_hlink_string(IStream *pStm, LPWSTR *out_str)
739 hr = IStream_Read(pStm, &len, sizeof(len), &read);
740 if (FAILED(hr)) return hr;
741 if (read != sizeof(len)) return STG_E_READFAULT;
743 TRACE("read len %d\n", len);
745 str = heap_alloc(len * sizeof(WCHAR));
746 if (!str) return E_OUTOFMEMORY;
748 hr = IStream_Read(pStm, str, len * sizeof(WCHAR), &read);
754 if (read != len * sizeof(WCHAR))
757 return STG_E_READFAULT;
759 TRACE("read string %s\n", debugstr_w(str));
765 static HRESULT WINAPI IPersistStream_fnLoad(IPersistStream* iface,
771 HlinkImpl *This = impl_from_IPersistStream(iface);
773 r = IStream_Read(pStm, hdr, sizeof(hdr), &read);
774 if (read != sizeof(hdr) || (hdr[0] != HLINK_SAVE_MAGIC))
779 if (hdr[1] & ~HLINK_SAVE_ALL)
780 FIXME("unknown flag(s) 0x%x\n", hdr[1] & ~HLINK_SAVE_ALL);
782 if (hdr[1] & HLINK_SAVE_TARGET_FRAME_PRESENT)
784 TRACE("loading target frame name\n");
785 r = read_hlink_string(pStm, &This->TargetFrameName);
786 if (FAILED(r)) goto end;
789 if (hdr[1] & HLINK_SAVE_FRIENDLY_PRESENT)
791 TRACE("loading target friendly name\n");
793 FIXME("0x4 flag not present with friendly name flag - not sure what this means\n");
794 r = read_hlink_string(pStm, &This->FriendlyName);
795 if (FAILED(r)) goto end;
798 if (hdr[1] & HLINK_SAVE_MONIKER_PRESENT)
800 TRACE("loading moniker\n");
801 r = OleLoadFromStream(pStm, &IID_IMoniker, (LPVOID*)&(This->Moniker));
804 This->absolute = (hdr[1] & HLINK_SAVE_MONIKER_IS_ABSOLUTE) != 0;
807 if (hdr[1] & HLINK_SAVE_LOCATION_PRESENT)
809 TRACE("loading location\n");
810 r = read_hlink_string(pStm, &This->Location);
811 if (FAILED(r)) goto end;
815 TRACE("Load Result 0x%x (%p)\n", r, This->Moniker);
820 static HRESULT WINAPI IPersistStream_fnSave(IPersistStream* iface,
821 IStream* pStm, BOOL fClearDirty)
824 HlinkImpl *This = impl_from_IPersistStream(iface);
828 TRACE("(%p) Moniker(%p)\n", This, This->Moniker);
830 r = __GetMoniker(This, &moniker, HLINKGETREF_DEFAULT);
835 hdr[0] = HLINK_SAVE_MAGIC;
839 hdr[1] |= HLINK_SAVE_MONIKER_PRESENT;
841 hdr[1] |= HLINK_SAVE_MONIKER_IS_ABSOLUTE;
843 hdr[1] |= HLINK_SAVE_LOCATION_PRESENT;
844 if (This->FriendlyName)
845 hdr[1] |= HLINK_SAVE_FRIENDLY_PRESENT | 4 /* FIXME */;
846 if (This->TargetFrameName)
847 hdr[1] |= HLINK_SAVE_TARGET_FRAME_PRESENT;
849 IStream_Write(pStm, hdr, sizeof(hdr), NULL);
851 if (This->TargetFrameName)
853 r = write_hlink_string(pStm, This->TargetFrameName);
854 if (FAILED(r)) goto end;
857 if (This->FriendlyName)
859 r = write_hlink_string(pStm, This->FriendlyName);
860 if (FAILED(r)) goto end;
865 IPersistStream* monstream;
868 IMoniker_QueryInterface(moniker, &IID_IPersistStream,
869 (LPVOID*)&monstream);
872 r = OleSaveToStream(monstream, pStm);
873 IPersistStream_Release(monstream);
875 if (FAILED(r)) goto end;
880 r = write_hlink_string(pStm, This->Location);
881 if (FAILED(r)) goto end;
885 if (moniker) IMoniker_Release(moniker);
886 TRACE("Save Result 0x%x\n", r);
891 static HRESULT WINAPI IPersistStream_fnGetSizeMax(IPersistStream* iface,
892 ULARGE_INTEGER* pcbSize)
895 HlinkImpl *This = impl_from_IPersistStream(iface);
898 TRACE("(%p) Moniker(%p)\n", This, This->Moniker);
900 pcbSize->QuadPart = sizeof(DWORD)*2;
902 if (This->TargetFrameName)
903 pcbSize->QuadPart += size_hlink_string(This->TargetFrameName);
905 if (This->FriendlyName)
906 pcbSize->QuadPart += size_hlink_string(This->FriendlyName);
908 r = __GetMoniker(This, &moniker, HLINKGETREF_DEFAULT);
915 IPersistStream* monstream = NULL;
916 IMoniker_QueryInterface(moniker, &IID_IPersistStream,
917 (LPVOID*)&monstream);
920 ULARGE_INTEGER mon_size;
921 r = IPersistStream_GetSizeMax(monstream, &mon_size);
922 pcbSize->QuadPart += mon_size.QuadPart;
923 IPersistStream_Release(monstream);
925 IMoniker_Release(moniker);
929 pcbSize->QuadPart += size_hlink_string(This->Location);
934 static const IPersistStreamVtbl psvt =
936 IPersistStream_fnQueryInterface,
937 IPersistStream_fnAddRef,
938 IPersistStream_fnRelease,
939 IPersistStream_fnGetClassID,
940 IPersistStream_fnIsDirty,
941 IPersistStream_fnLoad,
942 IPersistStream_fnSave,
943 IPersistStream_fnGetSizeMax,
946 HRESULT HLink_Constructor(IUnknown *pUnkOuter, REFIID riid, void **ppv)
950 TRACE("unkOut=%p riid=%s\n", pUnkOuter, debugstr_guid(riid));
954 return CLASS_E_NOAGGREGATION;
956 hl = heap_alloc_zero(sizeof(HlinkImpl));
958 return E_OUTOFMEMORY;
961 hl->IHlink_iface.lpVtbl = &hlvt;
962 hl->IPersistStream_iface.lpVtbl = &psvt;
963 hl->IDataObject_iface.lpVtbl = &dovt;