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 typedef HRESULT (CALLBACK
*LPFNCREATEINSTANCE
)(IUnknown
*, REFIID
, LPVOID
*);
34 const IClassFactoryVtbl
*lpVtbl
;
35 LPFNCREATEINSTANCE lpfnCI
;
38 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
40 TRACE("%p %d %p\n", hinstDLL
, fdwReason
, lpvReserved
);
44 case DLL_PROCESS_ATTACH
:
45 DisableThreadLibraryCalls(hinstDLL
);
47 case DLL_PROCESS_DETACH
:
53 /***********************************************************************
54 * DllCanUnloadNow (HLINK.@)
56 HRESULT WINAPI
DllCanUnloadNow( void )
61 /***********************************************************************
62 * HlinkCreateFromMoniker (HLINK.@)
64 HRESULT WINAPI
HlinkCreateFromMoniker( IMoniker
*pimkTrgt
, LPCWSTR pwzLocation
,
65 LPCWSTR pwzFriendlyName
, IHlinkSite
* pihlsite
, DWORD dwSiteData
,
66 IUnknown
* piunkOuter
, REFIID riid
, void** ppvObj
)
71 TRACE("%p %s %s %p %i %p %s %p\n", pimkTrgt
, debugstr_w(pwzLocation
),
72 debugstr_w(pwzFriendlyName
), pihlsite
, dwSiteData
, piunkOuter
,
73 debugstr_guid(riid
), ppvObj
);
75 r
= CoCreateInstance(&CLSID_StdHlink
, piunkOuter
, CLSCTX_INPROC_SERVER
, riid
, (LPVOID
*)&hl
);
79 IHlink_SetMonikerReference(hl
, HLINKSETF_LOCATION
| HLINKSETF_TARGET
, pimkTrgt
, pwzLocation
);
82 IHlink_SetFriendlyName(hl
, pwzFriendlyName
);
84 IHlink_SetHlinkSite(hl
, pihlsite
, dwSiteData
);
88 TRACE("Returning %i\n",r
);
93 /***********************************************************************
94 * HlinkCreateFromString (HLINK.@)
96 HRESULT WINAPI
HlinkCreateFromString( LPCWSTR pwzTarget
, LPCWSTR pwzLocation
,
97 LPCWSTR pwzFriendlyName
, IHlinkSite
* pihlsite
, DWORD dwSiteData
,
98 IUnknown
* piunkOuter
, REFIID riid
, void** ppvObj
)
103 TRACE("%s %s %s %p %i %p %s %p\n", debugstr_w(pwzTarget
),
104 debugstr_w(pwzLocation
), debugstr_w(pwzFriendlyName
), pihlsite
,
105 dwSiteData
, piunkOuter
, debugstr_guid(riid
), ppvObj
);
107 r
= CoCreateInstance(&CLSID_StdHlink
, piunkOuter
, CLSCTX_INPROC_SERVER
, riid
, (LPVOID
*)&hl
);
111 IHlink_SetStringReference(hl
, HLINKSETF_TARGET
| HLINKSETF_LOCATION
,
112 pwzTarget
, pwzLocation
);
115 IHlink_SetFriendlyName(hl
, pwzFriendlyName
);
118 IHlink_SetHlinkSite(hl
, pihlsite
, dwSiteData
);
120 TRACE("Returning %i\n",r
);
127 /***********************************************************************
128 * HlinkCreateBrowseContext (HLINK.@)
130 HRESULT WINAPI
HlinkCreateBrowseContext( IUnknown
* piunkOuter
, REFIID riid
, void** ppvObj
)
134 TRACE("%p %s %p\n", piunkOuter
, debugstr_guid(riid
), ppvObj
);
136 r
= CoCreateInstance(&CLSID_StdHlinkBrowseContext
, piunkOuter
, CLSCTX_INPROC_SERVER
, riid
, ppvObj
);
138 TRACE("returning %i\n",r
);
143 /***********************************************************************
144 * HlinkNavigate (HLINK.@)
146 HRESULT WINAPI
HlinkNavigate(IHlink
*phl
, IHlinkFrame
*phlFrame
,
147 DWORD grfHLNF
, LPBC pbc
, IBindStatusCallback
*pbsc
,
148 IHlinkBrowseContext
*phlbc
)
152 TRACE("%p %p %i %p %p %p\n", phl
, phlFrame
, grfHLNF
, pbc
, pbsc
, phlbc
);
155 r
= IHlinkFrame_Navigate(phlFrame
, grfHLNF
, pbc
, pbsc
, phl
);
157 r
= IHlink_Navigate(phl
, grfHLNF
, pbc
, pbsc
, phlbc
);
162 /***********************************************************************
163 * HlinkOnNavigate (HLINK.@)
165 HRESULT WINAPI
HlinkOnNavigate( IHlinkFrame
*phlFrame
,
166 IHlinkBrowseContext
* phlbc
, DWORD grfHLNF
, IMoniker
*pmkTarget
,
167 LPCWSTR pwzLocation
, LPCWSTR pwzFriendlyName
, ULONG
* puHLID
)
171 TRACE("%p %p %i %p %s %s %p\n",phlFrame
, phlbc
, grfHLNF
, pmkTarget
,
172 debugstr_w(pwzLocation
), debugstr_w(pwzFriendlyName
), puHLID
);
174 r
= IHlinkBrowseContext_OnNavigateHlink(phlbc
, grfHLNF
, pmkTarget
,
175 pwzLocation
, pwzFriendlyName
, puHLID
);
178 r
= IHlinkFrame_OnNavigate(phlFrame
,grfHLNF
,pmkTarget
, pwzLocation
,
184 /***********************************************************************
185 * HlinkCreateFromData (HLINK.@)
187 HRESULT WINAPI
HlinkCreateFromData(IDataObject
*piDataObj
,
188 IHlinkSite
*pihlsite
, DWORD dwSiteData
, IUnknown
*piunkOuter
,
189 REFIID riid
, void **ppvObj
)
191 FIXME("%p %p %d %p %p %p\n",
192 piDataObj
, pihlsite
, dwSiteData
, piunkOuter
, riid
, ppvObj
);
197 /***********************************************************************
198 * HlinkQueryCreateFromData (HLINK.@)
200 HRESULT WINAPI
HlinkQueryCreateFromData(IDataObject
* piDataObj
)
202 FIXME("%p\n", piDataObj
);
206 /***********************************************************************
207 * HlinkNavigateToStringReference (HLINK.@)
209 HRESULT WINAPI
HlinkNavigateToStringReference( LPCWSTR pwzTarget
,
210 LPCWSTR pwzLocation
, IHlinkSite
*pihlsite
, DWORD dwSiteData
,
211 IHlinkFrame
*pihlframe
, DWORD grfHLNF
, LPBC pibc
,
212 IBindStatusCallback
*pibsc
, IHlinkBrowseContext
*pihlbc
)
215 IHlink
*hlink
= NULL
;
217 FIXME("%s %s %p %08x %p %08x %p %p %p\n",
218 debugstr_w(pwzTarget
), debugstr_w(pwzLocation
), pihlsite
,
219 dwSiteData
, pihlframe
, grfHLNF
, pibc
, pibsc
, pihlbc
);
221 r
= HlinkCreateFromString( pwzTarget
, pwzLocation
, NULL
, pihlsite
,
222 dwSiteData
, NULL
, &IID_IHlink
, (LPVOID
*) &hlink
);
224 r
= HlinkNavigate(hlink
, pihlframe
, grfHLNF
, pibc
, pibsc
, pihlbc
);
229 /***********************************************************************
230 * HlinkIsShortcut (HLINK.@)
232 HRESULT WINAPI
HlinkIsShortcut(LPCWSTR pwzFileName
)
236 static const WCHAR url_ext
[] = {'.','u','r','l',0};
238 TRACE("(%s)\n", debugstr_w(pwzFileName
));
243 len
= strlenW(pwzFileName
)-4;
247 return strcmpiW(pwzFileName
+len
, url_ext
) ? S_FALSE
: S_OK
;
250 /***********************************************************************
251 * HlinkGetSpecialReference (HLINK.@)
253 HRESULT WINAPI
HlinkGetSpecialReference(ULONG uReference
, LPWSTR
*ppwzReference
)
255 DWORD res
, type
, size
= 100;
260 static const WCHAR start_pageW
[] = {'S','t','a','r','t',' ','P','a','g','e',0};
261 static const WCHAR search_pageW
[] = {'S','e','a','r','c','h',' ','P','a','g','e',0};
263 static const WCHAR ie_main_keyW
[] =
264 {'S','o','f','t','w','a','r','e',
265 '\\','M','i','c','r','o','s','o','f','t','\\',
266 'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
267 '\\','M','a','i','n',0};
269 TRACE("(%u %p)\n", uReference
, ppwzReference
);
271 *ppwzReference
= NULL
;
275 value_name
= start_pageW
;
277 case HLSR_SEARCHPAGE
:
278 value_name
= search_pageW
;
280 case HLSR_HISTORYFOLDER
:
286 res
= RegOpenKeyW(HKEY_CURRENT_USER
, ie_main_keyW
, &hkey
);
287 if(res
!= ERROR_SUCCESS
) {
288 WARN("Could not open key: %u\n", res
);
289 return HRESULT_FROM_WIN32(res
);
292 buf
= CoTaskMemAlloc(size
);
293 res
= RegQueryValueExW(hkey
, value_name
, NULL
, &type
, (PBYTE
)buf
, &size
);
294 buf
= CoTaskMemRealloc(buf
, size
);
295 if(res
== ERROR_MORE_DATA
)
296 res
= RegQueryValueExW(hkey
, value_name
, NULL
, &type
, (PBYTE
)buf
, &size
);
298 if(res
!= ERROR_SUCCESS
) {
299 WARN("Could not query value %s: %u\n", debugstr_w(value_name
), res
);
301 return HRESULT_FROM_WIN32(res
);
304 *ppwzReference
= buf
;
308 /***********************************************************************
309 * HlinkTranslateURL (HLINK.@)
311 HRESULT WINAPI
HlinkTranslateURL(LPCWSTR pwzURL
, DWORD grfFlags
, LPWSTR
*ppwzTranslatedURL
)
313 FIXME("(%s %08x %p)\n", debugstr_w(pwzURL
), grfFlags
, ppwzTranslatedURL
);
317 /***********************************************************************
318 * HlinkUpdateStackItem (HLINK.@)
320 HRESULT WINAPI
HlinkUpdateStackItem(IHlinkFrame
*pihlframe
, IHlinkBrowseContext
*pihlbc
,
321 ULONG uHLID
, IMoniker
*pimkTrgt
, LPCWSTR pwzLocation
, LPCWSTR pwzFriendlyName
)
323 FIXME("(%p %p %u %p %s %s)\n", pihlframe
, pihlbc
, uHLID
, pimkTrgt
, debugstr_w(pwzLocation
),
324 debugstr_w(pwzFriendlyName
));
328 /***********************************************************************
329 * HlinkParseDisplayName (HLINK.@)
331 HRESULT WINAPI
HlinkParseDisplayName(LPBC pibc
, LPCWSTR pwzDisplayName
, BOOL fNoForceAbs
,
332 ULONG
*pcchEaten
, IMoniker
**ppimk
)
336 TRACE("(%p %s %x %p %p)\n", pibc
, debugstr_w(pwzDisplayName
), fNoForceAbs
, pcchEaten
, ppimk
);
339 FIXME("Unsupported fNoForceAbs\n");
341 hres
= MkParseDisplayNameEx(pibc
, pwzDisplayName
, pcchEaten
, ppimk
);
345 hres
= MkParseDisplayName(pibc
, pwzDisplayName
, pcchEaten
, ppimk
);
349 hres
= CreateFileMoniker(pwzDisplayName
, ppimk
);
351 *pcchEaten
= strlenW(pwzDisplayName
);
356 /***********************************************************************
357 * HlinkResolveMonikerForData (HLINK.@)
359 HRESULT WINAPI
HlinkResolveMonikerForData(LPMONIKER pimkReference
, DWORD reserved
, LPBC pibc
,
360 ULONG cFmtetc
, FORMATETC
*rgFmtetc
, IBindStatusCallback
*pibsc
, LPMONIKER pimkBase
)
362 LPOLESTR name
= NULL
;
368 TRACE("(%p %x %p %d %p %p %p)\n", pimkReference
, reserved
, pibc
, cFmtetc
, rgFmtetc
, pibsc
, pimkBase
);
370 if(cFmtetc
|| rgFmtetc
|| pimkBase
)
371 FIXME("Unsupported args\n");
373 hres
= RegisterBindStatusCallback(pibc
, pibsc
, NULL
/* FIXME */, 0);
377 hres
= IMoniker_IsSystemMoniker(pimkReference
, &mksys
);
378 if(SUCCEEDED(hres
) && mksys
!= MKSYS_URLMONIKER
)
379 WARN("sysmk = %x\n", mksys
);
381 /* FIXME: What is it for? */
382 CreateBindCtx(0, &bctx
);
383 hres
= IMoniker_GetDisplayName(pimkReference
, bctx
, NULL
, &name
);
384 IBindCtx_Release(bctx
);
385 if(SUCCEEDED(hres
)) {
386 TRACE("got display name %s\n", debugstr_w(name
));
390 return IMoniker_BindToStorage(pimkReference
, pibc
, NULL
, &IID_IUnknown
, &obj
);
393 static HRESULT WINAPI
HLinkCF_fnQueryInterface ( LPCLASSFACTORY iface
,
394 REFIID riid
, LPVOID
*ppvObj
)
396 CFImpl
*This
= (CFImpl
*)iface
;
398 TRACE("(%p)->(%s)\n",This
,debugstr_guid(riid
));
402 if (IsEqualIID(riid
, &IID_IUnknown
) ||
403 IsEqualIID(riid
, &IID_IClassFactory
))
409 TRACE("-- E_NOINTERFACE\n");
410 return E_NOINTERFACE
;
413 static ULONG WINAPI
HLinkCF_fnAddRef (LPCLASSFACTORY iface
)
418 static ULONG WINAPI
HLinkCF_fnRelease(LPCLASSFACTORY iface
)
423 static HRESULT WINAPI
HLinkCF_fnCreateInstance( LPCLASSFACTORY iface
,
424 LPUNKNOWN pUnkOuter
, REFIID riid
, LPVOID
*ppvObject
)
426 CFImpl
*This
= (CFImpl
*)iface
;
428 TRACE("%p->(%p,%s,%p)\n", This
, pUnkOuter
, debugstr_guid(riid
), ppvObject
);
432 return This
->lpfnCI(pUnkOuter
, riid
, ppvObject
);
435 static HRESULT WINAPI
HLinkCF_fnLockServer(LPCLASSFACTORY iface
, BOOL fLock
)
437 FIXME("%p %d\n", iface
, fLock
);
441 static const IClassFactoryVtbl hlcfvt
=
443 HLinkCF_fnQueryInterface
,
446 HLinkCF_fnCreateInstance
,
450 static CFImpl HLink_cf
= { &hlcfvt
, HLink_Constructor
};
451 static CFImpl HLinkBrowseContext_cf
= { &hlcfvt
, HLinkBrowseContext_Constructor
};
453 /***********************************************************************
454 * DllGetClassObject (HLINK.@)
456 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID iid
, LPVOID
*ppv
)
458 IClassFactory
*pcf
= NULL
;
460 TRACE("%s %s %p\n", debugstr_guid(rclsid
), debugstr_guid(iid
), ppv
);
466 if (IsEqualIID(rclsid
, &CLSID_StdHlink
))
467 pcf
= (IClassFactory
*) &HLink_cf
;
468 else if (IsEqualIID(rclsid
, &CLSID_StdHlinkBrowseContext
))
469 pcf
= (IClassFactory
*) &HLinkBrowseContext_cf
;
471 return CLASS_E_CLASSNOTAVAILABLE
;
473 return IClassFactory_QueryInterface(pcf
, iid
, ppv
);
476 static HRESULT
register_clsid(LPCGUID guid
)
478 static const WCHAR clsid
[] =
479 {'C','L','S','I','D','\\',0};
480 static const WCHAR ips
[] =
481 {'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
482 static const WCHAR hlink
[] =
483 {'h','l','i','n','k','.','d','l','l',0};
484 static const WCHAR threading_model
[] =
485 {'T','h','r','e','a','d','i','n','g','M','o','d','e','l',0};
486 static const WCHAR apartment
[] =
487 {'A','p','a','r','t','m','e','n','t',0};
492 lstrcpyW(path
, clsid
);
493 StringFromGUID2(guid
, &path
[6], 80);
495 r
= RegCreateKeyW(HKEY_CLASSES_ROOT
, path
, &key
);
496 if (r
!= ERROR_SUCCESS
)
499 RegSetValueExW(key
, NULL
, 0, REG_SZ
, (const BYTE
*)hlink
, sizeof hlink
);
500 RegSetValueExW(key
, threading_model
, 0, REG_SZ
, (const BYTE
*)apartment
, sizeof apartment
);
506 /***********************************************************************
507 * DllRegisterServer (HLINK.@)
509 HRESULT WINAPI
DllRegisterServer(void)
513 r
= register_clsid(&CLSID_StdHlink
);
515 r
= register_clsid(&CLSID_StdHlinkBrowseContext
);