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 )
62 /***********************************************************************
63 * HlinkCreateFromMoniker (HLINK.@)
65 HRESULT WINAPI
HlinkCreateFromMoniker( IMoniker
*pimkTrgt
, LPCWSTR pwzLocation
,
66 LPCWSTR pwzFriendlyName
, IHlinkSite
* pihlsite
, DWORD dwSiteData
,
67 IUnknown
* piunkOuter
, REFIID riid
, void** ppvObj
)
72 TRACE("%p %s %s %p %i %p %s %p\n", pimkTrgt
, debugstr_w(pwzLocation
),
73 debugstr_w(pwzFriendlyName
), pihlsite
, dwSiteData
, piunkOuter
,
74 debugstr_guid(riid
), ppvObj
);
76 r
= CoCreateInstance(&CLSID_StdHlink
, piunkOuter
, CLSCTX_INPROC_SERVER
, riid
, (LPVOID
*)&hl
);
81 IHlink_SetStringReference(hl
, HLINKSETF_LOCATION
, NULL
, pwzLocation
);
83 IHlink_SetFriendlyName(hl
, pwzFriendlyName
);
85 IHlink_SetHlinkSite(hl
, pihlsite
, dwSiteData
);
87 IHlink_SetMonikerReference(hl
, 0, pimkTrgt
, pwzLocation
);
91 TRACE("Returning %i\n",r
);
96 /***********************************************************************
97 * HlinkCreateFromString (HLINK.@)
99 HRESULT WINAPI
HlinkCreateFromString( LPCWSTR pwzTarget
, LPCWSTR pwzLocation
,
100 LPCWSTR pwzFriendlyName
, IHlinkSite
* pihlsite
, DWORD dwSiteData
,
101 IUnknown
* piunkOuter
, REFIID riid
, void** ppvObj
)
106 TRACE("%s %s %s %p %i %p %s %p\n", debugstr_w(pwzTarget
),
107 debugstr_w(pwzLocation
), debugstr_w(pwzFriendlyName
), pihlsite
,
108 dwSiteData
, piunkOuter
, debugstr_guid(riid
), ppvObj
);
110 r
= CoCreateInstance(&CLSID_StdHlink
, piunkOuter
, CLSCTX_INPROC_SERVER
, riid
, (LPVOID
*)&hl
);
115 IHlink_SetStringReference(hl
, HLINKSETF_LOCATION
, NULL
, pwzLocation
);
119 IMoniker
*pTgtMk
= NULL
;
120 IBindCtx
*pbc
= NULL
;
123 CreateBindCtx(0, &pbc
);
124 r
= MkParseDisplayName(pbc
, pwzTarget
, &eaten
, &pTgtMk
);
125 IBindCtx_Release(pbc
);
129 LPCWSTR p
= strchrW(pwzTarget
, ':');
130 if (p
&& (p
- pwzTarget
> 1))
131 r
= CreateURLMoniker(NULL
, pwzTarget
, &pTgtMk
);
133 r
= CreateFileMoniker(pwzTarget
,&pTgtMk
);
138 ERR("couldn't create moniker for %s, failed with error 0x%08x\n",
139 debugstr_w(pwzTarget
), r
);
143 IHlink_SetMonikerReference(hl
, 0, pTgtMk
, pwzLocation
);
144 IMoniker_Release(pTgtMk
);
146 IHlink_SetStringReference(hl
, HLINKSETF_TARGET
, pwzTarget
, NULL
);
150 IHlink_SetFriendlyName(hl
, pwzFriendlyName
);
152 IHlink_SetHlinkSite(hl
, pihlsite
, dwSiteData
);
154 TRACE("Returning %i\n",r
);
161 /***********************************************************************
162 * HlinkNavigate (HLINK.@)
164 HRESULT WINAPI
HlinkCreateBrowseContext( IUnknown
* piunkOuter
, REFIID riid
, void** ppvObj
)
168 TRACE("%p %s %p\n", piunkOuter
, debugstr_guid(riid
), ppvObj
);
170 r
= CoCreateInstance(&CLSID_StdHlinkBrowseContext
, piunkOuter
, CLSCTX_INPROC_SERVER
, riid
, ppvObj
);
172 TRACE("returning %i\n",r
);
177 /***********************************************************************
178 * HlinkNavigate (HLINK.@)
180 HRESULT WINAPI
HlinkNavigate(IHlink
*phl
, IHlinkFrame
*phlFrame
,
181 DWORD grfHLNF
, LPBC pbc
, IBindStatusCallback
*pbsc
,
182 IHlinkBrowseContext
*phlbc
)
186 TRACE("%p %p %i %p %p %p\n", phl
, phlFrame
, grfHLNF
, pbc
, pbsc
, phlbc
);
189 r
= IHlinkFrame_Navigate(phlFrame
, grfHLNF
, pbc
, pbsc
, phl
);
191 r
= IHlink_Navigate(phl
, grfHLNF
, pbc
, pbsc
, phlbc
);
196 /***********************************************************************
197 * HlinkOnNavigate (HLINK.@)
199 HRESULT WINAPI
HlinkOnNavigate( IHlinkFrame
*phlFrame
,
200 IHlinkBrowseContext
* phlbc
, DWORD grfHLNF
, IMoniker
*pmkTarget
,
201 LPCWSTR pwzLocation
, LPCWSTR pwzFriendlyName
, ULONG
* puHLID
)
205 TRACE("%p %p %i %p %s %s %p\n",phlFrame
, phlbc
, grfHLNF
, pmkTarget
,
206 debugstr_w(pwzLocation
), debugstr_w(pwzFriendlyName
), puHLID
);
208 r
= IHlinkBrowseContext_OnNavigateHlink(phlbc
, grfHLNF
, pmkTarget
,
209 pwzLocation
, pwzFriendlyName
, puHLID
);
212 r
= IHlinkFrame_OnNavigate(phlFrame
,grfHLNF
,pmkTarget
, pwzLocation
,
218 /***********************************************************************
219 * HlinkCreateFromData (HLINK.@)
221 HRESULT WINAPI
HlinkCreateFromData(IDataObject
*piDataObj
,
222 IHlinkSite
*pihlsite
, DWORD dwSiteData
, IUnknown
*piunkOuter
,
223 REFIID riid
, void **ppvObj
)
225 FIXME("%p %p %d %p %p %p\n",
226 piDataObj
, pihlsite
, dwSiteData
, piunkOuter
, riid
, ppvObj
);
231 /***********************************************************************
232 * HlinkQueryCreateFromData (HLINK.@)
234 HRESULT WINAPI
HlinkQueryCreateFromData(IDataObject
* piDataObj
)
236 FIXME("%p\n", piDataObj
);
240 /***********************************************************************
241 * HlinkNavigateToStringReference (HLINK.@)
243 HRESULT WINAPI
HlinkNavigateToStringReference( LPCWSTR pwzTarget
,
244 LPCWSTR pwzLocation
, IHlinkSite
*pihlsite
, DWORD dwSiteData
,
245 IHlinkFrame
*pihlframe
, DWORD grfHLNF
, LPBC pibc
,
246 IBindStatusCallback
*pibsc
, IHlinkBrowseContext
*pihlbc
)
249 IHlink
*hlink
= NULL
;
251 FIXME("%s %s %p %08x %p %08x %p %p %p\n",
252 debugstr_w(pwzTarget
), debugstr_w(pwzLocation
), pihlsite
,
253 dwSiteData
, pihlframe
, grfHLNF
, pibc
, pibsc
, pihlbc
);
255 r
= HlinkCreateFromString( pwzTarget
, pwzLocation
, NULL
, pihlsite
,
256 dwSiteData
, NULL
, &IID_IHlink
, (LPVOID
*) &hlink
);
258 r
= HlinkNavigate(hlink
, pihlframe
, grfHLNF
, pibc
, pibsc
, pihlbc
);
263 /***********************************************************************
264 * HlinkIsShortcut (HLINK.@)
266 HRESULT WINAPI
HlinkIsShortcut(LPCWSTR pwzFileName
)
270 static const WCHAR url_ext
[] = {'.','u','r','l',0};
272 TRACE("(%s)\n", debugstr_w(pwzFileName
));
277 len
= strlenW(pwzFileName
)-4;
281 return strcmpiW(pwzFileName
+len
, url_ext
) ? S_FALSE
: S_OK
;
284 /***********************************************************************
285 * HlinkGetSpecialReference (HLINK.@)
287 HRESULT WINAPI
HlinkGetSpecialReference(ULONG uReference
, LPWSTR
*ppwzReference
)
289 DWORD res
, type
, size
= 100;
294 static const WCHAR start_pageW
[] = {'S','t','a','r','t',' ','P','a','g','e',0};
295 static const WCHAR search_pageW
[] = {'S','e','a','r','c','h',' ','P','a','g','e',0};
297 static const WCHAR ie_main_keyW
[] =
298 {'S','o','f','t','w','a','r','e',
299 '\\','M','i','c','r','o','s','o','f','t','\\',
300 'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
301 '\\','M','a','i','n',0};
303 TRACE("(%u %p)\n", uReference
, ppwzReference
);
305 *ppwzReference
= NULL
;
309 value_name
= start_pageW
;
311 case HLSR_SEARCHPAGE
:
312 value_name
= search_pageW
;
314 case HLSR_HISTORYFOLDER
:
320 res
= RegOpenKeyW(HKEY_CURRENT_USER
, ie_main_keyW
, &hkey
);
321 if(res
!= ERROR_SUCCESS
) {
322 WARN("Could not open key: %u\n", res
);
323 return HRESULT_FROM_WIN32(res
);
326 buf
= CoTaskMemAlloc(size
);
327 res
= RegQueryValueExW(hkey
, value_name
, NULL
, &type
, (PBYTE
)buf
, &size
);
328 buf
= CoTaskMemRealloc(buf
, size
);
329 if(res
== ERROR_MORE_DATA
)
330 res
= RegQueryValueExW(hkey
, value_name
, NULL
, &type
, (PBYTE
)buf
, &size
);
332 if(res
!= ERROR_SUCCESS
) {
333 WARN("Could not query value %s: %u\n", debugstr_w(value_name
), res
);
335 return HRESULT_FROM_WIN32(res
);
338 *ppwzReference
= buf
;
342 /***********************************************************************
343 * HlinkTranslateURL (HLINK.@)
345 HRESULT WINAPI
HlinkTranslateURL(LPCWSTR pwzURL
, DWORD grfFlags
, LPWSTR
*ppwzTranslatedURL
)
347 FIXME("(%s %08x %p)\n", debugstr_w(pwzURL
), grfFlags
, ppwzTranslatedURL
);
351 /***********************************************************************
352 * HlinkUpdateStackItem (HLINK.@)
354 HRESULT WINAPI
HlinkUpdateStackItem(IHlinkFrame
*pihlframe
, IHlinkBrowseContext
*pihlbc
,
355 ULONG uHLID
, IMoniker
*pimkTrgt
, LPCWSTR pwzLocation
, LPCWSTR pwzFriendlyName
)
357 FIXME("(%p %p %u %p %s %s)\n", pihlframe
, pihlbc
, uHLID
, pimkTrgt
, debugstr_w(pwzLocation
),
358 debugstr_w(pwzFriendlyName
));
362 /***********************************************************************
363 * HlinkParseDisplayName (HLINK.@)
365 HRESULT WINAPI
HlinkParseDisplayName(LPBC pibc
, LPCWSTR pwzDisplayName
, BOOL fNoForceAbs
,
366 ULONG
*pcchEaten
, IMoniker
**ppimk
)
370 TRACE("(%p %s %x %p %p)\n", pibc
, debugstr_w(pwzDisplayName
), fNoForceAbs
, pcchEaten
, ppimk
);
373 FIXME("Unsupported fNoForceAbs\n");
375 hres
= MkParseDisplayNameEx(pibc
, pwzDisplayName
, pcchEaten
, ppimk
);
379 hres
= MkParseDisplayName(pibc
, pwzDisplayName
, pcchEaten
, ppimk
);
383 hres
= CreateFileMoniker(pwzDisplayName
, ppimk
);
385 *pcchEaten
= strlenW(pwzDisplayName
);
390 /***********************************************************************
391 * HlinkResolveMonikerForData (HLINK.@)
393 HRESULT WINAPI
HlinkResolveMonikerForData(LPMONIKER pimkReference
, DWORD reserved
, LPBC pibc
,
394 ULONG cFmtetc
, FORMATETC
*rgFmtetc
, IBindStatusCallback
*pibsc
, LPMONIKER pimkBase
)
396 LPOLESTR name
= NULL
;
402 TRACE("(%p %x %p %d %p %p %p)\n", pimkReference
, reserved
, pibc
, cFmtetc
, rgFmtetc
, pibsc
, pimkBase
);
404 if(cFmtetc
|| rgFmtetc
|| pimkBase
)
405 FIXME("Unsupported args\n");
407 hres
= RegisterBindStatusCallback(pibc
, pibsc
, NULL
/* FIXME */, 0);
411 hres
= IMoniker_IsSystemMoniker(pimkReference
, &mksys
);
412 if(SUCCEEDED(hres
) && mksys
!= MKSYS_URLMONIKER
)
413 WARN("sysmk = %x\n", mksys
);
415 /* FIXME: What is it for? */
416 CreateBindCtx(0, &bctx
);
417 hres
= IMoniker_GetDisplayName(pimkReference
, bctx
, NULL
, &name
);
418 IBindCtx_Release(bctx
);
419 if(SUCCEEDED(hres
)) {
420 TRACE("got display name %s\n", debugstr_w(name
));
424 return IMoniker_BindToStorage(pimkReference
, pibc
, NULL
, &IID_IUnknown
, &obj
);
427 static HRESULT WINAPI
HLinkCF_fnQueryInterface ( LPCLASSFACTORY iface
,
428 REFIID riid
, LPVOID
*ppvObj
)
430 CFImpl
*This
= (CFImpl
*)iface
;
432 TRACE("(%p)->(%s)\n",This
,debugstr_guid(riid
));
436 if (IsEqualIID(riid
, &IID_IUnknown
) ||
437 IsEqualIID(riid
, &IID_IClassFactory
))
443 TRACE("-- E_NOINTERFACE\n");
444 return E_NOINTERFACE
;
447 static ULONG WINAPI
HLinkCF_fnAddRef (LPCLASSFACTORY iface
)
452 static ULONG WINAPI
HLinkCF_fnRelease(LPCLASSFACTORY iface
)
457 static HRESULT WINAPI
HLinkCF_fnCreateInstance( LPCLASSFACTORY iface
,
458 LPUNKNOWN pUnkOuter
, REFIID riid
, LPVOID
*ppvObject
)
460 CFImpl
*This
= (CFImpl
*)iface
;
462 TRACE("%p->(%p,%s,%p)\n", This
, pUnkOuter
, debugstr_guid(riid
), ppvObject
);
466 return This
->lpfnCI(pUnkOuter
, riid
, ppvObject
);
469 static HRESULT WINAPI
HLinkCF_fnLockServer(LPCLASSFACTORY iface
, BOOL fLock
)
471 FIXME("%p %d\n", iface
, fLock
);
475 static const IClassFactoryVtbl hlcfvt
=
477 HLinkCF_fnQueryInterface
,
480 HLinkCF_fnCreateInstance
,
484 static CFImpl HLink_cf
= { &hlcfvt
, &HLink_Constructor
};
485 static CFImpl HLinkBrowseContext_cf
= { &hlcfvt
, &HLinkBrowseContext_Constructor
};
487 /***********************************************************************
488 * DllGetClassObject (HLINK.@)
490 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID iid
, LPVOID
*ppv
)
492 IClassFactory
*pcf
= NULL
;
494 TRACE("%s %s %p\n", debugstr_guid(rclsid
), debugstr_guid(iid
), ppv
);
500 if (IsEqualIID(rclsid
, &CLSID_StdHlink
))
501 pcf
= (IClassFactory
*) &HLink_cf
;
502 else if (IsEqualIID(rclsid
, &CLSID_StdHlinkBrowseContext
))
503 pcf
= (IClassFactory
*) &HLinkBrowseContext_cf
;
505 return CLASS_E_CLASSNOTAVAILABLE
;
507 return IClassFactory_QueryInterface(pcf
, iid
, ppv
);
510 static HRESULT
register_clsid(LPCGUID guid
)
512 static const WCHAR clsid
[] =
513 {'C','L','S','I','D','\\',0};
514 static const WCHAR ips
[] =
515 {'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
516 static const WCHAR hlink
[] =
517 {'h','l','i','n','k','.','d','l','l',0};
518 static const WCHAR threading_model
[] =
519 {'T','h','r','e','a','d','i','n','g','M','o','d','e','l',0};
520 static const WCHAR apartment
[] =
521 {'A','p','a','r','t','m','e','n','t',0};
526 lstrcpyW(path
, clsid
);
527 StringFromGUID2(guid
, &path
[6], 80);
529 r
= RegCreateKeyW(HKEY_CLASSES_ROOT
, path
, &key
);
530 if (r
!= ERROR_SUCCESS
)
533 RegSetValueExW(key
, NULL
, 0, REG_SZ
, (const BYTE
*)hlink
, sizeof hlink
);
534 RegSetValueExW(key
, threading_model
, 0, REG_SZ
, (const BYTE
*)apartment
, sizeof apartment
);
540 /***********************************************************************
541 * DllRegisterServer (HLINK.@)
543 HRESULT WINAPI
DllRegisterServer(void)
547 r
= register_clsid(&CLSID_StdHlink
);
549 r
= register_clsid(&CLSID_StdHlinkBrowseContext
);