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.
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(ieframe
);
48 IUniformResourceLocatorA IUniformResourceLocatorA_iface
;
49 IUniformResourceLocatorW IUniformResourceLocatorW_iface
;
50 IPersistFile IPersistFile_iface
;
51 IPropertySetStorage IPropertySetStorage_iface
;
55 IPropertySetStorage
*property_set_storage
;
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};
89 PROCESS_INFORMATION pi
;
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
);
102 strcpyW( buffer
, app
);
103 strcatW( buffer
, args
);
105 TRACE("starting %s\n",debugstr_w(buffer
));
107 memset(&si
, 0, sizeof(si
));
110 Wow64DisableWow64FsRedirection( &redir
);
111 ret
= CreateProcessW( app
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
);
112 Wow64RevertWow64FsRedirection( redir
);
118 CloseHandle( pi
.hProcess
);
119 CloseHandle( pi
.hThread
);
125 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
127 static const WCHAR szFormat
[] = { ' ','-','w',' ','-','u',' ','"','%','s','"',0 };
132 len
= sizeof(szFormat
) + lstrlenW( szLink
) * sizeof(WCHAR
);
133 buffer
= heap_alloc( len
);
137 sprintfW( buffer
, szFormat
, szLink
);
138 ret
= run_winemenubuilder( buffer
);
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
);
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
;
171 FIXME("Interface with GUID %s not yet implemented by InternetShortcut\n", debugstr_guid(riid
));
172 return E_NOINTERFACE
;
174 IUnknown_AddRef((IUnknown
*)*ppvObject
);
178 static ULONG
Unknown_AddRef(InternetShortcut
*This
)
180 TRACE("(%p)\n", This
);
181 return InterlockedIncrement(&This
->refCount
);
184 static ULONG
Unknown_Release(InternetShortcut
*This
)
187 TRACE("(%p)\n", This
);
188 count
= InterlockedDecrement(&This
->refCount
);
191 CoTaskMemFree(This
->url
);
192 CoTaskMemFree(This
->currentFile
);
193 IPropertySetStorage_Release(This
->property_set_storage
);
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
);
227 FIXME("ignoring unsupported flags 0x%x\n", dwInFlags
);
230 newURL
= co_strdupW(pcszURL
);
232 return E_OUTOFMEMORY
;
234 CoTaskMemFree(This
->url
);
236 This
->isDirty
= TRUE
;
240 static HRESULT WINAPI
UniformResourceLocatorW_GetUrl(IUniformResourceLocatorW
*url
, LPWSTR
*ppszURL
)
242 InternetShortcut
*This
= impl_from_IUniformResourceLocatorW(url
);
244 TRACE("(%p, %p)\n", url
, ppszURL
);
251 *ppszURL
= co_strdupW(This
->url
);
253 return E_OUTOFMEMORY
;
258 static HRESULT WINAPI
UniformResourceLocatorW_InvokeCommand(IUniformResourceLocatorW
*url
, PURLINVOKECOMMANDINFOW pCommandInfo
)
260 InternetShortcut
*This
= impl_from_IUniformResourceLocatorW(url
);
263 static const WCHAR wszURLProtocol
[] = {'U','R','L',' ','P','r','o','t','o','c','o','l',0};
264 SHELLEXECUTEINFOW sei
;
268 TRACE("%p %p\n", This
, pCommandInfo
);
270 if (pCommandInfo
->dwcbSize
< sizeof (URLINVOKECOMMANDINFOW
))
273 if (pCommandInfo
->dwFlags
!= IURL_INVOKECOMMAND_FL_USE_DEFAULT_VERB
)
275 FIXME("(%p, %p): non-default verbs not implemented\n", url
, pCommandInfo
);
279 hres
= CoInternetParseUrl(This
->url
, PARSE_SCHEMA
, 0, app
, sizeof(app
)/sizeof(WCHAR
), NULL
, 0);
283 res
= RegOpenKeyW(HKEY_CLASSES_ROOT
, app
, &hkey
);
284 if(res
!= ERROR_SUCCESS
)
287 res
= RegQueryValueExW(hkey
, wszURLProtocol
, NULL
, &type
, NULL
, NULL
);
289 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
292 memset(&sei
, 0, sizeof(sei
));
293 sei
.cbSize
= sizeof(sei
);
294 sei
.lpFile
= This
->url
;
297 if( ShellExecuteExW(&sei
) )
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
);
330 FIXME("ignoring unsupported flags 0x%x\n", dwInFlags
);
333 newURL
= co_strdupAtoW(pcszURL
);
335 return E_OUTOFMEMORY
;
337 CoTaskMemFree(This
->url
);
339 This
->isDirty
= TRUE
;
343 static HRESULT WINAPI
UniformResourceLocatorA_GetUrl(IUniformResourceLocatorA
*url
, LPSTR
*ppszURL
)
345 InternetShortcut
*This
= impl_from_IUniformResourceLocatorA(url
);
347 TRACE("(%p, %p)\n", url
, ppszURL
);
355 *ppszURL
= co_strdupWtoA(This
->url
);
357 return E_OUTOFMEMORY
;
362 static HRESULT WINAPI
UniformResourceLocatorA_InvokeCommand(IUniformResourceLocatorA
*url
, PURLINVOKECOMMANDINFOA pCommandInfo
)
364 URLINVOKECOMMANDINFOW wideCommandInfo
;
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
);
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
;
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
)
429 buffer
= CoTaskMemAlloc(len
* sizeof(*buffer
));
432 r
= GetPrivateProfileStringW(lpAppName
, lpKeyName
, NULL
, buffer
, len
, lpFileName
);
438 realloc_buf
= CoTaskMemRealloc(buffer
, len
* sizeof(*buffer
));
439 if (realloc_buf
== NULL
)
441 CoTaskMemFree(buffer
);
445 buffer
= realloc_buf
;
447 r
= GetPrivateProfileStringW(lpAppName
, lpKeyName
, NULL
, buffer
, len
, lpFileName
);
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
;
463 InternetShortcut
*This
= impl_from_IPersistFile(pFile
);
464 TRACE("(%p, %s, 0x%x)\n", pFile
, debugstr_w(pszFileName
), dwMode
);
466 FIXME("ignoring unimplemented mode 0x%x\n", dwMode
);
467 filename
= co_strdupW(pszFileName
);
468 if (filename
!= NULL
)
473 r
= get_profile_string(str_header
, str_URL
, pszFileName
, &url
);
478 CoTaskMemFree(filename
);
483 CoTaskMemFree(filename
);
488 CoTaskMemFree(This
->currentFile
);
489 This
->currentFile
= filename
;
490 CoTaskMemFree(This
->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. */
500 IPropertyStorage
*pPropStg
;
502 WCHAR
*iconindexstring
;
503 hr
= IPropertySetStorage_Open(This
->property_set_storage
, &FMTID_Intshcut
,
504 STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
,
507 r
= get_profile_string(str_header
, str_iconfile
, pszFileName
, &iconfile
);
508 if (iconfile
!= NULL
)
512 ps
.ulKind
= PRSPEC_PROPID
;
513 ps
.u
.propid
= PID_IS_ICONFILE
;
515 pv
.u
.pwszVal
= iconfile
;
516 hr
= IPropertyStorage_WriteMultiple(pPropStg
, 1, &ps
, &pv
, 0);
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
)
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
;
538 pv
.u
.iVal
= iconindex
;
539 hr
= IPropertyStorage_WriteMultiple(pPropStg
, 1, &ps
, &pv
, 0);
542 TRACE("Failed to store the iconindex to our property storage. hr = 0x%x\n", hr
);
545 CoTaskMemFree(iconindexstring
);
548 IPropertyStorage_Release(pPropStg
);
558 static HRESULT WINAPI
PersistFile_Save(IPersistFile
*pFile
, LPCOLESTR pszFileName
, BOOL fRemember
)
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
)
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
);
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
)
597 char str_header
[] = "[InternetShortcut]";
598 char str_URL
[] = "URL=";
599 char str_ICONFILE
[] = "ICONFILE=";
600 char str_eol
[] = "\r\n";
601 IPropertyStorage
*pPropStgRead
;
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
);
618 hr
= IPropertyStorage_ReadMultiple(pPropStgRead
, 2, ps
, pvread
);
621 /* None of the properties are present, that'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]);
648 TRACE("Unable to read properties.\n");
653 TRACE("Unable to get the IPropertyStorage.\n");
657 if (pszFileName
== NULL
|| fRemember
)
658 This
->isDirty
= FALSE
;
659 StartLinkProcessor(pszFileName
);
671 static HRESULT WINAPI
PersistFile_SaveCompleted(IPersistFile
*pFile
, LPCOLESTR pszFileName
)
673 FIXME("(%p, %p): stub\n", pFile
, pszFileName
);
677 static HRESULT WINAPI
PersistFile_GetCurFile(IPersistFile
*pFile
, LPOLESTR
*ppszFileName
)
680 InternetShortcut
*This
= impl_from_IPersistFile(pFile
);
681 TRACE("(%p, %p)\n", pFile
, ppszFileName
);
682 if (This
->currentFile
== NULL
)
683 *ppszFileName
= NULL
;
686 *ppszFileName
= co_strdupW(This
->currentFile
);
687 if (*ppszFileName
== NULL
)
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
,
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
,
733 static HRESULT WINAPI
PropertySetStorage_Open(
734 IPropertySetStorage
* iface
,
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
,
745 grfMode
|STGM_SHARE_EXCLUSIVE
,
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
,
759 static HRESULT WINAPI
PropertySetStorage_Enum(IPropertySetStorage
*iface
, IEnumSTATPROPSETSTG
**ppenum
)
761 FIXME("(%p): stub\n", ppenum
);
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
,
787 PersistFile_GetClassID
,
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
));
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
);
824 TRACE("Failed to create the storage object needed for the shortcut.\n");
825 heap_free(newshortcut
);
829 hr
= IPropertySetStorage_Create(newshortcut
->property_set_storage
, &FMTID_Intshcut
, NULL
, PROPSETFLAG_DEFAULT
, STGM_CREATE
| STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, &dummy
);
832 TRACE("Failed to create the property object needed for the shortcut.\n");
833 IPropertySetStorage_Release(newshortcut
->property_set_storage
);
834 heap_free(newshortcut
);
837 IPropertySetStorage_Release(dummy
);
843 HRESULT WINAPI
InternetShortcut_Create(IClassFactory
*iface
, IUnknown
*outer
, REFIID riid
, void **ppv
)
845 InternetShortcut
*This
;
848 TRACE("(%p, %s, %p)\n", outer
, debugstr_guid(riid
), ppv
);
853 return CLASS_E_NOAGGREGATION
;
855 This
= create_shortcut();
857 return E_OUTOFMEMORY
;
859 hres
= Unknown_QueryInterface(This
, riid
, ppv
);
860 Unknown_Release(This
);
865 /**********************************************************************
866 * OpenURL (ieframe.@)
868 void WINAPI
OpenURL(HWND hWnd
, HINSTANCE hInst
, LPCSTR lpcstrUrl
, int nShowCmd
)
870 InternetShortcut
*shortcut
;
871 WCHAR
* urlfilepath
= NULL
;
874 shortcut
= create_shortcut();
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
);