Release 1.1.37.
[wine/gsoc-2012-control.git] / dlls / hlink / hlink_main.c
blobd07901aea4ab3656a480f6990b5324e9c3511ad2
1 /*
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"
23 #include "winreg.h"
24 #include "hlguids.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(hlink);
30 typedef HRESULT (CALLBACK *LPFNCREATEINSTANCE)(IUnknown*, REFIID, LPVOID*);
32 typedef struct
34 const IClassFactoryVtbl *lpVtbl;
35 LPFNCREATEINSTANCE lpfnCI;
36 } CFImpl;
38 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
40 TRACE("%p %d %p\n", hinstDLL, fdwReason, lpvReserved);
42 switch (fdwReason)
44 case DLL_PROCESS_ATTACH:
45 DisableThreadLibraryCalls(hinstDLL);
46 break;
47 case DLL_PROCESS_DETACH:
48 break;
50 return TRUE;
53 /***********************************************************************
54 * DllCanUnloadNow (HLINK.@)
56 HRESULT WINAPI DllCanUnloadNow( void )
58 return S_OK;
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)
68 IHlink *hl = NULL;
69 HRESULT r = S_OK;
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);
76 if (FAILED(r))
77 return r;
79 IHlink_SetMonikerReference(hl, HLINKSETF_LOCATION | HLINKSETF_TARGET, pimkTrgt, pwzLocation);
81 if (pwzFriendlyName)
82 IHlink_SetFriendlyName(hl, pwzFriendlyName);
83 if (pihlsite)
84 IHlink_SetHlinkSite(hl, pihlsite, dwSiteData);
86 *ppvObj = hl;
88 TRACE("Returning %i\n",r);
90 return 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)
100 IHlink *hl = NULL;
101 HRESULT r = S_OK;
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);
108 if (FAILED(r))
109 return r;
111 IHlink_SetStringReference(hl, HLINKSETF_TARGET | HLINKSETF_LOCATION,
112 pwzTarget, pwzLocation);
114 if (pwzFriendlyName)
115 IHlink_SetFriendlyName(hl, pwzFriendlyName);
117 if (pihlsite)
118 IHlink_SetHlinkSite(hl, pihlsite, dwSiteData);
120 TRACE("Returning %i\n",r);
121 *ppvObj = hl;
123 return r;
127 /***********************************************************************
128 * HlinkCreateBrowseContext (HLINK.@)
130 HRESULT WINAPI HlinkCreateBrowseContext( IUnknown* piunkOuter, REFIID riid, void** ppvObj)
132 HRESULT r = S_OK;
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);
140 return r;
143 /***********************************************************************
144 * HlinkNavigate (HLINK.@)
146 HRESULT WINAPI HlinkNavigate(IHlink *phl, IHlinkFrame *phlFrame,
147 DWORD grfHLNF, LPBC pbc, IBindStatusCallback *pbsc,
148 IHlinkBrowseContext *phlbc)
150 HRESULT r = S_OK;
152 TRACE("%p %p %i %p %p %p\n", phl, phlFrame, grfHLNF, pbc, pbsc, phlbc);
154 if (phlFrame)
155 r = IHlinkFrame_Navigate(phlFrame, grfHLNF, pbc, pbsc, phl);
156 else if (phl)
157 r = IHlink_Navigate(phl, grfHLNF, pbc, pbsc, phlbc);
159 return r;
162 /***********************************************************************
163 * HlinkOnNavigate (HLINK.@)
165 HRESULT WINAPI HlinkOnNavigate( IHlinkFrame *phlFrame,
166 IHlinkBrowseContext* phlbc, DWORD grfHLNF, IMoniker *pmkTarget,
167 LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName, ULONG* puHLID)
169 HRESULT r = S_OK;
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);
177 if (phlFrame)
178 r = IHlinkFrame_OnNavigate(phlFrame,grfHLNF,pmkTarget, pwzLocation,
179 pwzFriendlyName, 0);
181 return r;
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);
193 *ppvObj = NULL;
194 return E_NOTIMPL;
197 /***********************************************************************
198 * HlinkQueryCreateFromData (HLINK.@)
200 HRESULT WINAPI HlinkQueryCreateFromData(IDataObject* piDataObj)
202 FIXME("%p\n", piDataObj);
203 return E_NOTIMPL;
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)
214 HRESULT r;
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 );
223 if (SUCCEEDED(r))
224 r = HlinkNavigate(hlink, pihlframe, grfHLNF, pibc, pibsc, pihlbc);
226 return r;
229 /***********************************************************************
230 * HlinkIsShortcut (HLINK.@)
232 HRESULT WINAPI HlinkIsShortcut(LPCWSTR pwzFileName)
234 int len;
236 static const WCHAR url_ext[] = {'.','u','r','l',0};
238 TRACE("(%s)\n", debugstr_w(pwzFileName));
240 if(!pwzFileName)
241 return E_INVALIDARG;
243 len = strlenW(pwzFileName)-4;
244 if(len < 0)
245 return S_FALSE;
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;
256 LPCWSTR value_name;
257 WCHAR *buf;
258 HKEY hkey;
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;
273 switch(uReference) {
274 case HLSR_HOME:
275 value_name = start_pageW;
276 break;
277 case HLSR_SEARCHPAGE:
278 value_name = search_pageW;
279 break;
280 case HLSR_HISTORYFOLDER:
281 return E_NOTIMPL;
282 default:
283 return E_INVALIDARG;
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);
297 RegCloseKey(hkey);
298 if(res != ERROR_SUCCESS) {
299 WARN("Could not query value %s: %u\n", debugstr_w(value_name), res);
300 CoTaskMemFree(buf);
301 return HRESULT_FROM_WIN32(res);
304 *ppwzReference = buf;
305 return S_OK;
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);
314 return E_NOTIMPL;
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));
325 return E_NOTIMPL;
328 /***********************************************************************
329 * HlinkParseDisplayName (HLINK.@)
331 HRESULT WINAPI HlinkParseDisplayName(LPBC pibc, LPCWSTR pwzDisplayName, BOOL fNoForceAbs,
332 ULONG *pcchEaten, IMoniker **ppimk)
334 HRESULT hres;
336 TRACE("(%p %s %x %p %p)\n", pibc, debugstr_w(pwzDisplayName), fNoForceAbs, pcchEaten, ppimk);
338 if(fNoForceAbs)
339 FIXME("Unsupported fNoForceAbs\n");
341 hres = MkParseDisplayNameEx(pibc, pwzDisplayName, pcchEaten, ppimk);
342 if(SUCCEEDED(hres))
343 return hres;
345 hres = MkParseDisplayName(pibc, pwzDisplayName, pcchEaten, ppimk);
346 if(SUCCEEDED(hres))
347 return hres;
349 hres = CreateFileMoniker(pwzDisplayName, ppimk);
350 if(SUCCEEDED(hres))
351 *pcchEaten = strlenW(pwzDisplayName);
353 return hres;
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;
363 IBindCtx *bctx;
364 DWORD mksys = 0;
365 void *obj = NULL;
366 HRESULT hres;
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);
374 if(FAILED(hres))
375 return hres;
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));
387 CoTaskMemFree(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));
400 *ppvObj = NULL;
402 if (IsEqualIID(riid, &IID_IUnknown) ||
403 IsEqualIID(riid, &IID_IClassFactory))
405 *ppvObj = This;
406 return S_OK;
409 TRACE("-- E_NOINTERFACE\n");
410 return E_NOINTERFACE;
413 static ULONG WINAPI HLinkCF_fnAddRef (LPCLASSFACTORY iface)
415 return 2;
418 static ULONG WINAPI HLinkCF_fnRelease(LPCLASSFACTORY iface)
420 return 1;
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);
430 *ppvObject = NULL;
432 return This->lpfnCI(pUnkOuter, riid, ppvObject);
435 static HRESULT WINAPI HLinkCF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
437 FIXME("%p %d\n", iface, fLock);
438 return E_NOTIMPL;
441 static const IClassFactoryVtbl hlcfvt =
443 HLinkCF_fnQueryInterface,
444 HLinkCF_fnAddRef,
445 HLinkCF_fnRelease,
446 HLinkCF_fnCreateInstance,
447 HLinkCF_fnLockServer
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);
462 if (!ppv)
463 return E_INVALIDARG;
464 *ppv = NULL;
466 if (IsEqualIID(rclsid, &CLSID_StdHlink))
467 pcf = (IClassFactory*) &HLink_cf;
468 else if (IsEqualIID(rclsid, &CLSID_StdHlinkBrowseContext))
469 pcf = (IClassFactory*) &HLinkBrowseContext_cf;
470 else
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};
488 WCHAR path[80];
489 HKEY key = NULL;
490 LONG r;
492 lstrcpyW(path, clsid);
493 StringFromGUID2(guid, &path[6], 80);
494 lstrcatW(path, ips);
495 r = RegCreateKeyW(HKEY_CLASSES_ROOT, path, &key);
496 if (r != ERROR_SUCCESS)
497 return E_FAIL;
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);
501 RegCloseKey(key);
503 return S_OK;
506 /***********************************************************************
507 * DllRegisterServer (HLINK.@)
509 HRESULT WINAPI DllRegisterServer(void)
511 HRESULT r;
513 r = register_clsid(&CLSID_StdHlink);
514 if (SUCCEEDED(r))
515 r = register_clsid(&CLSID_StdHlinkBrowseContext);
517 return S_OK;