localspl: Remove a bunch of casts.
[wine.git] / dlls / ieframe / intshcut.c
blob17a13ec74ab51a8e629254fb3fa3535cf8942943
1 /*
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
22 * TODO:
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 <stdio.h>
32 #include "ieframe.h"
34 #include "shlobj.h"
35 #include "shobjidl.h"
36 #include "intshcut.h"
37 #include "shellapi.h"
38 #include "winreg.h"
39 #include "shlwapi.h"
40 #include "shlguid.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(ieframe);
46 typedef struct
48 IUniformResourceLocatorA IUniformResourceLocatorA_iface;
49 IUniformResourceLocatorW IUniformResourceLocatorW_iface;
50 IPersistFile IPersistFile_iface;
51 IPropertySetStorage IPropertySetStorage_iface;
53 LONG refCount;
55 IPropertySetStorage *property_set_storage;
56 WCHAR *url;
57 BOOLEAN isDirty;
58 LPOLESTR currentFile;
59 } InternetShortcut;
61 /* utility functions */
63 static inline InternetShortcut* impl_from_IUniformResourceLocatorA(IUniformResourceLocatorA *iface)
65 return CONTAINING_RECORD(iface, InternetShortcut, IUniformResourceLocatorA_iface);
68 static inline InternetShortcut* impl_from_IUniformResourceLocatorW(IUniformResourceLocatorW *iface)
70 return CONTAINING_RECORD(iface, InternetShortcut, IUniformResourceLocatorW_iface);
73 static inline InternetShortcut* impl_from_IPersistFile(IPersistFile *iface)
75 return CONTAINING_RECORD(iface, InternetShortcut, IPersistFile_iface);
78 static inline InternetShortcut* impl_from_IPropertySetStorage(IPropertySetStorage *iface)
80 return CONTAINING_RECORD(iface, InternetShortcut, IPropertySetStorage_iface);
83 static BOOL run_winemenubuilder( const WCHAR *args )
85 static const WCHAR menubuilder[] = {'\\','w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',0};
86 LONG len;
87 LPWSTR buffer;
88 STARTUPINFOW si;
89 PROCESS_INFORMATION pi;
90 BOOL ret;
91 WCHAR app[MAX_PATH];
92 void *redir;
94 GetSystemDirectoryW( app, MAX_PATH - sizeof(menubuilder)/sizeof(WCHAR) );
95 strcatW( app, menubuilder );
97 len = (strlenW( app ) + strlenW( args ) + 1) * sizeof(WCHAR);
98 buffer = heap_alloc( len );
99 if( !buffer )
100 return FALSE;
102 strcpyW( buffer, app );
103 strcatW( buffer, args );
105 TRACE("starting %s\n",debugstr_w(buffer));
107 memset(&si, 0, sizeof(si));
108 si.cb = sizeof(si);
110 Wow64DisableWow64FsRedirection( &redir );
111 ret = CreateProcessW( app, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi );
112 Wow64RevertWow64FsRedirection( redir );
114 heap_free( buffer );
116 if (ret)
118 CloseHandle( pi.hProcess );
119 CloseHandle( pi.hThread );
122 return ret;
125 static BOOL StartLinkProcessor( LPCOLESTR szLink )
127 static const WCHAR szFormat[] = { ' ','-','w',' ','-','u',' ','"','%','s','"',0 };
128 LONG len;
129 LPWSTR buffer;
130 BOOL ret;
132 len = sizeof(szFormat) + lstrlenW( szLink ) * sizeof(WCHAR);
133 buffer = heap_alloc( len );
134 if( !buffer )
135 return FALSE;
137 sprintfW( buffer, szFormat, szLink );
138 ret = run_winemenubuilder( buffer );
139 heap_free( buffer );
140 return ret;
143 /* interface functions */
145 static HRESULT Unknown_QueryInterface(InternetShortcut *This, REFIID riid, PVOID *ppvObject)
147 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppvObject);
148 *ppvObject = NULL;
149 if (IsEqualGUID(&IID_IUnknown, riid))
150 *ppvObject = &This->IUniformResourceLocatorA_iface;
151 else if (IsEqualGUID(&IID_IUniformResourceLocatorA, riid))
152 *ppvObject = &This->IUniformResourceLocatorA_iface;
153 else if (IsEqualGUID(&IID_IUniformResourceLocatorW, riid))
154 *ppvObject = &This->IUniformResourceLocatorW_iface;
155 else if (IsEqualGUID(&IID_IPersistFile, riid))
156 *ppvObject = &This->IPersistFile_iface;
157 else if (IsEqualGUID(&IID_IPropertySetStorage, riid))
158 *ppvObject = &This->IPropertySetStorage_iface;
159 else if (IsEqualGUID(&IID_IShellLinkA, riid))
161 FIXME("The IShellLinkA interface is not yet supported by InternetShortcut\n");
162 return E_NOINTERFACE;
164 else if (IsEqualGUID(&IID_IShellLinkW, riid))
166 FIXME("The IShellLinkW interface is not yet supported by InternetShortcut\n");
167 return E_NOINTERFACE;
169 else
171 FIXME("Interface with GUID %s not yet implemented by InternetShortcut\n", debugstr_guid(riid));
172 return E_NOINTERFACE;
174 IUnknown_AddRef((IUnknown*)*ppvObject);
175 return S_OK;
178 static ULONG Unknown_AddRef(InternetShortcut *This)
180 TRACE("(%p)\n", This);
181 return InterlockedIncrement(&This->refCount);
184 static ULONG Unknown_Release(InternetShortcut *This)
186 ULONG count;
187 TRACE("(%p)\n", This);
188 count = InterlockedDecrement(&This->refCount);
189 if (count == 0)
191 CoTaskMemFree(This->url);
192 CoTaskMemFree(This->currentFile);
193 IPropertySetStorage_Release(This->property_set_storage);
194 heap_free(This);
195 unlock_module();
197 return count;
200 static HRESULT WINAPI UniformResourceLocatorW_QueryInterface(IUniformResourceLocatorW *url, REFIID riid, PVOID *ppvObject)
202 InternetShortcut *This = impl_from_IUniformResourceLocatorW(url);
203 TRACE("(%p, %s, %p)\n", url, debugstr_guid(riid), ppvObject);
204 return Unknown_QueryInterface(This, riid, ppvObject);
207 static ULONG WINAPI UniformResourceLocatorW_AddRef(IUniformResourceLocatorW *url)
209 InternetShortcut *This = impl_from_IUniformResourceLocatorW(url);
210 TRACE("(%p)\n", url);
211 return Unknown_AddRef(This);
214 static ULONG WINAPI UniformResourceLocatorW_Release(IUniformResourceLocatorW *url)
216 InternetShortcut *This = impl_from_IUniformResourceLocatorW(url);
217 TRACE("(%p)\n", url);
218 return Unknown_Release(This);
221 static HRESULT WINAPI UniformResourceLocatorW_SetUrl(IUniformResourceLocatorW *url, LPCWSTR pcszURL, DWORD dwInFlags)
223 WCHAR *newURL = NULL;
224 InternetShortcut *This = impl_from_IUniformResourceLocatorW(url);
225 TRACE("(%p, %s, 0x%x)\n", url, debugstr_w(pcszURL), dwInFlags);
226 if (dwInFlags != 0)
227 FIXME("ignoring unsupported flags 0x%x\n", dwInFlags);
228 if (pcszURL != NULL)
230 newURL = co_strdupW(pcszURL);
231 if (newURL == NULL)
232 return E_OUTOFMEMORY;
234 CoTaskMemFree(This->url);
235 This->url = newURL;
236 This->isDirty = TRUE;
237 return S_OK;
240 static HRESULT WINAPI UniformResourceLocatorW_GetUrl(IUniformResourceLocatorW *url, LPWSTR *ppszURL)
242 InternetShortcut *This = impl_from_IUniformResourceLocatorW(url);
244 TRACE("(%p, %p)\n", url, ppszURL);
246 if (!This->url) {
247 *ppszURL = NULL;
248 return S_FALSE;
251 *ppszURL = co_strdupW(This->url);
252 if (!*ppszURL)
253 return E_OUTOFMEMORY;
255 return S_OK;
258 static HRESULT WINAPI UniformResourceLocatorW_InvokeCommand(IUniformResourceLocatorW *url, PURLINVOKECOMMANDINFOW pCommandInfo)
260 InternetShortcut *This = impl_from_IUniformResourceLocatorW(url);
261 WCHAR app[64];
262 HKEY hkey;
263 static const WCHAR wszURLProtocol[] = {'U','R','L',' ','P','r','o','t','o','c','o','l',0};
264 SHELLEXECUTEINFOW sei;
265 DWORD res, type;
266 HRESULT hres;
268 TRACE("%p %p\n", This, pCommandInfo );
270 if (pCommandInfo->dwcbSize < sizeof (URLINVOKECOMMANDINFOW))
271 return E_INVALIDARG;
273 if (pCommandInfo->dwFlags != IURL_INVOKECOMMAND_FL_USE_DEFAULT_VERB)
275 FIXME("(%p, %p): non-default verbs not implemented\n", url, pCommandInfo);
276 return E_NOTIMPL;
279 hres = CoInternetParseUrl(This->url, PARSE_SCHEMA, 0, app, sizeof(app)/sizeof(WCHAR), NULL, 0);
280 if(FAILED(hres))
281 return E_FAIL;
283 res = RegOpenKeyW(HKEY_CLASSES_ROOT, app, &hkey);
284 if(res != ERROR_SUCCESS)
285 return E_FAIL;
287 res = RegQueryValueExW(hkey, wszURLProtocol, NULL, &type, NULL, NULL);
288 RegCloseKey(hkey);
289 if(res != ERROR_SUCCESS || type != REG_SZ)
290 return E_FAIL;
292 memset(&sei, 0, sizeof(sei));
293 sei.cbSize = sizeof(sei);
294 sei.lpFile = This->url;
295 sei.nShow = SW_SHOW;
297 if( ShellExecuteExW(&sei) )
298 return S_OK;
299 else
300 return E_FAIL;
303 static HRESULT WINAPI UniformResourceLocatorA_QueryInterface(IUniformResourceLocatorA *url, REFIID riid, PVOID *ppvObject)
305 InternetShortcut *This = impl_from_IUniformResourceLocatorA(url);
306 TRACE("(%p, %s, %p)\n", url, debugstr_guid(riid), ppvObject);
307 return Unknown_QueryInterface(This, riid, ppvObject);
310 static ULONG WINAPI UniformResourceLocatorA_AddRef(IUniformResourceLocatorA *url)
312 InternetShortcut *This = impl_from_IUniformResourceLocatorA(url);
313 TRACE("(%p)\n", url);
314 return Unknown_AddRef(This);
317 static ULONG WINAPI UniformResourceLocatorA_Release(IUniformResourceLocatorA *url)
319 InternetShortcut *This = impl_from_IUniformResourceLocatorA(url);
320 TRACE("(%p)\n", url);
321 return Unknown_Release(This);
324 static HRESULT WINAPI UniformResourceLocatorA_SetUrl(IUniformResourceLocatorA *url, LPCSTR pcszURL, DWORD dwInFlags)
326 WCHAR *newURL = NULL;
327 InternetShortcut *This = impl_from_IUniformResourceLocatorA(url);
328 TRACE("(%p, %s, 0x%x)\n", url, debugstr_a(pcszURL), dwInFlags);
329 if (dwInFlags != 0)
330 FIXME("ignoring unsupported flags 0x%x\n", dwInFlags);
331 if (pcszURL != NULL)
333 newURL = co_strdupAtoW(pcszURL);
334 if (newURL == NULL)
335 return E_OUTOFMEMORY;
337 CoTaskMemFree(This->url);
338 This->url = newURL;
339 This->isDirty = TRUE;
340 return S_OK;
343 static HRESULT WINAPI UniformResourceLocatorA_GetUrl(IUniformResourceLocatorA *url, LPSTR *ppszURL)
345 InternetShortcut *This = impl_from_IUniformResourceLocatorA(url);
347 TRACE("(%p, %p)\n", url, ppszURL);
349 if (!This->url) {
350 *ppszURL = NULL;
351 return S_FALSE;
355 *ppszURL = co_strdupWtoA(This->url);
356 if (!*ppszURL)
357 return E_OUTOFMEMORY;
359 return S_OK;
362 static HRESULT WINAPI UniformResourceLocatorA_InvokeCommand(IUniformResourceLocatorA *url, PURLINVOKECOMMANDINFOA pCommandInfo)
364 URLINVOKECOMMANDINFOW wideCommandInfo;
365 int len;
366 WCHAR *wideVerb;
367 HRESULT res;
368 InternetShortcut *This = impl_from_IUniformResourceLocatorA(url);
370 wideCommandInfo.dwcbSize = sizeof wideCommandInfo;
371 wideCommandInfo.dwFlags = pCommandInfo->dwFlags;
372 wideCommandInfo.hwndParent = pCommandInfo->hwndParent;
374 len = MultiByteToWideChar(CP_ACP, 0, pCommandInfo->pcszVerb, -1, NULL, 0);
375 wideVerb = heap_alloc(len * sizeof(WCHAR));
376 MultiByteToWideChar(CP_ACP, 0, pCommandInfo->pcszVerb, -1, wideVerb, len);
378 wideCommandInfo.pcszVerb = wideVerb;
380 res = UniformResourceLocatorW_InvokeCommand(&This->IUniformResourceLocatorW_iface, &wideCommandInfo);
381 heap_free(wideVerb);
383 return res;
386 static HRESULT WINAPI PersistFile_QueryInterface(IPersistFile *pFile, REFIID riid, PVOID *ppvObject)
388 InternetShortcut *This = impl_from_IPersistFile(pFile);
389 TRACE("(%p, %s, %p)\n", pFile, debugstr_guid(riid), ppvObject);
390 return Unknown_QueryInterface(This, riid, ppvObject);
393 static ULONG WINAPI PersistFile_AddRef(IPersistFile *pFile)
395 InternetShortcut *This = impl_from_IPersistFile(pFile);
396 TRACE("(%p)\n", pFile);
397 return Unknown_AddRef(This);
400 static ULONG WINAPI PersistFile_Release(IPersistFile *pFile)
402 InternetShortcut *This = impl_from_IPersistFile(pFile);
403 TRACE("(%p)\n", pFile);
404 return Unknown_Release(This);
407 static HRESULT WINAPI PersistFile_GetClassID(IPersistFile *pFile, CLSID *pClassID)
409 TRACE("(%p, %p)\n", pFile, pClassID);
410 *pClassID = CLSID_InternetShortcut;
411 return S_OK;
414 static HRESULT WINAPI PersistFile_IsDirty(IPersistFile *pFile)
416 InternetShortcut *This = impl_from_IPersistFile(pFile);
417 TRACE("(%p)\n", pFile);
418 return This->isDirty ? S_OK : S_FALSE;
421 /* A helper function: Allocate and fill rString. Return number of bytes read. */
422 static DWORD get_profile_string(LPCWSTR lpAppName, LPCWSTR lpKeyName,
423 LPCWSTR lpFileName, WCHAR **rString )
425 DWORD r = 0;
426 DWORD len = 128;
427 WCHAR *buffer;
429 buffer = CoTaskMemAlloc(len * sizeof(*buffer));
430 if (buffer != NULL)
432 r = GetPrivateProfileStringW(lpAppName, lpKeyName, NULL, buffer, len, lpFileName);
433 while (r == len-1)
435 WCHAR *realloc_buf;
437 len *= 2;
438 realloc_buf = CoTaskMemRealloc(buffer, len * sizeof(*buffer));
439 if (realloc_buf == NULL)
441 CoTaskMemFree(buffer);
442 *rString = NULL;
443 return 0;
445 buffer = realloc_buf;
447 r = GetPrivateProfileStringW(lpAppName, lpKeyName, NULL, buffer, len, lpFileName);
451 *rString = buffer;
452 return r;
455 static HRESULT WINAPI PersistFile_Load(IPersistFile *pFile, LPCOLESTR pszFileName, DWORD dwMode)
457 WCHAR str_header[] = {'I','n','t','e','r','n','e','t','S','h','o','r','t','c','u','t',0};
458 WCHAR str_URL[] = {'U','R','L',0};
459 WCHAR str_iconfile[] = {'i','c','o','n','f','i','l','e',0};
460 WCHAR str_iconindex[] = {'i','c','o','n','i','n','d','e','x',0};
461 WCHAR *filename = NULL;
462 HRESULT hr;
463 InternetShortcut *This = impl_from_IPersistFile(pFile);
464 TRACE("(%p, %s, 0x%x)\n", pFile, debugstr_w(pszFileName), dwMode);
465 if (dwMode != 0)
466 FIXME("ignoring unimplemented mode 0x%x\n", dwMode);
467 filename = co_strdupW(pszFileName);
468 if (filename != NULL)
470 DWORD r;
471 WCHAR *url;
473 r = get_profile_string(str_header, str_URL, pszFileName, &url);
475 if (url == NULL)
477 hr = E_OUTOFMEMORY;
478 CoTaskMemFree(filename);
480 else if (r == 0)
482 hr = E_FAIL;
483 CoTaskMemFree(filename);
485 else
487 hr = S_OK;
488 CoTaskMemFree(This->currentFile);
489 This->currentFile = filename;
490 CoTaskMemFree(This->url);
491 This->url = url;
492 This->isDirty = FALSE;
495 /* Now we're going to read in the iconfile and iconindex.
496 If we don't find them, that's not a failure case -- it's possible
497 that they just aren't in there. */
498 if (SUCCEEDED(hr))
500 IPropertyStorage *pPropStg;
501 WCHAR *iconfile;
502 WCHAR *iconindexstring;
503 hr = IPropertySetStorage_Open(This->property_set_storage, &FMTID_Intshcut,
504 STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
505 &pPropStg);
507 r = get_profile_string(str_header, str_iconfile, pszFileName, &iconfile);
508 if (iconfile != NULL)
510 PROPSPEC ps;
511 PROPVARIANT pv;
512 ps.ulKind = PRSPEC_PROPID;
513 ps.u.propid = PID_IS_ICONFILE;
514 pv.vt = VT_LPWSTR;
515 pv.u.pwszVal = iconfile;
516 hr = IPropertyStorage_WriteMultiple(pPropStg, 1, &ps, &pv, 0);
517 if (FAILED(hr))
519 TRACE("Failed to store the iconfile to our property storage. hr = 0x%x\n", hr);
522 CoTaskMemFree(iconfile);
525 r = get_profile_string(str_header, str_iconindex, pszFileName, &iconindexstring);
527 if (iconindexstring != NULL)
529 int iconindex;
530 PROPSPEC ps;
531 PROPVARIANT pv;
532 char *iconindexastring = co_strdupWtoA(iconindexstring);
533 sscanf(iconindexastring, "%d", &iconindex);
534 CoTaskMemFree(iconindexastring);
535 ps.ulKind = PRSPEC_PROPID;
536 ps.u.propid = PID_IS_ICONINDEX;
537 pv.vt = VT_I4;
538 pv.u.iVal = iconindex;
539 hr = IPropertyStorage_WriteMultiple(pPropStg, 1, &ps, &pv, 0);
540 if (FAILED(hr))
542 TRACE("Failed to store the iconindex to our property storage. hr = 0x%x\n", hr);
545 CoTaskMemFree(iconindexstring);
548 IPropertyStorage_Release(pPropStg);
550 else
551 hr = E_OUTOFMEMORY;
553 else
554 hr = E_OUTOFMEMORY;
555 return hr;
558 static HRESULT WINAPI PersistFile_Save(IPersistFile *pFile, LPCOLESTR pszFileName, BOOL fRemember)
560 HRESULT hr = S_OK;
561 INT len;
562 CHAR *url;
563 InternetShortcut *This = impl_from_IPersistFile(pFile);
565 TRACE("(%p, %s, %d)\n", pFile, debugstr_w(pszFileName), fRemember);
567 if (pszFileName != NULL && fRemember)
569 LPOLESTR oldFile = This->currentFile;
570 This->currentFile = co_strdupW(pszFileName);
571 if (This->currentFile == NULL)
573 This->currentFile = oldFile;
574 return E_OUTOFMEMORY;
576 CoTaskMemFree(oldFile);
578 if (This->url == NULL)
579 return E_FAIL;
581 /* Windows seems to always write:
582 * ASCII "[InternetShortcut]" headers
583 * ASCII names in "name=value" pairs
584 * An ASCII (probably UTF8?) value in "URL=..."
586 len = WideCharToMultiByte(CP_UTF8, 0, This->url, -1, NULL, 0, 0, 0);
587 url = heap_alloc(len);
588 if (url != NULL)
590 HANDLE file;
591 WideCharToMultiByte(CP_UTF8, 0, This->url, -1, url, len, 0, 0);
592 file = CreateFileW(pszFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
593 if (file != INVALID_HANDLE_VALUE)
595 DWORD bytesWritten;
596 char *iconfile;
597 char str_header[] = "[InternetShortcut]";
598 char str_URL[] = "URL=";
599 char str_ICONFILE[] = "ICONFILE=";
600 char str_eol[] = "\r\n";
601 IPropertyStorage *pPropStgRead;
602 PROPSPEC ps[2];
603 PROPVARIANT pvread[2];
604 ps[0].ulKind = PRSPEC_PROPID;
605 ps[0].u.propid = PID_IS_ICONFILE;
606 ps[1].ulKind = PRSPEC_PROPID;
607 ps[1].u.propid = PID_IS_ICONINDEX;
609 WriteFile(file, str_header, lstrlenA(str_header), &bytesWritten, NULL);
610 WriteFile(file, str_eol, lstrlenA(str_eol), &bytesWritten, NULL);
611 WriteFile(file, str_URL, lstrlenA(str_URL), &bytesWritten, NULL);
612 WriteFile(file, url, lstrlenA(url), &bytesWritten, NULL);
613 WriteFile(file, str_eol, lstrlenA(str_eol), &bytesWritten, NULL);
615 hr = IPropertySetStorage_Open(This->property_set_storage, &FMTID_Intshcut, STGM_READ|STGM_SHARE_EXCLUSIVE, &pPropStgRead);
616 if SUCCEEDED(hr)
618 hr = IPropertyStorage_ReadMultiple(pPropStgRead, 2, ps, pvread);
619 if (hr == S_FALSE)
621 /* None of the properties are present, that's ok */
622 hr = S_OK;
623 IPropertyStorage_Release(pPropStgRead);
625 else if SUCCEEDED(hr)
627 char indexString[50];
628 len = WideCharToMultiByte(CP_UTF8, 0, pvread[0].u.pwszVal, -1, NULL, 0, 0, 0);
629 iconfile = heap_alloc(len);
630 if (iconfile != NULL)
632 WideCharToMultiByte(CP_UTF8, 0, pvread[0].u.pwszVal, -1, iconfile, len, 0, 0);
633 WriteFile(file, str_ICONFILE, lstrlenA(str_ICONFILE), &bytesWritten, NULL);
634 WriteFile(file, iconfile, lstrlenA(iconfile), &bytesWritten, NULL);
635 WriteFile(file, str_eol, lstrlenA(str_eol), &bytesWritten, NULL);
638 sprintf(indexString, "ICONINDEX=%d", pvread[1].u.iVal);
639 WriteFile(file, indexString, lstrlenA(indexString), &bytesWritten, NULL);
640 WriteFile(file, str_eol, lstrlenA(str_eol), &bytesWritten, NULL);
642 IPropertyStorage_Release(pPropStgRead);
643 PropVariantClear(&pvread[0]);
644 PropVariantClear(&pvread[1]);
646 else
648 TRACE("Unable to read properties.\n");
651 else
653 TRACE("Unable to get the IPropertyStorage.\n");
656 CloseHandle(file);
657 if (pszFileName == NULL || fRemember)
658 This->isDirty = FALSE;
659 StartLinkProcessor(pszFileName);
661 else
662 hr = E_FAIL;
663 heap_free(url);
665 else
666 hr = E_OUTOFMEMORY;
668 return hr;
671 static HRESULT WINAPI PersistFile_SaveCompleted(IPersistFile *pFile, LPCOLESTR pszFileName)
673 FIXME("(%p, %p): stub\n", pFile, pszFileName);
674 return E_NOTIMPL;
677 static HRESULT WINAPI PersistFile_GetCurFile(IPersistFile *pFile, LPOLESTR *ppszFileName)
679 HRESULT hr = S_OK;
680 InternetShortcut *This = impl_from_IPersistFile(pFile);
681 TRACE("(%p, %p)\n", pFile, ppszFileName);
682 if (This->currentFile == NULL)
683 *ppszFileName = NULL;
684 else
686 *ppszFileName = co_strdupW(This->currentFile);
687 if (*ppszFileName == NULL)
688 hr = E_OUTOFMEMORY;
690 return hr;
693 static HRESULT WINAPI PropertySetStorage_QueryInterface(IPropertySetStorage *iface, REFIID riid, PVOID *ppvObject)
695 InternetShortcut *This = impl_from_IPropertySetStorage(iface);
696 TRACE("(%p)\n", iface);
697 return Unknown_QueryInterface(This, riid, ppvObject);
700 static ULONG WINAPI PropertySetStorage_AddRef(IPropertySetStorage *iface)
702 InternetShortcut *This = impl_from_IPropertySetStorage(iface);
703 TRACE("(%p)\n", iface);
704 return Unknown_AddRef(This);
707 static ULONG WINAPI PropertySetStorage_Release(IPropertySetStorage *iface)
709 InternetShortcut *This = impl_from_IPropertySetStorage(iface);
710 TRACE("(%p)\n", iface);
711 return Unknown_Release(This);
714 static HRESULT WINAPI PropertySetStorage_Create(
715 IPropertySetStorage* iface,
716 REFFMTID rfmtid,
717 const CLSID *pclsid,
718 DWORD grfFlags,
719 DWORD grfMode,
720 IPropertyStorage **ppprstg)
722 InternetShortcut *This = impl_from_IPropertySetStorage(iface);
723 TRACE("(%s, %p, 0x%x, 0x%x, %p)\n", debugstr_guid(rfmtid), pclsid, grfFlags, grfMode, ppprstg);
725 return IPropertySetStorage_Create(This->property_set_storage,
726 rfmtid,
727 pclsid,
728 grfFlags,
729 grfMode,
730 ppprstg);
733 static HRESULT WINAPI PropertySetStorage_Open(
734 IPropertySetStorage* iface,
735 REFFMTID rfmtid,
736 DWORD grfMode,
737 IPropertyStorage **ppprstg)
739 InternetShortcut *This = impl_from_IPropertySetStorage(iface);
740 TRACE("(%s, 0x%x, %p)\n", debugstr_guid(rfmtid), grfMode, ppprstg);
742 /* Note: The |STGM_SHARE_EXCLUSIVE is to cope with a bug in the implementation. Should be fixed in ole32. */
743 return IPropertySetStorage_Open(This->property_set_storage,
744 rfmtid,
745 grfMode|STGM_SHARE_EXCLUSIVE,
746 ppprstg);
749 static HRESULT WINAPI PropertySetStorage_Delete(IPropertySetStorage *iface, REFFMTID rfmtid)
751 InternetShortcut *This = impl_from_IPropertySetStorage(iface);
752 TRACE("(%s)\n", debugstr_guid(rfmtid));
755 return IPropertySetStorage_Delete(This->property_set_storage,
756 rfmtid);
759 static HRESULT WINAPI PropertySetStorage_Enum(IPropertySetStorage *iface, IEnumSTATPROPSETSTG **ppenum)
761 FIXME("(%p): stub\n", ppenum);
762 return E_NOTIMPL;
765 static const IUniformResourceLocatorWVtbl uniformResourceLocatorWVtbl = {
766 UniformResourceLocatorW_QueryInterface,
767 UniformResourceLocatorW_AddRef,
768 UniformResourceLocatorW_Release,
769 UniformResourceLocatorW_SetUrl,
770 UniformResourceLocatorW_GetUrl,
771 UniformResourceLocatorW_InvokeCommand
774 static const IUniformResourceLocatorAVtbl uniformResourceLocatorAVtbl = {
775 UniformResourceLocatorA_QueryInterface,
776 UniformResourceLocatorA_AddRef,
777 UniformResourceLocatorA_Release,
778 UniformResourceLocatorA_SetUrl,
779 UniformResourceLocatorA_GetUrl,
780 UniformResourceLocatorA_InvokeCommand
783 static const IPersistFileVtbl persistFileVtbl = {
784 PersistFile_QueryInterface,
785 PersistFile_AddRef,
786 PersistFile_Release,
787 PersistFile_GetClassID,
788 PersistFile_IsDirty,
789 PersistFile_Load,
790 PersistFile_Save,
791 PersistFile_SaveCompleted,
792 PersistFile_GetCurFile
795 static const IPropertySetStorageVtbl propertySetStorageVtbl = {
796 PropertySetStorage_QueryInterface,
797 PropertySetStorage_AddRef,
798 PropertySetStorage_Release,
799 PropertySetStorage_Create,
800 PropertySetStorage_Open,
801 PropertySetStorage_Delete,
802 PropertySetStorage_Enum
805 static InternetShortcut *create_shortcut(void)
807 InternetShortcut *newshortcut;
809 newshortcut = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(InternetShortcut));
810 if (newshortcut)
812 HRESULT hr;
813 IPropertyStorage *dummy;
815 newshortcut->IUniformResourceLocatorA_iface.lpVtbl = &uniformResourceLocatorAVtbl;
816 newshortcut->IUniformResourceLocatorW_iface.lpVtbl = &uniformResourceLocatorWVtbl;
817 newshortcut->IPersistFile_iface.lpVtbl = &persistFileVtbl;
818 newshortcut->IPropertySetStorage_iface.lpVtbl = &propertySetStorageVtbl;
819 newshortcut->refCount = 1;
820 hr = StgCreateStorageEx(NULL, STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_DELETEONRELEASE,
821 STGFMT_STORAGE, 0, NULL, NULL, &IID_IPropertySetStorage, (void **) &newshortcut->property_set_storage);
822 if FAILED(hr)
824 TRACE("Failed to create the storage object needed for the shortcut.\n");
825 heap_free(newshortcut);
826 return NULL;
829 hr = IPropertySetStorage_Create(newshortcut->property_set_storage, &FMTID_Intshcut, NULL, PROPSETFLAG_DEFAULT, STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, &dummy);
830 if FAILED(hr)
832 TRACE("Failed to create the property object needed for the shortcut.\n");
833 IPropertySetStorage_Release(newshortcut->property_set_storage);
834 heap_free(newshortcut);
835 return NULL;
837 IPropertySetStorage_Release(dummy);
840 return newshortcut;
843 HRESULT WINAPI InternetShortcut_Create(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
845 InternetShortcut *This;
846 HRESULT hres;
848 TRACE("(%p, %s, %p)\n", outer, debugstr_guid(riid), ppv);
850 *ppv = NULL;
852 if(outer)
853 return CLASS_E_NOAGGREGATION;
855 This = create_shortcut();
856 if(!This)
857 return E_OUTOFMEMORY;
859 hres = Unknown_QueryInterface(This, riid, ppv);
860 Unknown_Release(This);
861 return hres;
865 /**********************************************************************
866 * OpenURL (ieframe.@)
868 void WINAPI OpenURL(HWND hWnd, HINSTANCE hInst, LPCSTR lpcstrUrl, int nShowCmd)
870 InternetShortcut *shortcut;
871 WCHAR* urlfilepath = NULL;
872 int len;
874 shortcut = create_shortcut();
876 if(!shortcut)
877 return;
879 len = MultiByteToWideChar(CP_ACP, 0, lpcstrUrl, -1, NULL, 0);
880 urlfilepath = heap_alloc(len * sizeof(WCHAR));
881 MultiByteToWideChar(CP_ACP, 0, lpcstrUrl, -1, urlfilepath, len);
883 if(SUCCEEDED(IPersistFile_Load(&shortcut->IPersistFile_iface, urlfilepath, 0))) {
884 URLINVOKECOMMANDINFOW ici;
886 memset( &ici, 0, sizeof ici );
887 ici.dwcbSize = sizeof ici;
888 ici.dwFlags = IURL_INVOKECOMMAND_FL_USE_DEFAULT_VERB;
889 ici.hwndParent = hWnd;
891 if(FAILED(UniformResourceLocatorW_InvokeCommand(&shortcut->IUniformResourceLocatorW_iface, (PURLINVOKECOMMANDINFOW) &ici)))
892 TRACE("failed to open URL: %s\n", debugstr_a(lpcstrUrl));
895 heap_free(urlfilepath);
896 Unknown_Release(shortcut);