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)
40 static const IHlinkVtbl hlvt
;
41 static const IPersistStreamVtbl psvt
;
42 static const IDataObjectVtbl dovt
;
46 const IHlinkVtbl
*lpVtbl
;
49 const IPersistStreamVtbl
*lpPSVtbl
;
50 const IDataObjectVtbl
*lpDOVtbl
;
54 LPWSTR TargetFrameName
;
62 static inline HlinkImpl
* HlinkImpl_from_IPersistStream( IPersistStream
* iface
)
64 return (HlinkImpl
*) ((CHAR
*)iface
- FIELD_OFFSET(HlinkImpl
, lpPSVtbl
));
67 static inline HlinkImpl
* HlinkImpl_from_IDataObject( IDataObject
* iface
)
69 return (HlinkImpl
*) ((CHAR
*)iface
- FIELD_OFFSET(HlinkImpl
, lpDOVtbl
));
72 static HRESULT
__GetMoniker(HlinkImpl
* This
, IMoniker
** moniker
,
77 if (ref_type
== HLINKGETREF_DEFAULT
)
78 ref_type
= HLINKGETREF_RELATIVE
;
80 if (ref_type
== HLINKGETREF_ABSOLUTE
&& This
->Site
)
82 IMoniker
*hls_moniker
;
84 hres
= IHlinkSite_GetMoniker(This
->Site
, This
->SiteData
,
85 OLEGETMONIKER_FORCEASSIGN
, OLEWHICHMK_CONTAINER
, &hls_moniker
);
91 hres
= IMoniker_ComposeWith(hls_moniker
, This
->Moniker
, FALSE
,
93 IMoniker_Release(hls_moniker
);
97 *moniker
= hls_moniker
;
101 *moniker
= This
->Moniker
;
103 IMoniker_AddRef(*moniker
);
108 HRESULT WINAPI
HLink_Constructor(IUnknown
*pUnkOuter
, REFIID riid
,
113 TRACE("unkOut=%p riid=%s\n", pUnkOuter
, debugstr_guid(riid
));
117 return CLASS_E_NOAGGREGATION
;
119 hl
= heap_alloc_zero(sizeof(HlinkImpl
));
121 return E_OUTOFMEMORY
;
125 hl
->lpPSVtbl
= &psvt
;
126 hl
->lpDOVtbl
= &dovt
;
132 static HRESULT WINAPI
IHlink_fnQueryInterface(IHlink
* iface
, REFIID riid
,
135 HlinkImpl
*This
= (HlinkImpl
*)iface
;
137 TRACE ("(%p)->(%s,%p)\n", This
, debugstr_guid (riid
), ppvObj
);
141 if (IsEqualIID(riid
, &IID_IUnknown
) || (IsEqualIID(riid
, &IID_IHlink
)))
143 else if (IsEqualIID(riid
, &IID_IPersistStream
))
144 *ppvObj
= &(This
->lpPSVtbl
);
145 else if (IsEqualIID(riid
, &IID_IDataObject
))
146 *ppvObj
= &(This
->lpDOVtbl
);
150 IUnknown_AddRef((IUnknown
*)(*ppvObj
));
153 return E_NOINTERFACE
;
156 static ULONG WINAPI
IHlink_fnAddRef (IHlink
* iface
)
158 HlinkImpl
*This
= (HlinkImpl
*)iface
;
159 ULONG refCount
= InterlockedIncrement(&This
->ref
);
161 TRACE("(%p)->(count=%u)\n", This
, refCount
- 1);
166 static ULONG WINAPI
IHlink_fnRelease (IHlink
* iface
)
168 HlinkImpl
*This
= (HlinkImpl
*)iface
;
169 ULONG refCount
= InterlockedDecrement(&This
->ref
);
171 TRACE("(%p)->(count=%u)\n", This
, refCount
+ 1);
175 TRACE("-- destroying IHlink (%p)\n", This
);
176 heap_free(This
->FriendlyName
);
177 heap_free(This
->TargetFrameName
);
178 heap_free(This
->Location
);
180 IMoniker_Release(This
->Moniker
);
182 IHlinkSite_Release(This
->Site
);
187 static HRESULT WINAPI
IHlink_fnSetHlinkSite( IHlink
* iface
,
188 IHlinkSite
* pihlSite
, DWORD dwSiteData
)
190 HlinkImpl
*This
= (HlinkImpl
*)iface
;
192 TRACE("(%p)->(%p %i)\n", This
, pihlSite
, dwSiteData
);
195 IHlinkSite_Release(This
->Site
);
197 This
->Site
= pihlSite
;
199 IHlinkSite_AddRef(This
->Site
);
201 This
->SiteData
= dwSiteData
;
206 static HRESULT WINAPI
IHlink_fnGetHlinkSite( IHlink
* iface
,
207 IHlinkSite
** ppihlSite
, DWORD
*pdwSiteData
)
209 HlinkImpl
*This
= (HlinkImpl
*)iface
;
211 TRACE("(%p)->(%p %p)\n", This
, ppihlSite
, pdwSiteData
);
213 *ppihlSite
= This
->Site
;
214 *pdwSiteData
= This
->SiteData
;
217 IHlinkSite_AddRef(This
->Site
);
222 static HRESULT WINAPI
IHlink_fnSetMonikerReference( IHlink
* iface
,
223 DWORD rfHLSETF
, IMoniker
*pmkTarget
, LPCWSTR pwzLocation
)
225 HlinkImpl
*This
= (HlinkImpl
*)iface
;
227 TRACE("(%p)->(%i %p %s)\n", This
, rfHLSETF
, pmkTarget
,
228 debugstr_w(pwzLocation
));
232 if(!(rfHLSETF
& (HLINKSETF_TARGET
| HLINKSETF_LOCATION
)))
235 if(rfHLSETF
& HLINKSETF_TARGET
){
237 IMoniker_Release(This
->Moniker
);
239 This
->Moniker
= pmkTarget
;
242 LPOLESTR display_name
;
243 IMoniker_AddRef(This
->Moniker
);
244 IMoniker_GetDisplayName(This
->Moniker
, NULL
, NULL
, &display_name
);
245 This
->absolute
= display_name
&& strchrW(display_name
, ':');
246 CoTaskMemFree(display_name
);
250 if(rfHLSETF
& HLINKSETF_LOCATION
){
251 heap_free(This
->Location
);
252 This
->Location
= hlink_strdupW( pwzLocation
);
258 static HRESULT WINAPI
IHlink_fnSetStringReference(IHlink
* iface
,
259 DWORD grfHLSETF
, LPCWSTR pwzTarget
, LPCWSTR pwzLocation
)
261 HlinkImpl
*This
= (HlinkImpl
*)iface
;
263 TRACE("(%p)->(%i %s %s)\n", This
, grfHLSETF
, debugstr_w(pwzTarget
),
264 debugstr_w(pwzLocation
));
266 if(grfHLSETF
> (HLINKSETF_TARGET
| HLINKSETF_LOCATION
) &&
267 grfHLSETF
< -(HLINKSETF_TARGET
| HLINKSETF_LOCATION
))
270 if (grfHLSETF
& HLINKSETF_TARGET
)
274 IMoniker_Release(This
->Moniker
);
275 This
->Moniker
= NULL
;
277 if (pwzTarget
&& *pwzTarget
)
280 IBindCtx
*pbc
= NULL
;
284 r
= CreateBindCtx(0, &pbc
);
286 return E_OUTOFMEMORY
;
288 r
= MkParseDisplayName(pbc
, pwzTarget
, &eaten
, &pMon
);
289 IBindCtx_Release(pbc
);
293 LPCWSTR p
= strchrW(pwzTarget
, ':');
294 if (p
&& (p
- pwzTarget
> 1))
295 r
= CreateURLMoniker(NULL
, pwzTarget
, &pMon
);
297 r
= CreateFileMoniker(pwzTarget
, &pMon
);
300 ERR("couldn't create moniker for %s, failed with error 0x%08x\n",
301 debugstr_w(pwzTarget
), r
);
306 IHlink_SetMonikerReference(iface
, HLINKSETF_TARGET
, pMon
, NULL
);
307 IMoniker_Release(pMon
);
311 if (grfHLSETF
& HLINKSETF_LOCATION
)
313 heap_free(This
->Location
);
314 This
->Location
= NULL
;
315 if (pwzLocation
&& *pwzLocation
)
316 This
->Location
= hlink_strdupW( pwzLocation
);
322 static HRESULT WINAPI
IHlink_fnGetMonikerReference(IHlink
* iface
,
323 DWORD dwWhichRef
, IMoniker
**ppimkTarget
, LPWSTR
*ppwzLocation
)
325 HlinkImpl
*This
= (HlinkImpl
*)iface
;
327 TRACE("(%p) -> (%i %p %p)\n", This
, dwWhichRef
, ppimkTarget
,
332 HRESULT hres
= __GetMoniker(This
, ppimkTarget
, dwWhichRef
);
336 *ppwzLocation
= NULL
;
342 IHlink_GetStringReference(iface
, dwWhichRef
, NULL
, ppwzLocation
);
347 static HRESULT WINAPI
IHlink_fnGetStringReference (IHlink
* iface
,
348 DWORD dwWhichRef
, LPWSTR
*ppwzTarget
, LPWSTR
*ppwzLocation
)
350 HlinkImpl
*This
= (HlinkImpl
*)iface
;
352 TRACE("(%p) -> (%i %p %p)\n", This
, dwWhichRef
, ppwzTarget
, ppwzLocation
);
354 if(dwWhichRef
!= -1 && dwWhichRef
& ~(HLINKGETREF_DEFAULT
| HLINKGETREF_ABSOLUTE
| HLINKGETREF_RELATIVE
))
359 *ppwzLocation
= NULL
;
366 HRESULT hres
= __GetMoniker(This
, &mon
, dwWhichRef
);
370 *ppwzLocation
= NULL
;
377 CreateBindCtx( 0, &pbc
);
378 IMoniker_GetDisplayName(mon
, pbc
, NULL
, ppwzTarget
);
379 IBindCtx_Release(pbc
);
380 IMoniker_Release(mon
);
386 *ppwzLocation
= hlink_co_strdupW( This
->Location
);
388 TRACE("(Target: %s Location: %s)\n",
389 (ppwzTarget
)?debugstr_w(*ppwzTarget
):"<NULL>",
390 (ppwzLocation
)?debugstr_w(*ppwzLocation
):"<NULL>");
395 static HRESULT WINAPI
IHlink_fnSetFriendlyName (IHlink
*iface
,
396 LPCWSTR pwzFriendlyName
)
398 HlinkImpl
*This
= (HlinkImpl
*)iface
;
400 TRACE("(%p) -> (%s)\n", This
, debugstr_w(pwzFriendlyName
));
402 heap_free(This
->FriendlyName
);
403 This
->FriendlyName
= hlink_strdupW( pwzFriendlyName
);
408 static HRESULT WINAPI
IHlink_fnGetFriendlyName (IHlink
* iface
,
409 DWORD grfHLFNAMEF
, LPWSTR
* ppwzFriendlyName
)
411 HlinkImpl
*This
= (HlinkImpl
*)iface
;
413 TRACE("(%p) -> (%i %p)\n", This
, grfHLFNAMEF
, ppwzFriendlyName
);
415 /* FIXME: Only using explicitly set and cached friendly names */
417 if (This
->FriendlyName
)
418 *ppwzFriendlyName
= hlink_co_strdupW( This
->FriendlyName
);
422 HRESULT hres
= __GetMoniker(This
, &moniker
, HLINKGETREF_DEFAULT
);
425 *ppwzFriendlyName
= NULL
;
431 CreateBindCtx(0, &bcxt
);
433 IMoniker_GetDisplayName(moniker
, bcxt
, NULL
, ppwzFriendlyName
);
434 IBindCtx_Release(bcxt
);
435 IMoniker_Release(moniker
);
438 *ppwzFriendlyName
= NULL
;
444 static HRESULT WINAPI
IHlink_fnSetTargetFrameName(IHlink
* iface
,
445 LPCWSTR pwzTargetFramename
)
447 HlinkImpl
*This
= (HlinkImpl
*)iface
;
448 TRACE("(%p)->(%s)\n", This
, debugstr_w(pwzTargetFramename
));
450 heap_free(This
->TargetFrameName
);
451 This
->TargetFrameName
= hlink_strdupW( pwzTargetFramename
);
456 static HRESULT WINAPI
IHlink_fnGetTargetFrameName(IHlink
* iface
,
457 LPWSTR
*ppwzTargetFrameName
)
459 HlinkImpl
*This
= (HlinkImpl
*)iface
;
461 TRACE("(%p)->(%p)\n", This
, ppwzTargetFrameName
);
462 *ppwzTargetFrameName
= hlink_co_strdupW( This
->TargetFrameName
);
467 static HRESULT WINAPI
IHlink_fnGetMiscStatus(IHlink
* iface
, DWORD
* pdwStatus
)
473 static HRESULT WINAPI
IHlink_fnNavigate(IHlink
* iface
, DWORD grfHLNF
, LPBC pbc
,
474 IBindStatusCallback
*pbsc
, IHlinkBrowseContext
*phbc
)
476 HlinkImpl
*This
= (HlinkImpl
*)iface
;
477 IMoniker
*mon
= NULL
;
480 FIXME("Semi-Stub:(%p)->(%i %p %p %p)\n", This
, grfHLNF
, pbc
, pbsc
, phbc
);
482 r
= __GetMoniker(This
, &mon
, HLINKGETREF_ABSOLUTE
);
483 TRACE("Moniker %p\n", mon
);
488 IHlinkTarget
*target
= NULL
;
490 CreateBindCtx(0, &bcxt
);
492 RegisterBindStatusCallback(bcxt
, pbsc
, NULL
, 0);
494 r
= IMoniker_BindToObject(mon
, bcxt
, NULL
, &IID_IHlinkTarget
,
496 TRACE("IHlinkTarget returned 0x%x\n", r
);
499 IHlinkTarget_SetBrowseContext(target
, phbc
);
500 IHlinkTarget_Navigate(target
, grfHLNF
, This
->Location
);
501 IHlinkTarget_Release(target
);
505 static const WCHAR szOpen
[] = {'o','p','e','n',0};
506 LPWSTR target
= NULL
;
508 r
= IHlink_GetStringReference(iface
, HLINKGETREF_DEFAULT
, &target
, NULL
);
509 if (SUCCEEDED(r
) && target
)
511 ShellExecuteW(NULL
, szOpen
, target
, NULL
, NULL
, SW_SHOW
);
512 CoTaskMemFree(target
);
516 RevokeBindStatusCallback(bcxt
, pbsc
);
518 IBindCtx_Release(bcxt
);
519 IMoniker_Release(mon
);
523 IHlinkSite_OnNavigationComplete(This
->Site
, This
->SiteData
, 0, r
, NULL
);
525 TRACE("Finished Navigation\n");
529 static HRESULT WINAPI
IHlink_fnSetAdditonalParams(IHlink
* iface
,
530 LPCWSTR pwzAdditionalParams
)
532 TRACE("Not implemented in native IHlink\n");
536 static HRESULT WINAPI
IHlink_fnGetAdditionalParams(IHlink
* iface
,
537 LPWSTR
* ppwzAdditionalParams
)
539 TRACE("Not implemented in native IHlink\n");
543 static const IHlinkVtbl hlvt
=
545 IHlink_fnQueryInterface
,
548 IHlink_fnSetHlinkSite
,
549 IHlink_fnGetHlinkSite
,
550 IHlink_fnSetMonikerReference
,
551 IHlink_fnGetMonikerReference
,
552 IHlink_fnSetStringReference
,
553 IHlink_fnGetStringReference
,
554 IHlink_fnSetFriendlyName
,
555 IHlink_fnGetFriendlyName
,
556 IHlink_fnSetTargetFrameName
,
557 IHlink_fnGetTargetFrameName
,
558 IHlink_fnGetMiscStatus
,
560 IHlink_fnSetAdditonalParams
,
561 IHlink_fnGetAdditionalParams
564 static HRESULT WINAPI
IDataObject_fnQueryInterface(IDataObject
* iface
,
565 REFIID riid
, LPVOID
*ppvObj
)
567 HlinkImpl
*This
= HlinkImpl_from_IDataObject(iface
);
569 return IHlink_QueryInterface((IHlink
*)This
, riid
, ppvObj
);
572 static ULONG WINAPI
IDataObject_fnAddRef (IDataObject
* iface
)
574 HlinkImpl
*This
= HlinkImpl_from_IDataObject(iface
);
576 return IHlink_AddRef((IHlink
*)This
);
579 static ULONG WINAPI
IDataObject_fnRelease (IDataObject
* iface
)
581 HlinkImpl
*This
= HlinkImpl_from_IDataObject(iface
);
583 return IHlink_Release((IHlink
*)This
);
586 static HRESULT WINAPI
IDataObject_fnGetData(IDataObject
* iface
,
587 FORMATETC
* pformatetcIn
, STGMEDIUM
* pmedium
)
593 static HRESULT WINAPI
IDataObject_fnGetDataHere(IDataObject
* iface
,
594 FORMATETC
* pformatetc
, STGMEDIUM
* pmedium
)
600 static HRESULT WINAPI
IDataObject_fnQueryGetData(IDataObject
* iface
,
601 FORMATETC
* pformatetc
)
607 static HRESULT WINAPI
IDataObject_fnGetConicalFormatEtc(IDataObject
* iface
,
608 FORMATETC
* pformatetcIn
, FORMATETC
* pformatetcOut
)
614 static HRESULT WINAPI
IDataObject_fnSetData(IDataObject
* iface
,
615 FORMATETC
* pformatetc
, STGMEDIUM
* pmedium
, BOOL fRelease
)
621 static HRESULT WINAPI
IDataObject_fnEnumFormatEtc(IDataObject
* iface
,
622 DWORD dwDirection
, IEnumFORMATETC
** ppenumFormatEtc
)
628 static HRESULT WINAPI
IDataObject_fnDAdvise(IDataObject
* iface
,
629 FORMATETC
* pformatetc
, DWORD advf
, IAdviseSink
* pAdvSink
,
630 DWORD
* pdwConnection
)
636 static HRESULT WINAPI
IDataObject_fnDUnadvise(IDataObject
* iface
,
643 static HRESULT WINAPI
IDataObject_fnEnumDAdvise(IDataObject
* iface
,
644 IEnumSTATDATA
** ppenumAdvise
)
650 static const IDataObjectVtbl dovt
=
652 IDataObject_fnQueryInterface
,
653 IDataObject_fnAddRef
,
654 IDataObject_fnRelease
,
655 IDataObject_fnGetData
,
656 IDataObject_fnGetDataHere
,
657 IDataObject_fnQueryGetData
,
658 IDataObject_fnGetConicalFormatEtc
,
659 IDataObject_fnSetData
,
660 IDataObject_fnEnumFormatEtc
,
661 IDataObject_fnDAdvise
,
662 IDataObject_fnDUnadvise
,
663 IDataObject_fnEnumDAdvise
666 static HRESULT WINAPI
IPersistStream_fnQueryInterface(IPersistStream
* iface
,
667 REFIID riid
, LPVOID
*ppvObj
)
669 HlinkImpl
*This
= HlinkImpl_from_IPersistStream(iface
);
670 TRACE("(%p)\n", This
);
671 return IHlink_QueryInterface((IHlink
*)This
, riid
, ppvObj
);
674 static ULONG WINAPI
IPersistStream_fnAddRef (IPersistStream
* iface
)
676 HlinkImpl
*This
= HlinkImpl_from_IPersistStream(iface
);
677 TRACE("(%p)\n", This
);
678 return IHlink_AddRef((IHlink
*)This
);
681 static ULONG WINAPI
IPersistStream_fnRelease (IPersistStream
* iface
)
683 HlinkImpl
*This
= HlinkImpl_from_IPersistStream(iface
);
684 TRACE("(%p)\n", This
);
685 return IHlink_Release((IHlink
*)This
);
688 static HRESULT WINAPI
IPersistStream_fnGetClassID(IPersistStream
* iface
,
691 HlinkImpl
*This
= HlinkImpl_from_IPersistStream(iface
);
692 TRACE("(%p)\n", This
);
693 *pClassID
= CLSID_StdHlink
;
697 static HRESULT WINAPI
IPersistStream_fnIsDirty(IPersistStream
* iface
)
703 static HRESULT
write_hlink_string(IStream
*pStm
, LPCWSTR str
)
708 TRACE("(%p, %s)\n", pStm
, debugstr_w(str
));
710 len
= strlenW(str
) + 1;
712 hr
= IStream_Write(pStm
, &len
, sizeof(len
), NULL
);
713 if (FAILED(hr
)) return hr
;
715 hr
= IStream_Write(pStm
, str
, len
* sizeof(WCHAR
), NULL
);
716 if (FAILED(hr
)) return hr
;
721 static inline ULONG
size_hlink_string(LPCWSTR str
)
723 return sizeof(DWORD
) + (strlenW(str
) + 1) * sizeof(WCHAR
);
726 static HRESULT
read_hlink_string(IStream
*pStm
, LPWSTR
*out_str
)
733 hr
= IStream_Read(pStm
, &len
, sizeof(len
), &read
);
734 if (FAILED(hr
)) return hr
;
735 if (read
!= sizeof(len
)) return STG_E_READFAULT
;
737 TRACE("read len %d\n", len
);
739 str
= heap_alloc(len
* sizeof(WCHAR
));
740 if (!str
) return E_OUTOFMEMORY
;
742 hr
= IStream_Read(pStm
, str
, len
* sizeof(WCHAR
), &read
);
748 if (read
!= len
* sizeof(WCHAR
))
751 return STG_E_READFAULT
;
753 TRACE("read string %s\n", debugstr_w(str
));
759 static HRESULT WINAPI
IPersistStream_fnLoad(IPersistStream
* iface
,
765 HlinkImpl
*This
= HlinkImpl_from_IPersistStream(iface
);
767 r
= IStream_Read(pStm
, hdr
, sizeof(hdr
), &read
);
768 if (read
!= sizeof(hdr
) || (hdr
[0] != HLINK_SAVE_MAGIC
))
773 if (hdr
[1] & ~HLINK_SAVE_ALL
)
774 FIXME("unknown flag(s) 0x%x\n", hdr
[1] & ~HLINK_SAVE_ALL
);
776 if (hdr
[1] & HLINK_SAVE_TARGET_FRAME_PRESENT
)
778 TRACE("loading target frame name\n");
779 r
= read_hlink_string(pStm
, &This
->TargetFrameName
);
780 if (FAILED(r
)) goto end
;
783 if (hdr
[1] & HLINK_SAVE_FRIENDLY_PRESENT
)
785 TRACE("loading target friendly name\n");
787 FIXME("0x4 flag not present with friendly name flag - not sure what this means\n");
788 r
= read_hlink_string(pStm
, &This
->FriendlyName
);
789 if (FAILED(r
)) goto end
;
792 if (hdr
[1] & HLINK_SAVE_MONIKER_PRESENT
)
794 TRACE("loading moniker\n");
795 r
= OleLoadFromStream(pStm
, &IID_IMoniker
, (LPVOID
*)&(This
->Moniker
));
798 This
->absolute
= hdr
[1] & HLINK_SAVE_MONIKER_IS_ABSOLUTE
? TRUE
: FALSE
;
801 if (hdr
[1] & HLINK_SAVE_LOCATION_PRESENT
)
803 TRACE("loading location\n");
804 r
= read_hlink_string(pStm
, &This
->Location
);
805 if (FAILED(r
)) goto end
;
809 TRACE("Load Result 0x%x (%p)\n", r
, This
->Moniker
);
814 static HRESULT WINAPI
IPersistStream_fnSave(IPersistStream
* iface
,
815 IStream
* pStm
, BOOL fClearDirty
)
818 HlinkImpl
*This
= HlinkImpl_from_IPersistStream(iface
);
822 TRACE("(%p) Moniker(%p)\n", This
, This
->Moniker
);
824 r
= __GetMoniker(This
, &moniker
, HLINKGETREF_DEFAULT
);
829 hdr
[0] = HLINK_SAVE_MAGIC
;
833 hdr
[1] |= HLINK_SAVE_MONIKER_PRESENT
;
835 hdr
[1] |= HLINK_SAVE_MONIKER_IS_ABSOLUTE
;
837 hdr
[1] |= HLINK_SAVE_LOCATION_PRESENT
;
838 if (This
->FriendlyName
)
839 hdr
[1] |= HLINK_SAVE_FRIENDLY_PRESENT
| 4 /* FIXME */;
840 if (This
->TargetFrameName
)
841 hdr
[1] |= HLINK_SAVE_TARGET_FRAME_PRESENT
;
843 IStream_Write(pStm
, hdr
, sizeof(hdr
), NULL
);
845 if (This
->TargetFrameName
)
847 r
= write_hlink_string(pStm
, This
->TargetFrameName
);
848 if (FAILED(r
)) goto end
;
851 if (This
->FriendlyName
)
853 r
= write_hlink_string(pStm
, This
->FriendlyName
);
854 if (FAILED(r
)) goto end
;
859 IPersistStream
* monstream
;
862 IMoniker_QueryInterface(moniker
, &IID_IPersistStream
,
863 (LPVOID
*)&monstream
);
866 r
= OleSaveToStream(monstream
, pStm
);
867 IPersistStream_Release(monstream
);
869 if (FAILED(r
)) goto end
;
874 r
= write_hlink_string(pStm
, This
->Location
);
875 if (FAILED(r
)) goto end
;
879 if (moniker
) IMoniker_Release(moniker
);
880 TRACE("Save Result 0x%x\n", r
);
885 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(IPersistStream
* iface
,
886 ULARGE_INTEGER
* pcbSize
)
889 HlinkImpl
*This
= HlinkImpl_from_IPersistStream(iface
);
892 TRACE("(%p) Moniker(%p)\n", This
, This
->Moniker
);
894 pcbSize
->QuadPart
= sizeof(DWORD
)*2;
896 if (This
->TargetFrameName
)
897 pcbSize
->QuadPart
+= size_hlink_string(This
->TargetFrameName
);
899 if (This
->FriendlyName
)
900 pcbSize
->QuadPart
+= size_hlink_string(This
->FriendlyName
);
902 r
= __GetMoniker(This
, &moniker
, HLINKGETREF_DEFAULT
);
909 IPersistStream
* monstream
= NULL
;
910 IMoniker_QueryInterface(moniker
, &IID_IPersistStream
,
911 (LPVOID
*)&monstream
);
914 ULARGE_INTEGER mon_size
;
915 r
= IPersistStream_GetSizeMax(monstream
, &mon_size
);
916 pcbSize
->QuadPart
+= mon_size
.QuadPart
;
917 IPersistStream_Release(monstream
);
919 IMoniker_Release(moniker
);
923 pcbSize
->QuadPart
+= size_hlink_string(This
->Location
);
928 static const IPersistStreamVtbl psvt
=
930 IPersistStream_fnQueryInterface
,
931 IPersistStream_fnAddRef
,
932 IPersistStream_fnRelease
,
933 IPersistStream_fnGetClassID
,
934 IPersistStream_fnIsDirty
,
935 IPersistStream_fnLoad
,
936 IPersistStream_fnSave
,
937 IPersistStream_fnGetSizeMax
,