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.
34 IUniformResourceLocatorA IUniformResourceLocatorA_iface
;
35 IUniformResourceLocatorW IUniformResourceLocatorW_iface
;
36 IPersistFile IPersistFile_iface
;
37 IPropertySetStorage IPropertySetStorage_iface
;
41 IPropertySetStorage
*property_set_storage
;
47 /* utility functions */
49 static inline InternetShortcut
* impl_from_IUniformResourceLocatorA(IUniformResourceLocatorA
*iface
)
51 return CONTAINING_RECORD(iface
, InternetShortcut
, IUniformResourceLocatorA_iface
);
54 static inline InternetShortcut
* impl_from_IUniformResourceLocatorW(IUniformResourceLocatorW
*iface
)
56 return CONTAINING_RECORD(iface
, InternetShortcut
, IUniformResourceLocatorW_iface
);
59 static inline InternetShortcut
* impl_from_IPersistFile(IPersistFile
*iface
)
61 return CONTAINING_RECORD(iface
, InternetShortcut
, IPersistFile_iface
);
64 static inline InternetShortcut
* impl_from_IPropertySetStorage(IPropertySetStorage
*iface
)
66 return CONTAINING_RECORD(iface
, InternetShortcut
, IPropertySetStorage_iface
);
69 static BOOL
run_winemenubuilder( const WCHAR
*args
)
71 static const WCHAR menubuilder
[] = {'\\','w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',0};
75 PROCESS_INFORMATION pi
;
80 GetSystemDirectoryW( app
, MAX_PATH
- sizeof(menubuilder
)/sizeof(WCHAR
) );
81 strcatW( app
, menubuilder
);
83 len
= (strlenW( app
) + strlenW( args
) + 1) * sizeof(WCHAR
);
84 buffer
= heap_alloc( len
);
88 strcpyW( buffer
, app
);
89 strcatW( buffer
, args
);
91 TRACE("starting %s\n",debugstr_w(buffer
));
93 memset(&si
, 0, sizeof(si
));
96 Wow64DisableWow64FsRedirection( &redir
);
97 ret
= CreateProcessW( app
, buffer
, NULL
, NULL
, FALSE
, DETACHED_PROCESS
, NULL
, NULL
, &si
, &pi
);
98 Wow64RevertWow64FsRedirection( redir
);
104 CloseHandle( pi
.hProcess
);
105 CloseHandle( pi
.hThread
);
111 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
113 static const WCHAR szFormat
[] = { ' ','-','w',' ','-','u',' ','"','%','s','"',0 };
118 len
= sizeof(szFormat
) + lstrlenW( szLink
) * sizeof(WCHAR
);
119 buffer
= heap_alloc( len
);
123 sprintfW( buffer
, szFormat
, szLink
);
124 ret
= run_winemenubuilder( buffer
);
129 /* interface functions */
131 static HRESULT
Unknown_QueryInterface(InternetShortcut
*This
, REFIID riid
, PVOID
*ppvObject
)
133 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppvObject
);
135 if (IsEqualGUID(&IID_IUnknown
, riid
))
136 *ppvObject
= &This
->IUniformResourceLocatorA_iface
;
137 else if (IsEqualGUID(&IID_IUniformResourceLocatorA
, riid
))
138 *ppvObject
= &This
->IUniformResourceLocatorA_iface
;
139 else if (IsEqualGUID(&IID_IUniformResourceLocatorW
, riid
))
140 *ppvObject
= &This
->IUniformResourceLocatorW_iface
;
141 else if (IsEqualGUID(&IID_IPersistFile
, riid
))
142 *ppvObject
= &This
->IPersistFile_iface
;
143 else if (IsEqualGUID(&IID_IPropertySetStorage
, riid
))
144 *ppvObject
= &This
->IPropertySetStorage_iface
;
145 else if (IsEqualGUID(&IID_IShellLinkA
, riid
))
147 FIXME("The IShellLinkA interface is not yet supported by InternetShortcut\n");
148 return E_NOINTERFACE
;
150 else if (IsEqualGUID(&IID_IShellLinkW
, riid
))
152 FIXME("The IShellLinkW interface is not yet supported by InternetShortcut\n");
153 return E_NOINTERFACE
;
157 FIXME("Interface with GUID %s not yet implemented by InternetShortcut\n", debugstr_guid(riid
));
158 return E_NOINTERFACE
;
160 IUnknown_AddRef((IUnknown
*)*ppvObject
);
164 static ULONG
Unknown_AddRef(InternetShortcut
*This
)
166 TRACE("(%p)\n", This
);
167 return InterlockedIncrement(&This
->refCount
);
170 static ULONG
Unknown_Release(InternetShortcut
*This
)
173 TRACE("(%p)\n", This
);
174 count
= InterlockedDecrement(&This
->refCount
);
177 CoTaskMemFree(This
->url
);
178 CoTaskMemFree(This
->currentFile
);
179 IPropertySetStorage_Release(This
->property_set_storage
);
186 static HRESULT WINAPI
UniformResourceLocatorW_QueryInterface(IUniformResourceLocatorW
*url
, REFIID riid
, PVOID
*ppvObject
)
188 InternetShortcut
*This
= impl_from_IUniformResourceLocatorW(url
);
189 TRACE("(%p, %s, %p)\n", url
, debugstr_guid(riid
), ppvObject
);
190 return Unknown_QueryInterface(This
, riid
, ppvObject
);
193 static ULONG WINAPI
UniformResourceLocatorW_AddRef(IUniformResourceLocatorW
*url
)
195 InternetShortcut
*This
= impl_from_IUniformResourceLocatorW(url
);
196 TRACE("(%p)\n", url
);
197 return Unknown_AddRef(This
);
200 static ULONG WINAPI
UniformResourceLocatorW_Release(IUniformResourceLocatorW
*url
)
202 InternetShortcut
*This
= impl_from_IUniformResourceLocatorW(url
);
203 TRACE("(%p)\n", url
);
204 return Unknown_Release(This
);
207 static HRESULT WINAPI
UniformResourceLocatorW_SetUrl(IUniformResourceLocatorW
*url
, LPCWSTR pcszURL
, DWORD dwInFlags
)
209 WCHAR
*newURL
= NULL
;
210 InternetShortcut
*This
= impl_from_IUniformResourceLocatorW(url
);
211 TRACE("(%p, %s, 0x%x)\n", url
, debugstr_w(pcszURL
), dwInFlags
);
213 FIXME("ignoring unsupported flags 0x%x\n", dwInFlags
);
216 newURL
= co_strdupW(pcszURL
);
218 return E_OUTOFMEMORY
;
220 CoTaskMemFree(This
->url
);
222 This
->isDirty
= TRUE
;
226 static HRESULT WINAPI
UniformResourceLocatorW_GetUrl(IUniformResourceLocatorW
*url
, LPWSTR
*ppszURL
)
228 InternetShortcut
*This
= impl_from_IUniformResourceLocatorW(url
);
230 TRACE("(%p, %p)\n", url
, ppszURL
);
237 *ppszURL
= co_strdupW(This
->url
);
239 return E_OUTOFMEMORY
;
244 static HRESULT WINAPI
UniformResourceLocatorW_InvokeCommand(IUniformResourceLocatorW
*url
, PURLINVOKECOMMANDINFOW pCommandInfo
)
246 InternetShortcut
*This
= impl_from_IUniformResourceLocatorW(url
);
249 static const WCHAR wszURLProtocol
[] = {'U','R','L',' ','P','r','o','t','o','c','o','l',0};
250 SHELLEXECUTEINFOW sei
;
254 TRACE("%p %p\n", This
, pCommandInfo
);
256 if (pCommandInfo
->dwcbSize
< sizeof (URLINVOKECOMMANDINFOW
))
259 if (pCommandInfo
->dwFlags
!= IURL_INVOKECOMMAND_FL_USE_DEFAULT_VERB
)
261 FIXME("(%p, %p): non-default verbs not implemented\n", url
, pCommandInfo
);
265 hres
= CoInternetParseUrl(This
->url
, PARSE_SCHEMA
, 0, app
, sizeof(app
)/sizeof(WCHAR
), NULL
, 0);
269 res
= RegOpenKeyW(HKEY_CLASSES_ROOT
, app
, &hkey
);
270 if(res
!= ERROR_SUCCESS
)
273 res
= RegQueryValueExW(hkey
, wszURLProtocol
, NULL
, &type
, NULL
, NULL
);
275 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
278 memset(&sei
, 0, sizeof(sei
));
279 sei
.cbSize
= sizeof(sei
);
280 sei
.lpFile
= This
->url
;
283 if( ShellExecuteExW(&sei
) )
289 static HRESULT WINAPI
UniformResourceLocatorA_QueryInterface(IUniformResourceLocatorA
*url
, REFIID riid
, PVOID
*ppvObject
)
291 InternetShortcut
*This
= impl_from_IUniformResourceLocatorA(url
);
292 TRACE("(%p, %s, %p)\n", url
, debugstr_guid(riid
), ppvObject
);
293 return Unknown_QueryInterface(This
, riid
, ppvObject
);
296 static ULONG WINAPI
UniformResourceLocatorA_AddRef(IUniformResourceLocatorA
*url
)
298 InternetShortcut
*This
= impl_from_IUniformResourceLocatorA(url
);
299 TRACE("(%p)\n", url
);
300 return Unknown_AddRef(This
);
303 static ULONG WINAPI
UniformResourceLocatorA_Release(IUniformResourceLocatorA
*url
)
305 InternetShortcut
*This
= impl_from_IUniformResourceLocatorA(url
);
306 TRACE("(%p)\n", url
);
307 return Unknown_Release(This
);
310 static HRESULT WINAPI
UniformResourceLocatorA_SetUrl(IUniformResourceLocatorA
*url
, LPCSTR pcszURL
, DWORD dwInFlags
)
312 WCHAR
*newURL
= NULL
;
313 InternetShortcut
*This
= impl_from_IUniformResourceLocatorA(url
);
314 TRACE("(%p, %s, 0x%x)\n", url
, debugstr_a(pcszURL
), dwInFlags
);
316 FIXME("ignoring unsupported flags 0x%x\n", dwInFlags
);
319 newURL
= co_strdupAtoW(pcszURL
);
321 return E_OUTOFMEMORY
;
323 CoTaskMemFree(This
->url
);
325 This
->isDirty
= TRUE
;
329 static HRESULT WINAPI
UniformResourceLocatorA_GetUrl(IUniformResourceLocatorA
*url
, LPSTR
*ppszURL
)
331 InternetShortcut
*This
= impl_from_IUniformResourceLocatorA(url
);
333 TRACE("(%p, %p)\n", url
, ppszURL
);
341 *ppszURL
= co_strdupWtoA(This
->url
);
343 return E_OUTOFMEMORY
;
348 static HRESULT WINAPI
UniformResourceLocatorA_InvokeCommand(IUniformResourceLocatorA
*url
, PURLINVOKECOMMANDINFOA pCommandInfo
)
350 URLINVOKECOMMANDINFOW wideCommandInfo
;
354 InternetShortcut
*This
= impl_from_IUniformResourceLocatorA(url
);
356 wideCommandInfo
.dwcbSize
= sizeof wideCommandInfo
;
357 wideCommandInfo
.dwFlags
= pCommandInfo
->dwFlags
;
358 wideCommandInfo
.hwndParent
= pCommandInfo
->hwndParent
;
360 len
= MultiByteToWideChar(CP_ACP
, 0, pCommandInfo
->pcszVerb
, -1, NULL
, 0);
361 wideVerb
= heap_alloc(len
* sizeof(WCHAR
));
362 MultiByteToWideChar(CP_ACP
, 0, pCommandInfo
->pcszVerb
, -1, wideVerb
, len
);
364 wideCommandInfo
.pcszVerb
= wideVerb
;
366 res
= UniformResourceLocatorW_InvokeCommand(&This
->IUniformResourceLocatorW_iface
, &wideCommandInfo
);
372 static HRESULT WINAPI
PersistFile_QueryInterface(IPersistFile
*pFile
, REFIID riid
, PVOID
*ppvObject
)
374 InternetShortcut
*This
= impl_from_IPersistFile(pFile
);
375 TRACE("(%p, %s, %p)\n", pFile
, debugstr_guid(riid
), ppvObject
);
376 return Unknown_QueryInterface(This
, riid
, ppvObject
);
379 static ULONG WINAPI
PersistFile_AddRef(IPersistFile
*pFile
)
381 InternetShortcut
*This
= impl_from_IPersistFile(pFile
);
382 TRACE("(%p)\n", pFile
);
383 return Unknown_AddRef(This
);
386 static ULONG WINAPI
PersistFile_Release(IPersistFile
*pFile
)
388 InternetShortcut
*This
= impl_from_IPersistFile(pFile
);
389 TRACE("(%p)\n", pFile
);
390 return Unknown_Release(This
);
393 static HRESULT WINAPI
PersistFile_GetClassID(IPersistFile
*pFile
, CLSID
*pClassID
)
395 TRACE("(%p, %p)\n", pFile
, pClassID
);
396 *pClassID
= CLSID_InternetShortcut
;
400 static HRESULT WINAPI
PersistFile_IsDirty(IPersistFile
*pFile
)
402 InternetShortcut
*This
= impl_from_IPersistFile(pFile
);
403 TRACE("(%p)\n", pFile
);
404 return This
->isDirty
? S_OK
: S_FALSE
;
407 /* A helper function: Allocate and fill rString. Return number of bytes read. */
408 static DWORD
get_profile_string(LPCWSTR lpAppName
, LPCWSTR lpKeyName
,
409 LPCWSTR lpFileName
, WCHAR
**rString
)
415 buffer
= CoTaskMemAlloc(len
* sizeof(*buffer
));
418 r
= GetPrivateProfileStringW(lpAppName
, lpKeyName
, NULL
, buffer
, len
, lpFileName
);
424 realloc_buf
= CoTaskMemRealloc(buffer
, len
* sizeof(*buffer
));
425 if (realloc_buf
== NULL
)
427 CoTaskMemFree(buffer
);
431 buffer
= realloc_buf
;
433 r
= GetPrivateProfileStringW(lpAppName
, lpKeyName
, NULL
, buffer
, len
, lpFileName
);
441 static HRESULT WINAPI
PersistFile_Load(IPersistFile
*pFile
, LPCOLESTR pszFileName
, DWORD dwMode
)
443 WCHAR str_header
[] = {'I','n','t','e','r','n','e','t','S','h','o','r','t','c','u','t',0};
444 WCHAR str_URL
[] = {'U','R','L',0};
445 WCHAR str_iconfile
[] = {'i','c','o','n','f','i','l','e',0};
446 WCHAR str_iconindex
[] = {'i','c','o','n','i','n','d','e','x',0};
447 WCHAR
*filename
= NULL
;
449 InternetShortcut
*This
= impl_from_IPersistFile(pFile
);
450 TRACE("(%p, %s, 0x%x)\n", pFile
, debugstr_w(pszFileName
), dwMode
);
452 FIXME("ignoring unimplemented mode 0x%x\n", dwMode
);
453 filename
= co_strdupW(pszFileName
);
454 if (filename
!= NULL
)
459 r
= get_profile_string(str_header
, str_URL
, pszFileName
, &url
);
464 CoTaskMemFree(filename
);
469 CoTaskMemFree(filename
);
474 CoTaskMemFree(This
->currentFile
);
475 This
->currentFile
= filename
;
476 CoTaskMemFree(This
->url
);
478 This
->isDirty
= FALSE
;
481 /* Now we're going to read in the iconfile and iconindex.
482 If we don't find them, that's not a failure case -- it's possible
483 that they just aren't in there. */
486 IPropertyStorage
*pPropStg
;
488 WCHAR
*iconindexstring
;
489 hr
= IPropertySetStorage_Open(This
->property_set_storage
, &FMTID_Intshcut
,
490 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
,
493 r
= get_profile_string(str_header
, str_iconfile
, pszFileName
, &iconfile
);
494 if (iconfile
!= NULL
)
498 ps
.ulKind
= PRSPEC_PROPID
;
499 ps
.u
.propid
= PID_IS_ICONFILE
;
501 pv
.u
.pwszVal
= iconfile
;
502 hr
= IPropertyStorage_WriteMultiple(pPropStg
, 1, &ps
, &pv
, 0);
505 TRACE("Failed to store the iconfile to our property storage. hr = 0x%x\n", hr
);
508 CoTaskMemFree(iconfile
);
511 r
= get_profile_string(str_header
, str_iconindex
, pszFileName
, &iconindexstring
);
513 if (iconindexstring
!= NULL
)
518 char *iconindexastring
= co_strdupWtoA(iconindexstring
);
519 sscanf(iconindexastring
, "%d", &iconindex
);
520 CoTaskMemFree(iconindexastring
);
521 ps
.ulKind
= PRSPEC_PROPID
;
522 ps
.u
.propid
= PID_IS_ICONINDEX
;
524 pv
.u
.iVal
= iconindex
;
525 hr
= IPropertyStorage_WriteMultiple(pPropStg
, 1, &ps
, &pv
, 0);
528 TRACE("Failed to store the iconindex to our property storage. hr = 0x%x\n", hr
);
531 CoTaskMemFree(iconindexstring
);
534 IPropertyStorage_Release(pPropStg
);
544 static HRESULT WINAPI
PersistFile_Save(IPersistFile
*pFile
, LPCOLESTR pszFileName
, BOOL fRemember
)
549 InternetShortcut
*This
= impl_from_IPersistFile(pFile
);
551 TRACE("(%p, %s, %d)\n", pFile
, debugstr_w(pszFileName
), fRemember
);
553 if (pszFileName
!= NULL
&& fRemember
)
555 LPOLESTR oldFile
= This
->currentFile
;
556 This
->currentFile
= co_strdupW(pszFileName
);
557 if (This
->currentFile
== NULL
)
559 This
->currentFile
= oldFile
;
560 return E_OUTOFMEMORY
;
562 CoTaskMemFree(oldFile
);
564 if (This
->url
== NULL
)
567 /* Windows seems to always write:
568 * ASCII "[InternetShortcut]" headers
569 * ASCII names in "name=value" pairs
570 * An ASCII (probably UTF8?) value in "URL=..."
572 len
= WideCharToMultiByte(CP_UTF8
, 0, This
->url
, -1, NULL
, 0, 0, 0);
573 url
= heap_alloc(len
);
577 WideCharToMultiByte(CP_UTF8
, 0, This
->url
, -1, url
, len
, 0, 0);
578 file
= CreateFileW(pszFileName
, GENERIC_WRITE
, FILE_SHARE_READ
, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
579 if (file
!= INVALID_HANDLE_VALUE
)
583 char str_header
[] = "[InternetShortcut]";
584 char str_URL
[] = "URL=";
585 char str_ICONFILE
[] = "ICONFILE=";
586 char str_eol
[] = "\r\n";
587 IPropertyStorage
*pPropStgRead
;
589 PROPVARIANT pvread
[2];
590 ps
[0].ulKind
= PRSPEC_PROPID
;
591 ps
[0].u
.propid
= PID_IS_ICONFILE
;
592 ps
[1].ulKind
= PRSPEC_PROPID
;
593 ps
[1].u
.propid
= PID_IS_ICONINDEX
;
595 WriteFile(file
, str_header
, lstrlenA(str_header
), &bytesWritten
, NULL
);
596 WriteFile(file
, str_eol
, lstrlenA(str_eol
), &bytesWritten
, NULL
);
597 WriteFile(file
, str_URL
, lstrlenA(str_URL
), &bytesWritten
, NULL
);
598 WriteFile(file
, url
, lstrlenA(url
), &bytesWritten
, NULL
);
599 WriteFile(file
, str_eol
, lstrlenA(str_eol
), &bytesWritten
, NULL
);
601 hr
= IPropertySetStorage_Open(This
->property_set_storage
, &FMTID_Intshcut
, STGM_READ
|STGM_SHARE_EXCLUSIVE
, &pPropStgRead
);
604 hr
= IPropertyStorage_ReadMultiple(pPropStgRead
, 2, ps
, pvread
);
607 /* None of the properties are present, that's ok */
609 IPropertyStorage_Release(pPropStgRead
);
611 else if (SUCCEEDED(hr
))
613 char indexString
[50];
614 len
= WideCharToMultiByte(CP_UTF8
, 0, pvread
[0].u
.pwszVal
, -1, NULL
, 0, 0, 0);
615 iconfile
= heap_alloc(len
);
616 if (iconfile
!= NULL
)
618 WideCharToMultiByte(CP_UTF8
, 0, pvread
[0].u
.pwszVal
, -1, iconfile
, len
, 0, 0);
619 WriteFile(file
, str_ICONFILE
, lstrlenA(str_ICONFILE
), &bytesWritten
, NULL
);
620 WriteFile(file
, iconfile
, lstrlenA(iconfile
), &bytesWritten
, NULL
);
621 WriteFile(file
, str_eol
, lstrlenA(str_eol
), &bytesWritten
, NULL
);
624 sprintf(indexString
, "ICONINDEX=%d", pvread
[1].u
.iVal
);
625 WriteFile(file
, indexString
, lstrlenA(indexString
), &bytesWritten
, NULL
);
626 WriteFile(file
, str_eol
, lstrlenA(str_eol
), &bytesWritten
, NULL
);
628 IPropertyStorage_Release(pPropStgRead
);
629 PropVariantClear(&pvread
[0]);
630 PropVariantClear(&pvread
[1]);
634 TRACE("Unable to read properties.\n");
639 TRACE("Unable to get the IPropertyStorage.\n");
643 if (pszFileName
== NULL
|| fRemember
)
644 This
->isDirty
= FALSE
;
645 StartLinkProcessor(pszFileName
);
657 static HRESULT WINAPI
PersistFile_SaveCompleted(IPersistFile
*pFile
, LPCOLESTR pszFileName
)
659 FIXME("(%p, %p): stub\n", pFile
, pszFileName
);
663 static HRESULT WINAPI
PersistFile_GetCurFile(IPersistFile
*pFile
, LPOLESTR
*ppszFileName
)
666 InternetShortcut
*This
= impl_from_IPersistFile(pFile
);
667 TRACE("(%p, %p)\n", pFile
, ppszFileName
);
668 if (This
->currentFile
== NULL
)
669 *ppszFileName
= NULL
;
672 *ppszFileName
= co_strdupW(This
->currentFile
);
673 if (*ppszFileName
== NULL
)
679 static HRESULT WINAPI
PropertySetStorage_QueryInterface(IPropertySetStorage
*iface
, REFIID riid
, PVOID
*ppvObject
)
681 InternetShortcut
*This
= impl_from_IPropertySetStorage(iface
);
682 TRACE("(%p)\n", iface
);
683 return Unknown_QueryInterface(This
, riid
, ppvObject
);
686 static ULONG WINAPI
PropertySetStorage_AddRef(IPropertySetStorage
*iface
)
688 InternetShortcut
*This
= impl_from_IPropertySetStorage(iface
);
689 TRACE("(%p)\n", iface
);
690 return Unknown_AddRef(This
);
693 static ULONG WINAPI
PropertySetStorage_Release(IPropertySetStorage
*iface
)
695 InternetShortcut
*This
= impl_from_IPropertySetStorage(iface
);
696 TRACE("(%p)\n", iface
);
697 return Unknown_Release(This
);
700 static HRESULT WINAPI
PropertySetStorage_Create(
701 IPropertySetStorage
* iface
,
706 IPropertyStorage
**ppprstg
)
708 InternetShortcut
*This
= impl_from_IPropertySetStorage(iface
);
709 TRACE("(%s, %p, 0x%x, 0x%x, %p)\n", debugstr_guid(rfmtid
), pclsid
, grfFlags
, grfMode
, ppprstg
);
711 return IPropertySetStorage_Create(This
->property_set_storage
,
719 static HRESULT WINAPI
PropertySetStorage_Open(
720 IPropertySetStorage
* iface
,
723 IPropertyStorage
**ppprstg
)
725 InternetShortcut
*This
= impl_from_IPropertySetStorage(iface
);
726 TRACE("(%s, 0x%x, %p)\n", debugstr_guid(rfmtid
), grfMode
, ppprstg
);
728 /* Note: The |STGM_SHARE_EXCLUSIVE is to cope with a bug in the implementation. Should be fixed in ole32. */
729 return IPropertySetStorage_Open(This
->property_set_storage
,
731 grfMode
|STGM_SHARE_EXCLUSIVE
,
735 static HRESULT WINAPI
PropertySetStorage_Delete(IPropertySetStorage
*iface
, REFFMTID rfmtid
)
737 InternetShortcut
*This
= impl_from_IPropertySetStorage(iface
);
738 TRACE("(%s)\n", debugstr_guid(rfmtid
));
741 return IPropertySetStorage_Delete(This
->property_set_storage
,
745 static HRESULT WINAPI
PropertySetStorage_Enum(IPropertySetStorage
*iface
, IEnumSTATPROPSETSTG
**ppenum
)
747 FIXME("(%p): stub\n", ppenum
);
751 static const IUniformResourceLocatorWVtbl uniformResourceLocatorWVtbl
= {
752 UniformResourceLocatorW_QueryInterface
,
753 UniformResourceLocatorW_AddRef
,
754 UniformResourceLocatorW_Release
,
755 UniformResourceLocatorW_SetUrl
,
756 UniformResourceLocatorW_GetUrl
,
757 UniformResourceLocatorW_InvokeCommand
760 static const IUniformResourceLocatorAVtbl uniformResourceLocatorAVtbl
= {
761 UniformResourceLocatorA_QueryInterface
,
762 UniformResourceLocatorA_AddRef
,
763 UniformResourceLocatorA_Release
,
764 UniformResourceLocatorA_SetUrl
,
765 UniformResourceLocatorA_GetUrl
,
766 UniformResourceLocatorA_InvokeCommand
769 static const IPersistFileVtbl persistFileVtbl
= {
770 PersistFile_QueryInterface
,
773 PersistFile_GetClassID
,
777 PersistFile_SaveCompleted
,
778 PersistFile_GetCurFile
781 static const IPropertySetStorageVtbl propertySetStorageVtbl
= {
782 PropertySetStorage_QueryInterface
,
783 PropertySetStorage_AddRef
,
784 PropertySetStorage_Release
,
785 PropertySetStorage_Create
,
786 PropertySetStorage_Open
,
787 PropertySetStorage_Delete
,
788 PropertySetStorage_Enum
791 static InternetShortcut
*create_shortcut(void)
793 InternetShortcut
*newshortcut
;
795 newshortcut
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(InternetShortcut
));
799 IPropertyStorage
*dummy
;
801 newshortcut
->IUniformResourceLocatorA_iface
.lpVtbl
= &uniformResourceLocatorAVtbl
;
802 newshortcut
->IUniformResourceLocatorW_iface
.lpVtbl
= &uniformResourceLocatorWVtbl
;
803 newshortcut
->IPersistFile_iface
.lpVtbl
= &persistFileVtbl
;
804 newshortcut
->IPropertySetStorage_iface
.lpVtbl
= &propertySetStorageVtbl
;
805 newshortcut
->refCount
= 1;
806 hr
= StgCreateStorageEx(NULL
, STGM_CREATE
| STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
| STGM_DELETEONRELEASE
,
807 STGFMT_STORAGE
, 0, NULL
, NULL
, &IID_IPropertySetStorage
, (void **) &newshortcut
->property_set_storage
);
810 TRACE("Failed to create the storage object needed for the shortcut.\n");
811 heap_free(newshortcut
);
815 hr
= IPropertySetStorage_Create(newshortcut
->property_set_storage
, &FMTID_Intshcut
, NULL
, PROPSETFLAG_DEFAULT
, STGM_CREATE
| STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, &dummy
);
818 TRACE("Failed to create the property object needed for the shortcut.\n");
819 IPropertySetStorage_Release(newshortcut
->property_set_storage
);
820 heap_free(newshortcut
);
823 IPropertyStorage_Release(dummy
);
829 HRESULT WINAPI
InternetShortcut_Create(IClassFactory
*iface
, IUnknown
*outer
, REFIID riid
, void **ppv
)
831 InternetShortcut
*This
;
834 TRACE("(%p, %s, %p)\n", outer
, debugstr_guid(riid
), ppv
);
839 return CLASS_E_NOAGGREGATION
;
841 This
= create_shortcut();
843 return E_OUTOFMEMORY
;
845 hres
= Unknown_QueryInterface(This
, riid
, ppv
);
846 Unknown_Release(This
);
851 /**********************************************************************
852 * OpenURL (ieframe.@)
854 void WINAPI
OpenURL(HWND hWnd
, HINSTANCE hInst
, LPCSTR lpcstrUrl
, int nShowCmd
)
856 InternetShortcut
*shortcut
;
857 WCHAR
* urlfilepath
= NULL
;
860 shortcut
= create_shortcut();
865 len
= MultiByteToWideChar(CP_ACP
, 0, lpcstrUrl
, -1, NULL
, 0);
866 urlfilepath
= heap_alloc(len
* sizeof(WCHAR
));
867 MultiByteToWideChar(CP_ACP
, 0, lpcstrUrl
, -1, urlfilepath
, len
);
869 if(SUCCEEDED(IPersistFile_Load(&shortcut
->IPersistFile_iface
, urlfilepath
, 0))) {
870 URLINVOKECOMMANDINFOW ici
;
872 memset( &ici
, 0, sizeof ici
);
873 ici
.dwcbSize
= sizeof ici
;
874 ici
.dwFlags
= IURL_INVOKECOMMAND_FL_USE_DEFAULT_VERB
;
875 ici
.hwndParent
= hWnd
;
877 if(FAILED(UniformResourceLocatorW_InvokeCommand(&shortcut
->IUniformResourceLocatorW_iface
, (PURLINVOKECOMMANDINFOW
) &ici
)))
878 TRACE("failed to open URL: %s\n", debugstr_a(lpcstrUrl
));
881 heap_free(urlfilepath
);
882 Unknown_Release(shortcut
);