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
)
105 TRACE("%s %s %s %p %i %p %s %p\n", debugstr_w(pwzTarget
),
106 debugstr_w(pwzLocation
), debugstr_w(pwzFriendlyName
), pihlsite
,
107 dwSiteData
, piunkOuter
, debugstr_guid(riid
), ppvObj
);
109 r
= CoCreateInstance(&CLSID_StdHlink
, piunkOuter
, CLSCTX_INPROC_SERVER
, riid
, (LPVOID
*)&hl
);
115 hash
= strchrW(pwzTarget
, '#');
118 if (hash
== pwzTarget
)
122 int tgt_len
= hash
- pwzTarget
;
123 tgt
= heap_alloc((tgt_len
+ 1) * sizeof(WCHAR
));
125 return E_OUTOFMEMORY
;
126 memcpy(tgt
, pwzTarget
, tgt_len
* sizeof(WCHAR
));
136 tgt
= hlink_strdupW(pwzTarget
);
138 return E_OUTOFMEMORY
;
148 IHlink_SetStringReference(hl
, HLINKSETF_TARGET
| HLINKSETF_LOCATION
, tgt
, loc
);
153 IHlink_SetFriendlyName(hl
, pwzFriendlyName
);
156 IHlink_SetHlinkSite(hl
, pihlsite
, dwSiteData
);
158 TRACE("Returning %i\n",r
);
165 /***********************************************************************
166 * HlinkCreateBrowseContext (HLINK.@)
168 HRESULT WINAPI
HlinkCreateBrowseContext( IUnknown
* piunkOuter
, REFIID riid
, void** ppvObj
)
172 TRACE("%p %s %p\n", piunkOuter
, debugstr_guid(riid
), ppvObj
);
174 r
= CoCreateInstance(&CLSID_StdHlinkBrowseContext
, piunkOuter
, CLSCTX_INPROC_SERVER
, riid
, ppvObj
);
176 TRACE("returning %i\n",r
);
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 %p %p\n",
230 piDataObj
, pihlsite
, dwSiteData
, piunkOuter
, 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 FIXME("%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
);
267 /***********************************************************************
268 * HlinkIsShortcut (HLINK.@)
270 HRESULT WINAPI
HlinkIsShortcut(LPCWSTR pwzFileName
)
274 static const WCHAR url_ext
[] = {'.','u','r','l',0};
276 TRACE("(%s)\n", debugstr_w(pwzFileName
));
281 len
= strlenW(pwzFileName
)-4;
285 return strcmpiW(pwzFileName
+len
, url_ext
) ? S_FALSE
: S_OK
;
288 /***********************************************************************
289 * HlinkGetSpecialReference (HLINK.@)
291 HRESULT WINAPI
HlinkGetSpecialReference(ULONG uReference
, LPWSTR
*ppwzReference
)
293 DWORD res
, type
, size
= 100;
298 static const WCHAR start_pageW
[] = {'S','t','a','r','t',' ','P','a','g','e',0};
299 static const WCHAR search_pageW
[] = {'S','e','a','r','c','h',' ','P','a','g','e',0};
301 static const WCHAR ie_main_keyW
[] =
302 {'S','o','f','t','w','a','r','e',
303 '\\','M','i','c','r','o','s','o','f','t','\\',
304 'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
305 '\\','M','a','i','n',0};
307 TRACE("(%u %p)\n", uReference
, ppwzReference
);
309 *ppwzReference
= NULL
;
313 value_name
= start_pageW
;
315 case HLSR_SEARCHPAGE
:
316 value_name
= search_pageW
;
318 case HLSR_HISTORYFOLDER
:
324 res
= RegOpenKeyW(HKEY_CURRENT_USER
, ie_main_keyW
, &hkey
);
325 if(res
!= ERROR_SUCCESS
) {
326 WARN("Could not open key: %u\n", res
);
327 return HRESULT_FROM_WIN32(res
);
330 buf
= CoTaskMemAlloc(size
);
331 res
= RegQueryValueExW(hkey
, value_name
, NULL
, &type
, (PBYTE
)buf
, &size
);
332 buf
= CoTaskMemRealloc(buf
, size
);
333 if(res
== ERROR_MORE_DATA
)
334 res
= RegQueryValueExW(hkey
, value_name
, NULL
, &type
, (PBYTE
)buf
, &size
);
336 if(res
!= ERROR_SUCCESS
) {
337 WARN("Could not query value %s: %u\n", debugstr_w(value_name
), res
);
339 return HRESULT_FROM_WIN32(res
);
342 *ppwzReference
= buf
;
346 /***********************************************************************
347 * HlinkTranslateURL (HLINK.@)
349 HRESULT WINAPI
HlinkTranslateURL(LPCWSTR pwzURL
, DWORD grfFlags
, LPWSTR
*ppwzTranslatedURL
)
351 FIXME("(%s %08x %p)\n", debugstr_w(pwzURL
), grfFlags
, ppwzTranslatedURL
);
355 /***********************************************************************
356 * HlinkUpdateStackItem (HLINK.@)
358 HRESULT WINAPI
HlinkUpdateStackItem(IHlinkFrame
*pihlframe
, IHlinkBrowseContext
*pihlbc
,
359 ULONG uHLID
, IMoniker
*pimkTrgt
, LPCWSTR pwzLocation
, LPCWSTR pwzFriendlyName
)
361 FIXME("(%p %p %u %p %s %s)\n", pihlframe
, pihlbc
, uHLID
, pimkTrgt
, debugstr_w(pwzLocation
),
362 debugstr_w(pwzFriendlyName
));
366 /***********************************************************************
367 * HlinkParseDisplayName (HLINK.@)
369 HRESULT WINAPI
HlinkParseDisplayName(LPBC pibc
, LPCWSTR pwzDisplayName
, BOOL fNoForceAbs
,
370 ULONG
*pcchEaten
, IMoniker
**ppimk
)
374 TRACE("(%p %s %x %p %p)\n", pibc
, debugstr_w(pwzDisplayName
), fNoForceAbs
, pcchEaten
, ppimk
);
377 FIXME("Unsupported fNoForceAbs\n");
379 hres
= MkParseDisplayNameEx(pibc
, pwzDisplayName
, pcchEaten
, ppimk
);
383 hres
= MkParseDisplayName(pibc
, pwzDisplayName
, pcchEaten
, ppimk
);
387 hres
= CreateFileMoniker(pwzDisplayName
, ppimk
);
389 *pcchEaten
= strlenW(pwzDisplayName
);
394 /***********************************************************************
395 * HlinkResolveMonikerForData (HLINK.@)
397 HRESULT WINAPI
HlinkResolveMonikerForData(LPMONIKER pimkReference
, DWORD reserved
, LPBC pibc
,
398 ULONG cFmtetc
, FORMATETC
*rgFmtetc
, IBindStatusCallback
*pibsc
, LPMONIKER pimkBase
)
400 LPOLESTR name
= NULL
;
406 TRACE("(%p %x %p %d %p %p %p)\n", pimkReference
, reserved
, pibc
, cFmtetc
, rgFmtetc
, pibsc
, pimkBase
);
408 if(cFmtetc
|| rgFmtetc
|| pimkBase
)
409 FIXME("Unsupported args\n");
411 hres
= RegisterBindStatusCallback(pibc
, pibsc
, NULL
/* FIXME */, 0);
415 hres
= IMoniker_IsSystemMoniker(pimkReference
, &mksys
);
416 if(SUCCEEDED(hres
) && mksys
!= MKSYS_URLMONIKER
)
417 WARN("sysmk = %x\n", mksys
);
419 /* FIXME: What is it for? */
420 CreateBindCtx(0, &bctx
);
421 hres
= IMoniker_GetDisplayName(pimkReference
, bctx
, NULL
, &name
);
422 IBindCtx_Release(bctx
);
423 if(SUCCEEDED(hres
)) {
424 TRACE("got display name %s\n", debugstr_w(name
));
428 return IMoniker_BindToStorage(pimkReference
, pibc
, NULL
, &IID_IUnknown
, &obj
);
431 static HRESULT WINAPI
HLinkCF_fnQueryInterface ( LPCLASSFACTORY iface
,
432 REFIID riid
, LPVOID
*ppvObj
)
434 CFImpl
*This
= (CFImpl
*)iface
;
436 TRACE("(%p)->(%s)\n",This
,debugstr_guid(riid
));
440 if (IsEqualIID(riid
, &IID_IUnknown
) ||
441 IsEqualIID(riid
, &IID_IClassFactory
))
447 TRACE("-- E_NOINTERFACE\n");
448 return E_NOINTERFACE
;
451 static ULONG WINAPI
HLinkCF_fnAddRef (LPCLASSFACTORY iface
)
456 static ULONG WINAPI
HLinkCF_fnRelease(LPCLASSFACTORY iface
)
461 static HRESULT WINAPI
HLinkCF_fnCreateInstance( LPCLASSFACTORY iface
,
462 LPUNKNOWN pUnkOuter
, REFIID riid
, LPVOID
*ppvObject
)
464 CFImpl
*This
= (CFImpl
*)iface
;
466 TRACE("%p->(%p,%s,%p)\n", This
, pUnkOuter
, debugstr_guid(riid
), ppvObject
);
470 return This
->lpfnCI(pUnkOuter
, riid
, ppvObject
);
473 static HRESULT WINAPI
HLinkCF_fnLockServer(LPCLASSFACTORY iface
, BOOL fLock
)
475 FIXME("%p %d\n", iface
, fLock
);
479 static const IClassFactoryVtbl hlcfvt
=
481 HLinkCF_fnQueryInterface
,
484 HLinkCF_fnCreateInstance
,
488 static CFImpl HLink_cf
= { &hlcfvt
, HLink_Constructor
};
489 static CFImpl HLinkBrowseContext_cf
= { &hlcfvt
, HLinkBrowseContext_Constructor
};
491 /***********************************************************************
492 * DllGetClassObject (HLINK.@)
494 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID iid
, LPVOID
*ppv
)
496 IClassFactory
*pcf
= NULL
;
498 TRACE("%s %s %p\n", debugstr_guid(rclsid
), debugstr_guid(iid
), ppv
);
504 if (IsEqualIID(rclsid
, &CLSID_StdHlink
))
505 pcf
= (IClassFactory
*) &HLink_cf
;
506 else if (IsEqualIID(rclsid
, &CLSID_StdHlinkBrowseContext
))
507 pcf
= (IClassFactory
*) &HLinkBrowseContext_cf
;
509 return CLASS_E_CLASSNOTAVAILABLE
;
511 return IClassFactory_QueryInterface(pcf
, iid
, ppv
);
514 static HRESULT
register_clsid(LPCGUID guid
)
516 static const WCHAR clsid
[] =
517 {'C','L','S','I','D','\\',0};
518 static const WCHAR ips
[] =
519 {'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
520 static const WCHAR hlink
[] =
521 {'h','l','i','n','k','.','d','l','l',0};
522 static const WCHAR threading_model
[] =
523 {'T','h','r','e','a','d','i','n','g','M','o','d','e','l',0};
524 static const WCHAR apartment
[] =
525 {'A','p','a','r','t','m','e','n','t',0};
530 lstrcpyW(path
, clsid
);
531 StringFromGUID2(guid
, &path
[6], 80);
533 r
= RegCreateKeyW(HKEY_CLASSES_ROOT
, path
, &key
);
534 if (r
!= ERROR_SUCCESS
)
537 RegSetValueExW(key
, NULL
, 0, REG_SZ
, (const BYTE
*)hlink
, sizeof hlink
);
538 RegSetValueExW(key
, threading_model
, 0, REG_SZ
, (const BYTE
*)apartment
, sizeof apartment
);
544 /***********************************************************************
545 * DllRegisterServer (HLINK.@)
547 HRESULT WINAPI
DllRegisterServer(void)
551 r
= register_clsid(&CLSID_StdHlink
);
553 r
= register_clsid(&CLSID_StdHlinkBrowseContext
);