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
33 #include "wine/debug.h"
34 #include "wine/unicode.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(hlink);
42 extern HRESULT WINAPI HLink_Constructor(IUnknown *, REFIID, LPVOID*);
43 extern HRESULT WINAPI HLinkBrowseContext_Constructor(IUnknown *, REFIID, LPVOID*);
45 typedef HRESULT (CALLBACK *LPFNCREATEINSTANCE)(IUnknown*, REFIID, LPVOID*);
49 const IClassFactoryVtbl *lpVtbl;
50 LPFNCREATEINSTANCE lpfnCI;
53 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
55 TRACE("%p %d %p\n", hinstDLL, fdwReason, lpvReserved);
59 case DLL_WINE_PREATTACH:
60 return FALSE; /* prefer native version */
61 case DLL_PROCESS_ATTACH:
62 DisableThreadLibraryCalls(hinstDLL);
64 case DLL_PROCESS_DETACH:
70 HRESULT WINAPI DllCanUnloadNow( void )
76 HRESULT WINAPI HlinkCreateFromMoniker( IMoniker *pimkTrgt, LPCWSTR pwzLocation,
77 LPCWSTR pwzFriendlyName, IHlinkSite* pihlsite, DWORD dwSiteData,
78 IUnknown* piunkOuter, REFIID riid, void** ppvObj)
83 TRACE("%p %s %s %p %i %p %s %p\n", pimkTrgt, debugstr_w(pwzLocation),
84 debugstr_w(pwzFriendlyName), pihlsite, dwSiteData, piunkOuter,
85 debugstr_guid(riid), ppvObj);
87 r = CoCreateInstance(&CLSID_StdHlink, piunkOuter, CLSCTX_INPROC_SERVER, riid, (LPVOID*)&hl);
92 IHlink_SetStringReference(hl, HLINKSETF_LOCATION, NULL, pwzLocation);
94 IHlink_SetFriendlyName(hl, pwzFriendlyName);
96 IHlink_SetHlinkSite(hl, pihlsite, dwSiteData);
98 IHlink_SetMonikerReference(hl, 0, pimkTrgt, pwzLocation);
102 TRACE("Returning %i\n",r);
107 HRESULT WINAPI HlinkCreateFromString( LPCWSTR pwzTarget, LPCWSTR pwzLocation,
108 LPCWSTR pwzFriendlyName, IHlinkSite* pihlsite, DWORD dwSiteData,
109 IUnknown* piunkOuter, REFIID riid, void** ppvObj)
114 TRACE("%s %s %s %p %i %p %s %p\n", debugstr_w(pwzTarget),
115 debugstr_w(pwzLocation), debugstr_w(pwzFriendlyName), pihlsite,
116 dwSiteData, piunkOuter, debugstr_guid(riid), ppvObj);
118 r = CoCreateInstance(&CLSID_StdHlink, piunkOuter, CLSCTX_INPROC_SERVER, riid, (LPVOID*)&hl);
123 IHlink_SetStringReference(hl, HLINKSETF_LOCATION, NULL, pwzLocation);
127 IMoniker *pTgtMk = NULL;
128 IBindCtx *pbc = NULL;
131 CreateBindCtx(0, &pbc);
132 r = MkParseDisplayName(pbc, pwzTarget, &eaten, &pTgtMk);
133 IBindCtx_Release(pbc);
137 FIXME("ParseDisplayName failed, falling back to file\n");
138 r = CreateFileMoniker(pwzTarget,&pTgtMk);
143 IHlink_SetMonikerReference(hl, 0, pTgtMk, pwzLocation);
144 IMoniker_Release(pTgtMk);
147 FIXME("Unable to come up with a moniker, expect problems\n");
149 IHlink_SetStringReference(hl, HLINKSETF_TARGET, pwzTarget, NULL);
153 IHlink_SetFriendlyName(hl, pwzFriendlyName);
155 IHlink_SetHlinkSite(hl, pihlsite, dwSiteData);
157 TRACE("Returning %i\n",r);
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 HRESULT WINAPI HlinkNavigate(IHlink *phl, IHlinkFrame *phlFrame,
178 DWORD grfHLNF, LPBC pbc, IBindStatusCallback *pbsc,
179 IHlinkBrowseContext *phlbc)
183 TRACE("%p %p %i %p %p %p\n", phl, phlFrame, grfHLNF, pbc, pbsc, phlbc);
186 r = IHlinkFrame_Navigate(phlFrame, grfHLNF, pbc, pbsc, phl);
188 r = IHlink_Navigate(phl, grfHLNF, pbc, pbsc, phlbc);
193 HRESULT WINAPI HlinkOnNavigate( IHlinkFrame *phlFrame,
194 IHlinkBrowseContext* phlbc, DWORD grfHLNF, IMoniker *pmkTarget,
195 LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName, ULONG* puHLID)
199 TRACE("%p %p %i %p %s %s %p\n",phlFrame, phlbc, grfHLNF, pmkTarget,
200 debugstr_w(pwzLocation), debugstr_w(pwzFriendlyName), puHLID);
202 r = IHlinkBrowseContext_OnNavigateHlink(phlbc, grfHLNF, pmkTarget,
203 pwzLocation, pwzFriendlyName, puHLID);
206 r = IHlinkFrame_OnNavigate(phlFrame,grfHLNF,pmkTarget, pwzLocation,
212 HRESULT WINAPI HlinkCreateFromData(IDataObject *piDataObj,
213 IHlinkSite *pihlsite, DWORD dwSiteData, IUnknown *piunkOuter,
214 REFIID riid, void **ppvObj)
216 FIXME("%p %p %d %p %p %p\n",
217 piDataObj, pihlsite, dwSiteData, piunkOuter, riid, ppvObj);
222 HRESULT WINAPI HlinkQueryCreateFromData(IDataObject* piDataObj)
224 FIXME("%p\n", piDataObj);
228 HRESULT WINAPI HlinkCreateExtensionServices(LPCWSTR pwzAdditionalHeaders,
229 HWND phwnd, LPCWSTR pszUsername, LPCWSTR pszPassword,
230 IUnknown *punkOuter, REFIID riid, void** ppvObj)
232 FIXME("%s %p %s %s %p %s %p\n",debugstr_w(pwzAdditionalHeaders),
233 phwnd, debugstr_w(pszUsername), debugstr_w(pszPassword),
234 punkOuter, debugstr_guid(riid), ppvObj);
238 HRESULT WINAPI HlinkNavigateToStringReference( LPCWSTR pwzTarget,
239 LPCWSTR pwzLocation, IHlinkSite *pihlsite, DWORD dwSiteData,
240 IHlinkFrame *pihlframe, DWORD grfHLNF, LPBC pibc,
241 IBindStatusCallback *pibsc, IHlinkBrowseContext *pihlbc)
244 IHlink *hlink = NULL;
246 FIXME("%s %s %p %08x %p %08x %p %p %p\n",
247 debugstr_w(pwzTarget), debugstr_w(pwzLocation), pihlsite,
248 dwSiteData, pihlframe, grfHLNF, pibc, pibsc, pihlbc);
250 r = HlinkCreateFromString( pwzTarget, pwzLocation, NULL, pihlsite,
251 dwSiteData, NULL, &IID_IHlink, (LPVOID*) &hlink );
253 r = HlinkNavigate(hlink, pihlframe, grfHLNF, pibc, pibsc, pihlbc);
258 HRESULT WINAPI HlinkIsShortcut(LPCWSTR pwzFileName)
262 static const WCHAR url_ext[] = {'.','u','r','l',0};
264 TRACE("(%s)\n", debugstr_w(pwzFileName));
269 len = strlenW(pwzFileName)-4;
273 return strcmpiW(pwzFileName+len, url_ext) ? S_FALSE : S_OK;
276 HRESULT WINAPI HlinkTranslateURL(LPCWSTR pwzURL, DWORD grfFlags, LPWSTR *ppwzTranslatedURL)
278 FIXME("(%s %08x %p)\n", debugstr_w(pwzURL), grfFlags, ppwzTranslatedURL);
282 static HRESULT WINAPI HLinkCF_fnQueryInterface ( LPCLASSFACTORY iface,
283 REFIID riid, LPVOID *ppvObj)
285 CFImpl *This = (CFImpl *)iface;
287 TRACE("(%p)->(%s)\n",This,debugstr_guid(riid));
291 if (IsEqualIID(riid, &IID_IUnknown) ||
292 IsEqualIID(riid, &IID_IClassFactory))
298 TRACE("-- E_NOINTERFACE\n");
299 return E_NOINTERFACE;
302 static ULONG WINAPI HLinkCF_fnAddRef (LPCLASSFACTORY iface)
307 static ULONG WINAPI HLinkCF_fnRelease(LPCLASSFACTORY iface)
312 static HRESULT WINAPI HLinkCF_fnCreateInstance( LPCLASSFACTORY iface,
313 LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
315 CFImpl *This = (CFImpl *)iface;
317 TRACE("%p->(%p,%s,%p)\n", This, pUnkOuter, debugstr_guid(riid), ppvObject);
321 return This->lpfnCI(pUnkOuter, riid, ppvObject);
324 static HRESULT WINAPI HLinkCF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
326 FIXME("%p %d\n", iface, fLock);
330 static const IClassFactoryVtbl hlcfvt =
332 HLinkCF_fnQueryInterface,
335 HLinkCF_fnCreateInstance,
339 static CFImpl HLink_cf = { &hlcfvt, &HLink_Constructor };
340 static CFImpl HLinkBrowseContext_cf = { &hlcfvt, &HLinkBrowseContext_Constructor };
342 /***********************************************************************
343 * DllGetClassObject (HLINK.@)
345 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
347 IClassFactory *pcf = NULL;
349 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
355 if (IsEqualIID(rclsid, &CLSID_StdHlink))
356 pcf = (IClassFactory*) &HLink_cf;
357 else if (IsEqualIID(rclsid, &CLSID_StdHlinkBrowseContext))
358 pcf = (IClassFactory*) &HLinkBrowseContext_cf;
360 return CLASS_E_CLASSNOTAVAILABLE;
362 return IClassFactory_QueryInterface(pcf, iid, ppv);
365 static HRESULT register_clsid(LPCGUID guid)
367 static const WCHAR clsid[] =
368 {'C','L','S','I','D','\\',0};
369 static const WCHAR ips[] =
370 {'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
371 static const WCHAR hlink[] =
372 {'h','l','i','n','k','.','d','l','l',0};
373 static const WCHAR threading_model[] =
374 {'T','h','r','e','a','d','i','n','g','M','o','d','e','l',0};
375 static const WCHAR apartment[] =
376 {'A','p','a','r','t','m','e','n','t',0};
381 lstrcpyW(path, clsid);
382 StringFromGUID2(guid, &path[6], 80);
384 r = RegCreateKeyW(HKEY_CLASSES_ROOT, path, &key);
385 if (r != ERROR_SUCCESS)
388 RegSetValueExW(key, NULL, 0, REG_SZ, (const BYTE *)hlink, sizeof hlink);
389 RegSetValueExW(key, threading_model, 0, REG_SZ, (const BYTE *)apartment, sizeof apartment);
395 HRESULT WINAPI DllRegisterServer(void)
399 r = register_clsid(&CLSID_StdHlink);
401 r = register_clsid(&CLSID_StdHlinkBrowseContext);