2 * Copyright 2008 Damjan Jovanovic
4 * ShellLink's barely documented cousin that handles URLs.
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
23 * Implement the IShellLinkA/W interfaces
24 * Handle the SetURL flags
25 * Implement any other interfaces? Does any software actually use them?
27 * The installer for the Zuma Deluxe Popcap game is good for testing.
30 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw
);
40 IUniformResourceLocatorA uniformResourceLocatorA
;
41 IUniformResourceLocatorW uniformResourceLocatorW
;
42 IPersistFile persistFile
;
51 /* utility functions */
53 static inline InternetShortcut
* impl_from_IUniformResourceLocatorA(IUniformResourceLocatorA
*iface
)
55 return (InternetShortcut
*)((char*)iface
- FIELD_OFFSET(InternetShortcut
, uniformResourceLocatorA
));
58 static inline InternetShortcut
* impl_from_IUniformResourceLocatorW(IUniformResourceLocatorW
*iface
)
60 return (InternetShortcut
*)((char*)iface
- FIELD_OFFSET(InternetShortcut
, uniformResourceLocatorW
));
63 static inline InternetShortcut
* impl_from_IPersistFile(IPersistFile
*iface
)
65 return (InternetShortcut
*)((char*)iface
- FIELD_OFFSET(InternetShortcut
, persistFile
));
68 static BOOL
StartLinkProcessor(LPCOLESTR szLink
)
70 static const WCHAR szFormat
[] = {
71 'w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',
72 ' ','-','w',' ','-','u',' ','"','%','s','"',0 };
76 PROCESS_INFORMATION pi
;
79 len
= sizeof(szFormat
) + lstrlenW( szLink
) * sizeof(WCHAR
);
80 buffer
= heap_alloc( len
);
84 wsprintfW( buffer
, szFormat
, szLink
);
86 TRACE("starting %s\n",debugstr_w(buffer
));
88 memset(&si
, 0, sizeof(si
));
91 ret
= CreateProcessW( NULL
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
);
93 HeapFree( GetProcessHeap(), 0, buffer
);
97 CloseHandle( pi
.hProcess
);
98 CloseHandle( pi
.hThread
);
104 /* interface functions */
106 static HRESULT
Unknown_QueryInterface(InternetShortcut
*This
, REFIID riid
, PVOID
*ppvObject
)
108 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppvObject
);
110 if (IsEqualGUID(&IID_IUnknown
, riid
))
111 *ppvObject
= &This
->uniformResourceLocatorA
;
112 else if (IsEqualGUID(&IID_IUniformResourceLocatorA
, riid
))
113 *ppvObject
= &This
->uniformResourceLocatorA
;
114 else if (IsEqualGUID(&IID_IUniformResourceLocatorW
, riid
))
115 *ppvObject
= &This
->uniformResourceLocatorW
;
116 else if (IsEqualGUID(&IID_IPersistFile
, riid
))
117 *ppvObject
= &This
->persistFile
;
118 else if (IsEqualGUID(&IID_IShellLinkA
, riid
))
120 FIXME("The IShellLinkA interface is not yet supported by InternetShortcut\n");
121 return E_NOINTERFACE
;
123 else if (IsEqualGUID(&IID_IShellLinkW
, riid
))
125 FIXME("The IShellLinkW interface is not yet supported by InternetShortcut\n");
126 return E_NOINTERFACE
;
130 FIXME("Interface with GUID %s not yet implemented by InternetShortcut\n", debugstr_guid(riid
));
131 return E_NOINTERFACE
;
133 IUnknown_AddRef((IUnknown
*)*ppvObject
);
137 static ULONG
Unknown_AddRef(InternetShortcut
*This
)
139 TRACE("(%p)\n", This
);
140 return InterlockedIncrement(&This
->refCount
);
143 static ULONG
Unknown_Release(InternetShortcut
*This
)
146 TRACE("(%p)\n", This
);
147 count
= InterlockedDecrement(&This
->refCount
);
150 CoTaskMemFree(This
->url
);
151 CoTaskMemFree(This
->currentFile
);
153 SHDOCVW_UnlockModule();
158 static HRESULT WINAPI
UniformResourceLocatorW_QueryInterface(IUniformResourceLocatorW
*url
, REFIID riid
, PVOID
*ppvObject
)
160 InternetShortcut
*This
= impl_from_IUniformResourceLocatorW(url
);
161 TRACE("(%p, %s, %p)\n", url
, debugstr_guid(riid
), ppvObject
);
162 return Unknown_QueryInterface(This
, riid
, ppvObject
);
165 static ULONG WINAPI
UniformResourceLocatorW_AddRef(IUniformResourceLocatorW
*url
)
167 InternetShortcut
*This
= impl_from_IUniformResourceLocatorW(url
);
168 TRACE("(%p)\n", url
);
169 return Unknown_AddRef(This
);
172 static ULONG WINAPI
UniformResourceLocatorW_Release(IUniformResourceLocatorW
*url
)
174 InternetShortcut
*This
= impl_from_IUniformResourceLocatorW(url
);
175 TRACE("(%p)\n", url
);
176 return Unknown_Release(This
);
179 static HRESULT WINAPI
UniformResourceLocatorW_SetUrl(IUniformResourceLocatorW
*url
, LPCWSTR pcszURL
, DWORD dwInFlags
)
181 WCHAR
*newURL
= NULL
;
182 InternetShortcut
*This
= impl_from_IUniformResourceLocatorW(url
);
183 TRACE("(%p, %s, 0x%x)\n", url
, debugstr_w(pcszURL
), dwInFlags
);
185 FIXME("ignoring unsupported flags 0x%x\n", dwInFlags
);
188 newURL
= co_strdupW(pcszURL
);
190 return E_OUTOFMEMORY
;
192 CoTaskMemFree(This
->url
);
194 This
->isDirty
= TRUE
;
198 static HRESULT WINAPI
UniformResourceLocatorW_GetUrl(IUniformResourceLocatorW
*url
, LPWSTR
*ppszURL
)
201 InternetShortcut
*This
= impl_from_IUniformResourceLocatorW(url
);
202 TRACE("(%p, %p)\n", url
, ppszURL
);
203 if (This
->url
== NULL
)
207 *ppszURL
= co_strdupW(This
->url
);
208 if (*ppszURL
== NULL
)
214 static HRESULT WINAPI
UniformResourceLocatorW_InvokeCommand(IUniformResourceLocatorW
*url
, PURLINVOKECOMMANDINFOW pCommandInfo
)
216 FIXME("(%p, %p): stub\n", url
, pCommandInfo
);
220 static HRESULT WINAPI
UniformResourceLocatorA_QueryInterface(IUniformResourceLocatorA
*url
, REFIID riid
, PVOID
*ppvObject
)
222 InternetShortcut
*This
= impl_from_IUniformResourceLocatorA(url
);
223 TRACE("(%p, %s, %p)\n", url
, debugstr_guid(riid
), ppvObject
);
224 return Unknown_QueryInterface(This
, riid
, ppvObject
);
227 static ULONG WINAPI
UniformResourceLocatorA_AddRef(IUniformResourceLocatorA
*url
)
229 InternetShortcut
*This
= impl_from_IUniformResourceLocatorA(url
);
230 TRACE("(%p)\n", url
);
231 return Unknown_AddRef(This
);
234 static ULONG WINAPI
UniformResourceLocatorA_Release(IUniformResourceLocatorA
*url
)
236 InternetShortcut
*This
= impl_from_IUniformResourceLocatorA(url
);
237 TRACE("(%p)\n", url
);
238 return Unknown_Release(This
);
241 static HRESULT WINAPI
UniformResourceLocatorA_SetUrl(IUniformResourceLocatorA
*url
, LPCSTR pcszURL
, DWORD dwInFlags
)
243 WCHAR
*newURL
= NULL
;
244 InternetShortcut
*This
= impl_from_IUniformResourceLocatorA(url
);
245 TRACE("(%p, %s, 0x%x)\n", url
, debugstr_a(pcszURL
), dwInFlags
);
247 FIXME("ignoring unsupported flags 0x%x\n", dwInFlags
);
250 newURL
= co_strdupAtoW(pcszURL
);
252 return E_OUTOFMEMORY
;
254 CoTaskMemFree(This
->url
);
256 This
->isDirty
= TRUE
;
260 static HRESULT WINAPI
UniformResourceLocatorA_GetUrl(IUniformResourceLocatorA
*url
, LPSTR
*ppszURL
)
263 InternetShortcut
*This
= impl_from_IUniformResourceLocatorA(url
);
264 TRACE("(%p, %p)\n", url
, ppszURL
);
265 if (This
->url
== NULL
)
269 *ppszURL
= co_strdupWtoA(This
->url
);
270 if (*ppszURL
== NULL
)
276 static HRESULT WINAPI
UniformResourceLocatorA_InvokeCommand(IUniformResourceLocatorA
*url
, PURLINVOKECOMMANDINFOA pCommandInfo
)
278 FIXME("(%p, %p): stub\n", url
, pCommandInfo
);
282 static HRESULT WINAPI
PersistFile_QueryInterface(IPersistFile
*pFile
, REFIID riid
, PVOID
*ppvObject
)
284 InternetShortcut
*This
= impl_from_IPersistFile(pFile
);
285 TRACE("(%p, %s, %p)\n", pFile
, debugstr_guid(riid
), ppvObject
);
286 return Unknown_QueryInterface(This
, riid
, ppvObject
);
289 static ULONG WINAPI
PersistFile_AddRef(IPersistFile
*pFile
)
291 InternetShortcut
*This
= impl_from_IPersistFile(pFile
);
292 TRACE("(%p)\n", pFile
);
293 return Unknown_AddRef(This
);
296 static ULONG WINAPI
PersistFile_Release(IPersistFile
*pFile
)
298 InternetShortcut
*This
= impl_from_IPersistFile(pFile
);
299 TRACE("(%p)\n", pFile
);
300 return Unknown_Release(This
);
303 static HRESULT WINAPI
PersistFile_GetClassID(IPersistFile
*pFile
, CLSID
*pClassID
)
305 TRACE("(%p, %p)\n", pFile
, pClassID
);
306 *pClassID
= CLSID_InternetShortcut
;
310 static HRESULT WINAPI
PersistFile_IsDirty(IPersistFile
*pFile
)
312 InternetShortcut
*This
= impl_from_IPersistFile(pFile
);
313 TRACE("(%p)\n", pFile
);
314 return This
->isDirty
? S_OK
: S_FALSE
;
317 static HRESULT WINAPI
PersistFile_Load(IPersistFile
*pFile
, LPCOLESTR pszFileName
, DWORD dwMode
)
319 WCHAR str_header
[] = {'I','n','t','e','r','n','e','t','S','h','o','r','t','c','u','t',0};
320 WCHAR str_URL
[] = {'U','R','L',0};
321 WCHAR
*filename
= NULL
;
323 InternetShortcut
*This
= impl_from_IPersistFile(pFile
);
324 TRACE("(%p, %s, 0x%x)\n", pFile
, debugstr_w(pszFileName
), dwMode
);
326 FIXME("ignoring unimplemented mode 0x%x\n", dwMode
);
327 filename
= co_strdupW(pszFileName
);
328 if (filename
!= NULL
)
332 WCHAR
*url
= CoTaskMemAlloc(len
*sizeof(WCHAR
));
335 r
= GetPrivateProfileStringW(str_header
, str_URL
, NULL
, url
, len
, pszFileName
);
340 url
= CoTaskMemAlloc(len
);
343 r
= GetPrivateProfileStringW(str_header
, str_URL
, NULL
, url
, len
, pszFileName
);
347 else if (url
!= NULL
)
349 CoTaskMemFree(This
->currentFile
);
350 This
->currentFile
= filename
;
351 CoTaskMemFree(This
->url
);
353 This
->isDirty
= FALSE
;
362 CoTaskMemFree(filename
);
369 static HRESULT WINAPI
PersistFile_Save(IPersistFile
*pFile
, LPCOLESTR pszFileName
, BOOL fRemember
)
374 InternetShortcut
*This
= impl_from_IPersistFile(pFile
);
376 TRACE("(%p, %s, %d)\n", pFile
, debugstr_w(pszFileName
), fRemember
);
378 if (pszFileName
!= NULL
&& fRemember
)
380 LPOLESTR oldFile
= This
->currentFile
;
381 This
->currentFile
= co_strdupW(pszFileName
);
382 if (This
->currentFile
== NULL
)
384 This
->currentFile
= oldFile
;
385 return E_OUTOFMEMORY
;
387 CoTaskMemFree(oldFile
);
389 if (This
->url
== NULL
)
392 /* Windows seems to always write:
393 * ASCII "[InternetShortcut]" headers
394 * ASCII names in "name=value" pairs
395 * An ASCII (probably UTF8?) value in "URL=..."
397 len
= WideCharToMultiByte(CP_UTF8
, 0, This
->url
, -1, NULL
, 0, 0, 0);
398 url
= heap_alloc(len
);
402 WideCharToMultiByte(CP_UTF8
, 0, This
->url
, -1, url
, len
, 0, 0);
403 file
= CreateFileW(pszFileName
, GENERIC_WRITE
, FILE_SHARE_READ
, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
404 if (file
!= INVALID_HANDLE_VALUE
)
407 char str_header
[] = "[InternetShortcut]";
408 char str_URL
[] = "URL=";
409 char str_eol
[] = "\r\n";
411 WriteFile(file
, str_header
, lstrlenA(str_header
), &bytesWritten
, NULL
);
412 WriteFile(file
, str_eol
, lstrlenA(str_eol
), &bytesWritten
, NULL
);
413 WriteFile(file
, str_URL
, lstrlenA(str_URL
), &bytesWritten
, NULL
);
414 WriteFile(file
, url
, lstrlenA(url
), &bytesWritten
, NULL
);
415 WriteFile(file
, str_eol
, lstrlenA(str_eol
), &bytesWritten
, NULL
);
417 if (pszFileName
== NULL
|| fRemember
)
418 This
->isDirty
= FALSE
;
419 StartLinkProcessor(pszFileName
);
431 static HRESULT WINAPI
PersistFile_SaveCompleted(IPersistFile
*pFile
, LPCOLESTR pszFileName
)
433 FIXME("(%p, %p): stub\n", pFile
, pszFileName
);
437 static HRESULT WINAPI
PersistFile_GetCurFile(IPersistFile
*pFile
, LPOLESTR
*ppszFileName
)
440 InternetShortcut
*This
= impl_from_IPersistFile(pFile
);
441 TRACE("(%p, %p)\n", pFile
, ppszFileName
);
442 if (This
->currentFile
== NULL
)
443 *ppszFileName
= NULL
;
446 *ppszFileName
= co_strdupW(This
->currentFile
);
447 if (*ppszFileName
== NULL
)
455 static const IUniformResourceLocatorWVtbl uniformResourceLocatorWVtbl
= {
456 UniformResourceLocatorW_QueryInterface
,
457 UniformResourceLocatorW_AddRef
,
458 UniformResourceLocatorW_Release
,
459 UniformResourceLocatorW_SetUrl
,
460 UniformResourceLocatorW_GetUrl
,
461 UniformResourceLocatorW_InvokeCommand
464 static const IUniformResourceLocatorAVtbl uniformResourceLocatorAVtbl
= {
465 UniformResourceLocatorA_QueryInterface
,
466 UniformResourceLocatorA_AddRef
,
467 UniformResourceLocatorA_Release
,
468 UniformResourceLocatorA_SetUrl
,
469 UniformResourceLocatorA_GetUrl
,
470 UniformResourceLocatorA_InvokeCommand
473 static const IPersistFileVtbl persistFileVtbl
= {
474 PersistFile_QueryInterface
,
477 PersistFile_GetClassID
,
481 PersistFile_SaveCompleted
,
482 PersistFile_GetCurFile
485 HRESULT
InternetShortcut_Create(IUnknown
*pOuter
, REFIID riid
, void **ppv
)
487 InternetShortcut
*This
;
490 TRACE("(%p, %s, %p)\n", pOuter
, debugstr_guid(riid
), ppv
);
495 return CLASS_E_NOAGGREGATION
;
497 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(InternetShortcut
));
500 This
->uniformResourceLocatorA
.lpVtbl
= &uniformResourceLocatorAVtbl
;
501 This
->uniformResourceLocatorW
.lpVtbl
= &uniformResourceLocatorWVtbl
;
502 This
->persistFile
.lpVtbl
= &persistFileVtbl
;
504 hr
= Unknown_QueryInterface(This
, riid
, ppv
);
506 SHDOCVW_LockModule();
512 return E_OUTOFMEMORY
;