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"
38 WINE_DEFAULT_DEBUG_CHANNEL(hlink
);
40 extern HRESULT WINAPI
HLink_Constructor(IUnknown
*, REFIID
, LPVOID
*);
41 extern HRESULT WINAPI
HLinkBrowseContext_Constructor(IUnknown
*, REFIID
, LPVOID
*);
43 typedef HRESULT (CALLBACK
*LPFNCREATEINSTANCE
)(IUnknown
*, REFIID
, LPVOID
*);
47 const IClassFactoryVtbl
*lpVtbl
;
48 LPFNCREATEINSTANCE lpfnCI
;
51 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
53 TRACE("%p %d %p\n", hinstDLL
, fdwReason
, lpvReserved
);
57 case DLL_WINE_PREATTACH
:
58 return FALSE
; /* prefer native version */
59 case DLL_PROCESS_ATTACH
:
60 DisableThreadLibraryCalls(hinstDLL
);
62 case DLL_PROCESS_DETACH
:
68 HRESULT WINAPI
DllCanUnloadNow( void )
74 HRESULT WINAPI
HlinkCreateFromMoniker( IMoniker
*pimkTrgt
, LPCWSTR pwzLocation
,
75 LPCWSTR pwzFriendlyName
, IHlinkSite
* pihlsite
, DWORD dwSiteData
,
76 IUnknown
* piunkOuter
, REFIID riid
, void** ppvObj
)
81 TRACE("%p %s %s %p %i %p %s %p\n", pimkTrgt
, debugstr_w(pwzLocation
),
82 debugstr_w(pwzFriendlyName
), pihlsite
, dwSiteData
, piunkOuter
,
83 debugstr_guid(riid
), ppvObj
);
85 r
= CoCreateInstance(&CLSID_StdHlink
, piunkOuter
, CLSCTX_INPROC_SERVER
, riid
, (LPVOID
*)&hl
);
90 IHlink_SetStringReference(hl
, HLINKSETF_LOCATION
, NULL
, pwzLocation
);
92 IHlink_SetFriendlyName(hl
, pwzFriendlyName
);
94 IHlink_SetHlinkSite(hl
, pihlsite
, dwSiteData
);
96 IHlink_SetMonikerReference(hl
, 0, pimkTrgt
, pwzLocation
);
100 TRACE("Returning %i\n",r
);
105 HRESULT WINAPI
HlinkCreateFromString( LPCWSTR pwzTarget
, LPCWSTR pwzLocation
,
106 LPCWSTR pwzFriendlyName
, IHlinkSite
* pihlsite
, DWORD dwSiteData
,
107 IUnknown
* piunkOuter
, REFIID riid
, void** ppvObj
)
112 TRACE("%s %s %s %p %i %p %s %p\n", debugstr_w(pwzTarget
),
113 debugstr_w(pwzLocation
), debugstr_w(pwzFriendlyName
), pihlsite
,
114 dwSiteData
, piunkOuter
, debugstr_guid(riid
), ppvObj
);
116 r
= CoCreateInstance(&CLSID_StdHlink
, piunkOuter
, CLSCTX_INPROC_SERVER
, riid
, (LPVOID
*)&hl
);
121 IHlink_SetStringReference(hl
, HLINKSETF_LOCATION
, NULL
, pwzLocation
);
125 IMoniker
*pTgtMk
= NULL
;
126 IBindCtx
*pbc
= NULL
;
129 CreateBindCtx(0, &pbc
);
130 r
= MkParseDisplayName(pbc
, pwzTarget
, &eaten
, &pTgtMk
);
131 IBindCtx_Release(pbc
);
135 LPCWSTR p
= strchrW(pwzTarget
, ':');
136 if (p
&& (p
- pwzTarget
> 1))
137 r
= CreateURLMoniker(NULL
, pwzTarget
, &pTgtMk
);
139 r
= CreateFileMoniker(pwzTarget
,&pTgtMk
);
144 ERR("couldn't create moniker for %s, failed with error 0x%08x\n",
145 debugstr_w(pwzTarget
), r
);
149 IHlink_SetMonikerReference(hl
, 0, pTgtMk
, pwzLocation
);
150 IMoniker_Release(pTgtMk
);
152 IHlink_SetStringReference(hl
, HLINKSETF_TARGET
, pwzTarget
, NULL
);
156 IHlink_SetFriendlyName(hl
, pwzFriendlyName
);
158 IHlink_SetHlinkSite(hl
, pihlsite
, dwSiteData
);
160 TRACE("Returning %i\n",r
);
167 HRESULT WINAPI
HlinkCreateBrowseContext( IUnknown
* piunkOuter
, REFIID riid
, void** ppvObj
)
171 TRACE("%p %s %p\n", piunkOuter
, debugstr_guid(riid
), ppvObj
);
173 r
= CoCreateInstance(&CLSID_StdHlinkBrowseContext
, piunkOuter
, CLSCTX_INPROC_SERVER
, riid
, ppvObj
);
175 TRACE("returning %i\n",r
);
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 HRESULT WINAPI
HlinkOnNavigate( IHlinkFrame
*phlFrame
,
197 IHlinkBrowseContext
* phlbc
, DWORD grfHLNF
, IMoniker
*pmkTarget
,
198 LPCWSTR pwzLocation
, LPCWSTR pwzFriendlyName
, ULONG
* puHLID
)
202 TRACE("%p %p %i %p %s %s %p\n",phlFrame
, phlbc
, grfHLNF
, pmkTarget
,
203 debugstr_w(pwzLocation
), debugstr_w(pwzFriendlyName
), puHLID
);
205 r
= IHlinkBrowseContext_OnNavigateHlink(phlbc
, grfHLNF
, pmkTarget
,
206 pwzLocation
, pwzFriendlyName
, puHLID
);
209 r
= IHlinkFrame_OnNavigate(phlFrame
,grfHLNF
,pmkTarget
, pwzLocation
,
215 HRESULT WINAPI
HlinkCreateFromData(IDataObject
*piDataObj
,
216 IHlinkSite
*pihlsite
, DWORD dwSiteData
, IUnknown
*piunkOuter
,
217 REFIID riid
, void **ppvObj
)
219 FIXME("%p %p %d %p %p %p\n",
220 piDataObj
, pihlsite
, dwSiteData
, piunkOuter
, riid
, ppvObj
);
225 HRESULT WINAPI
HlinkQueryCreateFromData(IDataObject
* piDataObj
)
227 FIXME("%p\n", piDataObj
);
231 HRESULT WINAPI
HlinkCreateExtensionServices(LPCWSTR pwzAdditionalHeaders
,
232 HWND phwnd
, LPCWSTR pszUsername
, LPCWSTR pszPassword
,
233 IUnknown
*punkOuter
, REFIID riid
, void** ppvObj
)
235 FIXME("%s %p %s %s %p %s %p\n",debugstr_w(pwzAdditionalHeaders
),
236 phwnd
, debugstr_w(pszUsername
), debugstr_w(pszPassword
),
237 punkOuter
, debugstr_guid(riid
), ppvObj
);
241 HRESULT WINAPI
HlinkNavigateToStringReference( LPCWSTR pwzTarget
,
242 LPCWSTR pwzLocation
, IHlinkSite
*pihlsite
, DWORD dwSiteData
,
243 IHlinkFrame
*pihlframe
, DWORD grfHLNF
, LPBC pibc
,
244 IBindStatusCallback
*pibsc
, IHlinkBrowseContext
*pihlbc
)
247 IHlink
*hlink
= NULL
;
249 FIXME("%s %s %p %08x %p %08x %p %p %p\n",
250 debugstr_w(pwzTarget
), debugstr_w(pwzLocation
), pihlsite
,
251 dwSiteData
, pihlframe
, grfHLNF
, pibc
, pibsc
, pihlbc
);
253 r
= HlinkCreateFromString( pwzTarget
, pwzLocation
, NULL
, pihlsite
,
254 dwSiteData
, NULL
, &IID_IHlink
, (LPVOID
*) &hlink
);
256 r
= HlinkNavigate(hlink
, pihlframe
, grfHLNF
, pibc
, pibsc
, pihlbc
);
261 HRESULT WINAPI
HlinkIsShortcut(LPCWSTR pwzFileName
)
265 static const WCHAR url_ext
[] = {'.','u','r','l',0};
267 TRACE("(%s)\n", debugstr_w(pwzFileName
));
272 len
= strlenW(pwzFileName
)-4;
276 return strcmpiW(pwzFileName
+len
, url_ext
) ? S_FALSE
: S_OK
;
279 HRESULT WINAPI
HlinkTranslateURL(LPCWSTR pwzURL
, DWORD grfFlags
, LPWSTR
*ppwzTranslatedURL
)
281 FIXME("(%s %08x %p)\n", debugstr_w(pwzURL
), grfFlags
, ppwzTranslatedURL
);
285 static HRESULT WINAPI
HLinkCF_fnQueryInterface ( LPCLASSFACTORY iface
,
286 REFIID riid
, LPVOID
*ppvObj
)
288 CFImpl
*This
= (CFImpl
*)iface
;
290 TRACE("(%p)->(%s)\n",This
,debugstr_guid(riid
));
294 if (IsEqualIID(riid
, &IID_IUnknown
) ||
295 IsEqualIID(riid
, &IID_IClassFactory
))
301 TRACE("-- E_NOINTERFACE\n");
302 return E_NOINTERFACE
;
305 static ULONG WINAPI
HLinkCF_fnAddRef (LPCLASSFACTORY iface
)
310 static ULONG WINAPI
HLinkCF_fnRelease(LPCLASSFACTORY iface
)
315 static HRESULT WINAPI
HLinkCF_fnCreateInstance( LPCLASSFACTORY iface
,
316 LPUNKNOWN pUnkOuter
, REFIID riid
, LPVOID
*ppvObject
)
318 CFImpl
*This
= (CFImpl
*)iface
;
320 TRACE("%p->(%p,%s,%p)\n", This
, pUnkOuter
, debugstr_guid(riid
), ppvObject
);
324 return This
->lpfnCI(pUnkOuter
, riid
, ppvObject
);
327 static HRESULT WINAPI
HLinkCF_fnLockServer(LPCLASSFACTORY iface
, BOOL fLock
)
329 FIXME("%p %d\n", iface
, fLock
);
333 static const IClassFactoryVtbl hlcfvt
=
335 HLinkCF_fnQueryInterface
,
338 HLinkCF_fnCreateInstance
,
342 static CFImpl HLink_cf
= { &hlcfvt
, &HLink_Constructor
};
343 static CFImpl HLinkBrowseContext_cf
= { &hlcfvt
, &HLinkBrowseContext_Constructor
};
345 /***********************************************************************
346 * DllGetClassObject (HLINK.@)
348 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID iid
, LPVOID
*ppv
)
350 IClassFactory
*pcf
= NULL
;
352 TRACE("%s %s %p\n", debugstr_guid(rclsid
), debugstr_guid(iid
), ppv
);
358 if (IsEqualIID(rclsid
, &CLSID_StdHlink
))
359 pcf
= (IClassFactory
*) &HLink_cf
;
360 else if (IsEqualIID(rclsid
, &CLSID_StdHlinkBrowseContext
))
361 pcf
= (IClassFactory
*) &HLinkBrowseContext_cf
;
363 return CLASS_E_CLASSNOTAVAILABLE
;
365 return IClassFactory_QueryInterface(pcf
, iid
, ppv
);
368 static HRESULT
register_clsid(LPCGUID guid
)
370 static const WCHAR clsid
[] =
371 {'C','L','S','I','D','\\',0};
372 static const WCHAR ips
[] =
373 {'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
374 static const WCHAR hlink
[] =
375 {'h','l','i','n','k','.','d','l','l',0};
376 static const WCHAR threading_model
[] =
377 {'T','h','r','e','a','d','i','n','g','M','o','d','e','l',0};
378 static const WCHAR apartment
[] =
379 {'A','p','a','r','t','m','e','n','t',0};
384 lstrcpyW(path
, clsid
);
385 StringFromGUID2(guid
, &path
[6], 80);
387 r
= RegCreateKeyW(HKEY_CLASSES_ROOT
, path
, &key
);
388 if (r
!= ERROR_SUCCESS
)
391 RegSetValueExW(key
, NULL
, 0, REG_SZ
, (const BYTE
*)hlink
, sizeof hlink
);
392 RegSetValueExW(key
, threading_model
, 0, REG_SZ
, (const BYTE
*)apartment
, sizeof apartment
);
398 HRESULT WINAPI
DllRegisterServer(void)
402 r
= register_clsid(&CLSID_StdHlink
);
404 r
= register_clsid(&CLSID_StdHlinkBrowseContext
);