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"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(hlink
);
31 static HINSTANCE instance
;
33 typedef HRESULT (*LPFNCREATEINSTANCE
)(IUnknown
*, REFIID
, LPVOID
*);
37 IClassFactory IClassFactory_iface
;
38 LPFNCREATEINSTANCE lpfnCI
;
41 static inline CFImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
43 return CONTAINING_RECORD(iface
, CFImpl
, IClassFactory_iface
);
46 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
48 TRACE("%p %d %p\n", hinstDLL
, fdwReason
, lpvReserved
);
52 case DLL_PROCESS_ATTACH
:
54 DisableThreadLibraryCalls(hinstDLL
);
60 /***********************************************************************
61 * DllCanUnloadNow (HLINK.@)
63 HRESULT WINAPI
DllCanUnloadNow( void )
68 /***********************************************************************
69 * HlinkCreateFromMoniker (HLINK.@)
71 HRESULT WINAPI
HlinkCreateFromMoniker( IMoniker
*pimkTrgt
, LPCWSTR pwzLocation
,
72 LPCWSTR pwzFriendlyName
, IHlinkSite
* pihlsite
, DWORD dwSiteData
,
73 IUnknown
* piunkOuter
, REFIID riid
, void** ppvObj
)
78 TRACE("%p %s %s %p %i %p %s %p\n", pimkTrgt
, debugstr_w(pwzLocation
),
79 debugstr_w(pwzFriendlyName
), pihlsite
, dwSiteData
, piunkOuter
,
80 debugstr_guid(riid
), ppvObj
);
82 r
= CoCreateInstance(&CLSID_StdHlink
, piunkOuter
, CLSCTX_INPROC_SERVER
, riid
, (LPVOID
*)&hl
);
86 IHlink_SetMonikerReference(hl
, HLINKSETF_LOCATION
| HLINKSETF_TARGET
, pimkTrgt
, pwzLocation
);
89 IHlink_SetFriendlyName(hl
, pwzFriendlyName
);
91 IHlink_SetHlinkSite(hl
, pihlsite
, dwSiteData
);
95 TRACE("Returning %i\n",r
);
100 /***********************************************************************
101 * HlinkCreateFromString (HLINK.@)
103 HRESULT WINAPI
HlinkCreateFromString( LPCWSTR pwzTarget
, LPCWSTR pwzLocation
,
104 LPCWSTR pwzFriendlyName
, IHlinkSite
* pihlsite
, DWORD dwSiteData
,
105 IUnknown
* piunkOuter
, REFIID riid
, void** ppvObj
)
112 TRACE("%s %s %s %p %i %p %s %p\n", debugstr_w(pwzTarget
),
113 debugstr_w(pwzLocation
), debugstr_w(pwzFriendlyName
), pihlsite
,
114 dwSiteData
, piunkOuter
, debugstr_guid(riid
), ppvObj
);
116 r
= CoCreateInstance(&CLSID_StdHlink
, piunkOuter
, CLSCTX_INPROC_SERVER
, riid
, (LPVOID
*)&hl
);
122 hash
= strchrW(pwzTarget
, '#');
125 if (hash
== pwzTarget
)
129 int tgt_len
= hash
- pwzTarget
;
130 tgt
= heap_alloc((tgt_len
+ 1) * sizeof(WCHAR
));
132 return E_OUTOFMEMORY
;
133 memcpy(tgt
, pwzTarget
, tgt_len
* sizeof(WCHAR
));
143 tgt
= hlink_strdupW(pwzTarget
);
145 return E_OUTOFMEMORY
;
155 IHlink_SetStringReference(hl
, HLINKSETF_TARGET
| HLINKSETF_LOCATION
, tgt
, loc
);
160 IHlink_SetFriendlyName(hl
, pwzFriendlyName
);
163 IHlink_SetHlinkSite(hl
, pihlsite
, dwSiteData
);
165 TRACE("Returning %i\n",r
);
172 /***********************************************************************
173 * HlinkCreateBrowseContext (HLINK.@)
175 HRESULT WINAPI
HlinkCreateBrowseContext( IUnknown
* piunkOuter
, REFIID riid
, void** ppvObj
)
177 TRACE("%p %s %p\n", piunkOuter
, debugstr_guid(riid
), ppvObj
);
178 return CoCreateInstance(&CLSID_StdHlinkBrowseContext
, piunkOuter
, CLSCTX_INPROC_SERVER
, riid
, ppvObj
);
181 /***********************************************************************
182 * HlinkNavigate (HLINK.@)
184 HRESULT WINAPI
HlinkNavigate(IHlink
*phl
, IHlinkFrame
*phlFrame
,
185 DWORD grfHLNF
, LPBC pbc
, IBindStatusCallback
*pbsc
,
186 IHlinkBrowseContext
*phlbc
)
190 TRACE("%p %p %i %p %p %p\n", phl
, phlFrame
, grfHLNF
, pbc
, pbsc
, phlbc
);
193 r
= IHlinkFrame_Navigate(phlFrame
, grfHLNF
, pbc
, pbsc
, phl
);
195 r
= IHlink_Navigate(phl
, grfHLNF
, pbc
, pbsc
, phlbc
);
200 /***********************************************************************
201 * HlinkOnNavigate (HLINK.@)
203 HRESULT WINAPI
HlinkOnNavigate( IHlinkFrame
*phlFrame
,
204 IHlinkBrowseContext
* phlbc
, DWORD grfHLNF
, IMoniker
*pmkTarget
,
205 LPCWSTR pwzLocation
, LPCWSTR pwzFriendlyName
, ULONG
* puHLID
)
209 TRACE("%p %p %i %p %s %s %p\n",phlFrame
, phlbc
, grfHLNF
, pmkTarget
,
210 debugstr_w(pwzLocation
), debugstr_w(pwzFriendlyName
), puHLID
);
212 r
= IHlinkBrowseContext_OnNavigateHlink(phlbc
, grfHLNF
, pmkTarget
,
213 pwzLocation
, pwzFriendlyName
, puHLID
);
216 r
= IHlinkFrame_OnNavigate(phlFrame
,grfHLNF
,pmkTarget
, pwzLocation
,
222 /***********************************************************************
223 * HlinkCreateFromData (HLINK.@)
225 HRESULT WINAPI
HlinkCreateFromData(IDataObject
*piDataObj
,
226 IHlinkSite
*pihlsite
, DWORD dwSiteData
, IUnknown
*piunkOuter
,
227 REFIID riid
, void **ppvObj
)
229 FIXME("%p, %p, %d, %p, %s, %p\n", piDataObj
, pihlsite
, dwSiteData
,
230 piunkOuter
, debugstr_guid(riid
), ppvObj
);
235 /***********************************************************************
236 * HlinkQueryCreateFromData (HLINK.@)
238 HRESULT WINAPI
HlinkQueryCreateFromData(IDataObject
* piDataObj
)
240 FIXME("%p\n", piDataObj
);
244 /***********************************************************************
245 * HlinkNavigateToStringReference (HLINK.@)
247 HRESULT WINAPI
HlinkNavigateToStringReference( LPCWSTR pwzTarget
,
248 LPCWSTR pwzLocation
, IHlinkSite
*pihlsite
, DWORD dwSiteData
,
249 IHlinkFrame
*pihlframe
, DWORD grfHLNF
, LPBC pibc
,
250 IBindStatusCallback
*pibsc
, IHlinkBrowseContext
*pihlbc
)
253 IHlink
*hlink
= NULL
;
255 TRACE("%s %s %p %08x %p %08x %p %p %p\n",
256 debugstr_w(pwzTarget
), debugstr_w(pwzLocation
), pihlsite
,
257 dwSiteData
, pihlframe
, grfHLNF
, pibc
, pibsc
, pihlbc
);
259 r
= HlinkCreateFromString( pwzTarget
, pwzLocation
, NULL
, pihlsite
,
260 dwSiteData
, NULL
, &IID_IHlink
, (LPVOID
*) &hlink
);
262 r
= HlinkNavigate(hlink
, pihlframe
, grfHLNF
, pibc
, pibsc
, pihlbc
);
263 IHlink_Release(hlink
);
269 /***********************************************************************
270 * HlinkIsShortcut (HLINK.@)
272 HRESULT WINAPI
HlinkIsShortcut(LPCWSTR pwzFileName
)
276 static const WCHAR url_ext
[] = {'.','u','r','l',0};
278 TRACE("(%s)\n", debugstr_w(pwzFileName
));
283 len
= strlenW(pwzFileName
)-4;
287 return strcmpiW(pwzFileName
+len
, url_ext
) ? S_FALSE
: S_OK
;
290 /***********************************************************************
291 * HlinkGetSpecialReference (HLINK.@)
293 HRESULT WINAPI
HlinkGetSpecialReference(ULONG uReference
, LPWSTR
*ppwzReference
)
295 DWORD res
, type
, size
= 100;
300 static const WCHAR start_pageW
[] = {'S','t','a','r','t',' ','P','a','g','e',0};
301 static const WCHAR search_pageW
[] = {'S','e','a','r','c','h',' ','P','a','g','e',0};
303 static const WCHAR ie_main_keyW
[] =
304 {'S','o','f','t','w','a','r','e',
305 '\\','M','i','c','r','o','s','o','f','t','\\',
306 'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
307 '\\','M','a','i','n',0};
309 TRACE("(%u %p)\n", uReference
, ppwzReference
);
311 *ppwzReference
= NULL
;
315 value_name
= start_pageW
;
317 case HLSR_SEARCHPAGE
:
318 value_name
= search_pageW
;
320 case HLSR_HISTORYFOLDER
:
326 res
= RegOpenKeyW(HKEY_CURRENT_USER
, ie_main_keyW
, &hkey
);
327 if(res
!= ERROR_SUCCESS
) {
328 WARN("Could not open key: %u\n", res
);
329 return HRESULT_FROM_WIN32(res
);
332 buf
= CoTaskMemAlloc(size
);
333 res
= RegQueryValueExW(hkey
, value_name
, NULL
, &type
, (PBYTE
)buf
, &size
);
334 buf
= CoTaskMemRealloc(buf
, size
);
335 if(res
== ERROR_MORE_DATA
)
336 res
= RegQueryValueExW(hkey
, value_name
, NULL
, &type
, (PBYTE
)buf
, &size
);
338 if(res
!= ERROR_SUCCESS
) {
339 WARN("Could not query value %s: %u\n", debugstr_w(value_name
), res
);
341 return HRESULT_FROM_WIN32(res
);
344 *ppwzReference
= buf
;
348 /***********************************************************************
349 * HlinkTranslateURL (HLINK.@)
351 HRESULT WINAPI
HlinkTranslateURL(LPCWSTR pwzURL
, DWORD grfFlags
, LPWSTR
*ppwzTranslatedURL
)
353 FIXME("(%s %08x %p)\n", debugstr_w(pwzURL
), grfFlags
, ppwzTranslatedURL
);
357 /***********************************************************************
358 * HlinkUpdateStackItem (HLINK.@)
360 HRESULT WINAPI
HlinkUpdateStackItem(IHlinkFrame
*frame
, IHlinkBrowseContext
*bc
,
361 ULONG hlid
, IMoniker
*target
, LPCWSTR location
, LPCWSTR friendly_name
)
365 TRACE("(%p %p 0x%x %p %s %s)\n", frame
, bc
, hlid
, target
, debugstr_w(location
), debugstr_w(friendly_name
));
367 if (!frame
&& !bc
) return E_INVALIDARG
;
370 hr
= IHlinkFrame_UpdateHlink(frame
, hlid
, target
, location
, friendly_name
);
372 hr
= IHlinkBrowseContext_UpdateHlink(bc
, hlid
, target
, location
, friendly_name
);
377 /***********************************************************************
378 * HlinkParseDisplayName (HLINK.@)
380 HRESULT WINAPI
HlinkParseDisplayName(LPBC pibc
, LPCWSTR pwzDisplayName
, BOOL fNoForceAbs
,
381 ULONG
*pcchEaten
, IMoniker
**ppimk
)
383 static const WCHAR file_colonW
[] = {'f','i','l','e',':'};
387 TRACE("(%p %s %x %p %p)\n", pibc
, debugstr_w(pwzDisplayName
), fNoForceAbs
, pcchEaten
, ppimk
);
390 FIXME("Unsupported fNoForceAbs\n");
392 if(!strncmpiW(pwzDisplayName
, file_colonW
, sizeof(file_colonW
)/sizeof(WCHAR
))) {
393 pwzDisplayName
+= sizeof(file_colonW
)/sizeof(WCHAR
);
394 eaten
+= sizeof(file_colonW
)/sizeof(WCHAR
);
396 while(*pwzDisplayName
== '/') {
401 hres
= MkParseDisplayNameEx(pibc
, pwzDisplayName
, pcchEaten
, ppimk
);
405 hres
= MkParseDisplayName(pibc
, pwzDisplayName
, pcchEaten
, ppimk
);
410 hres
= CreateFileMoniker(pwzDisplayName
, ppimk
);
412 *pcchEaten
= eaten
+ strlenW(pwzDisplayName
);
417 /***********************************************************************
418 * HlinkResolveMonikerForData (HLINK.@)
420 HRESULT WINAPI
HlinkResolveMonikerForData(LPMONIKER pimkReference
, DWORD reserved
, LPBC pibc
,
421 ULONG cFmtetc
, FORMATETC
*rgFmtetc
, IBindStatusCallback
*pibsc
, LPMONIKER pimkBase
)
423 LPOLESTR name
= NULL
;
429 TRACE("(%p %x %p %d %p %p %p)\n", pimkReference
, reserved
, pibc
, cFmtetc
, rgFmtetc
, pibsc
, pimkBase
);
431 if(cFmtetc
|| rgFmtetc
|| pimkBase
)
432 FIXME("Unsupported args\n");
434 hres
= RegisterBindStatusCallback(pibc
, pibsc
, NULL
/* FIXME */, 0);
438 hres
= IMoniker_IsSystemMoniker(pimkReference
, &mksys
);
439 if(SUCCEEDED(hres
) && mksys
!= MKSYS_URLMONIKER
)
440 WARN("sysmk = %x\n", mksys
);
442 /* FIXME: What is it for? */
443 CreateBindCtx(0, &bctx
);
444 hres
= IMoniker_GetDisplayName(pimkReference
, bctx
, NULL
, &name
);
445 IBindCtx_Release(bctx
);
446 if(SUCCEEDED(hres
)) {
447 TRACE("got display name %s\n", debugstr_w(name
));
451 return IMoniker_BindToStorage(pimkReference
, pibc
, NULL
, &IID_IUnknown
, &obj
);
454 /***********************************************************************
455 * HlinkClone (HLINK.@)
457 HRESULT WINAPI
HlinkClone(IHlink
*hlink
, REFIID riid
, IHlinkSite
*hls
,
458 DWORD site_data
, void **obj
)
460 IMoniker
*mk
, *clone_mk
= NULL
;
461 WCHAR
*loc
, *name
= NULL
;
464 if(!hlink
|| !riid
|| !obj
)
469 hres
= IHlink_GetMonikerReference(hlink
, HLINKGETREF_DEFAULT
, &mk
, &loc
);
477 hres
= CreateStreamOnHGlobal(NULL
, TRUE
, &strm
);
479 IMoniker_Release(mk
);
483 hres
= OleSaveToStream((IPersistStream
*)mk
, strm
);
485 IStream_Release(strm
);
486 IMoniker_Release(mk
);
489 IMoniker_Release(mk
);
492 hres
= IStream_Seek(strm
, lgint
, STREAM_SEEK_SET
, NULL
);
494 IStream_Release(strm
);
498 hres
= OleLoadFromStream(strm
, &IID_IMoniker
, (void**)&clone_mk
);
499 IStream_Release(strm
);
504 hres
= IHlink_GetFriendlyName(hlink
, HLFNAMEF_DEFAULT
, &name
);
508 hres
= HlinkCreateFromMoniker(clone_mk
, loc
, name
, hls
, site_data
, NULL
,
513 IMoniker_Release(clone_mk
);
519 static HRESULT WINAPI
HLinkCF_fnQueryInterface ( LPCLASSFACTORY iface
,
520 REFIID riid
, LPVOID
*ppvObj
)
522 CFImpl
*This
= impl_from_IClassFactory(iface
);
524 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppvObj
);
528 if (IsEqualIID(riid
, &IID_IUnknown
) ||
529 IsEqualIID(riid
, &IID_IClassFactory
))
531 *ppvObj
= &This
->IClassFactory_iface
;
535 TRACE("-- E_NOINTERFACE\n");
536 return E_NOINTERFACE
;
539 static ULONG WINAPI
HLinkCF_fnAddRef (LPCLASSFACTORY iface
)
544 static ULONG WINAPI
HLinkCF_fnRelease(LPCLASSFACTORY iface
)
549 static HRESULT WINAPI
HLinkCF_fnCreateInstance( LPCLASSFACTORY iface
,
550 LPUNKNOWN pUnkOuter
, REFIID riid
, LPVOID
*ppvObject
)
552 CFImpl
*This
= impl_from_IClassFactory(iface
);
554 TRACE("%p->(%p,%s,%p)\n", This
, pUnkOuter
, debugstr_guid(riid
), ppvObject
);
558 return This
->lpfnCI(pUnkOuter
, riid
, ppvObject
);
561 static HRESULT WINAPI
HLinkCF_fnLockServer(LPCLASSFACTORY iface
, BOOL fLock
)
563 FIXME("%p %d\n", iface
, fLock
);
567 static const IClassFactoryVtbl hlcfvt
=
569 HLinkCF_fnQueryInterface
,
572 HLinkCF_fnCreateInstance
,
576 static CFImpl HLink_cf
= { { &hlcfvt
}, HLink_Constructor
};
577 static CFImpl HLinkBrowseContext_cf
= { { &hlcfvt
}, HLinkBrowseContext_Constructor
};
579 /***********************************************************************
580 * DllGetClassObject (HLINK.@)
582 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID iid
, LPVOID
*ppv
)
584 IClassFactory
*pcf
= NULL
;
586 TRACE("%s %s %p\n", debugstr_guid(rclsid
), debugstr_guid(iid
), ppv
);
592 if (IsEqualIID(rclsid
, &CLSID_StdHlink
))
593 pcf
= &HLink_cf
.IClassFactory_iface
;
594 else if (IsEqualIID(rclsid
, &CLSID_StdHlinkBrowseContext
))
595 pcf
= &HLinkBrowseContext_cf
.IClassFactory_iface
;
597 return CLASS_E_CLASSNOTAVAILABLE
;
599 return IClassFactory_QueryInterface(pcf
, iid
, ppv
);
602 /***********************************************************************
603 * DllRegisterServer (HLINK.@)
605 HRESULT WINAPI
DllRegisterServer(void)
607 return __wine_register_resources( instance
);
610 /***********************************************************************
611 * DllUnregisterServer (HLINK.@)
613 HRESULT WINAPI
DllUnregisterServer(void)
615 return __wine_unregister_resources( instance
);