shdocvw: Rudimentary implementation of CLSID_InternetShortcut.
This commit is contained in:
parent
da0604bebd
commit
ad886d6698
|
@ -17,6 +17,7 @@ C_SRCS = \
|
|||
frame.c \
|
||||
ie.c \
|
||||
iexplore.c \
|
||||
intshcut.c \
|
||||
navigate.c \
|
||||
oleobject.c \
|
||||
persist.c \
|
||||
|
|
|
@ -134,6 +134,7 @@ HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
|
|||
static IClassFactoryImpl WB1ClassFactory = {&WBCF_Vtbl, WebBrowserV1_Create};
|
||||
static IClassFactoryImpl WB2ClassFactory = {&WBCF_Vtbl, WebBrowserV2_Create};
|
||||
static IClassFactoryImpl CUHClassFactory = {&WBCF_Vtbl, CUrlHistory_Create};
|
||||
static IClassFactoryImpl ISCClassFactory = {&WBCF_Vtbl, InternetShortcut_Create};
|
||||
|
||||
TRACE("\n");
|
||||
|
||||
|
@ -146,6 +147,9 @@ HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
|
|||
if(IsEqualGUID(&CLSID_CUrlHistory, rclsid))
|
||||
return IClassFactory_QueryInterface(FACTORY(&CUHClassFactory), riid, ppv);
|
||||
|
||||
if(IsEqualGUID(&CLSID_InternetShortcut, rclsid))
|
||||
return IClassFactory_QueryInterface(FACTORY(&ISCClassFactory), riid, ppv);
|
||||
|
||||
/* As a last resort, figure if the CLSID belongs to a 'Shell Instance Object' */
|
||||
return SHDOCVW_GetShellInstanceObjectClassObject(rclsid, riid, ppv);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,432 @@
|
|||
/*
|
||||
* Copyright 2008 Damjan Jovanovic
|
||||
*
|
||||
* ShellLink's barely documented cousin that handles URLs.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* fd.o desktop and menu integration
|
||||
* Implement the IShellLinkA/W interfaces
|
||||
* Handle the SetURL flags
|
||||
* Loading .url files
|
||||
* Implement any other interfaces? Does any software actually use them?
|
||||
*
|
||||
* The installer for the Zuma Deluxe Popcap game is good for testing.
|
||||
*/
|
||||
|
||||
#include "wine/debug.h"
|
||||
#include "shdocvw.h"
|
||||
#include "objidl.h"
|
||||
#include "shobjidl.h"
|
||||
#include "intshcut.h"
|
||||
|
||||
WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
IUniformResourceLocatorA uniformResourceLocatorA;
|
||||
IUniformResourceLocatorW uniformResourceLocatorW;
|
||||
IPersistFile persistFile;
|
||||
|
||||
LONG refCount;
|
||||
|
||||
WCHAR *url;
|
||||
BOOLEAN isDirty;
|
||||
LPOLESTR currentFile;
|
||||
} InternetShortcut;
|
||||
|
||||
/* utility functions */
|
||||
|
||||
static inline InternetShortcut* impl_from_IUniformResourceLocatorA(IUniformResourceLocatorA *iface)
|
||||
{
|
||||
return (InternetShortcut*)((char*)iface - FIELD_OFFSET(InternetShortcut, uniformResourceLocatorA));
|
||||
}
|
||||
|
||||
static inline InternetShortcut* impl_from_IUniformResourceLocatorW(IUniformResourceLocatorW *iface)
|
||||
{
|
||||
return (InternetShortcut*)((char*)iface - FIELD_OFFSET(InternetShortcut, uniformResourceLocatorW));
|
||||
}
|
||||
|
||||
static inline InternetShortcut* impl_from_IPersistFile(IPersistFile *iface)
|
||||
{
|
||||
return (InternetShortcut*)((char*)iface - FIELD_OFFSET(InternetShortcut, persistFile));
|
||||
}
|
||||
|
||||
/* interface functions */
|
||||
|
||||
static HRESULT WINAPI Unknown_QueryInterface(InternetShortcut *This, REFIID riid, PVOID *ppvObject)
|
||||
{
|
||||
TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppvObject);
|
||||
*ppvObject = NULL;
|
||||
if (IsEqualGUID(&IID_IUnknown, riid))
|
||||
*ppvObject = &This->uniformResourceLocatorA;
|
||||
else if (IsEqualGUID(&IID_IUniformResourceLocatorA, riid))
|
||||
*ppvObject = &This->uniformResourceLocatorA;
|
||||
else if (IsEqualGUID(&IID_IUniformResourceLocatorW, riid))
|
||||
*ppvObject = &This->uniformResourceLocatorW;
|
||||
else if (IsEqualGUID(&IID_IPersistFile, riid))
|
||||
*ppvObject = &This->persistFile;
|
||||
else if (IsEqualGUID(&IID_IShellLinkA, riid))
|
||||
{
|
||||
FIXME("The IShellLinkA interface is not yet supported by InternetShortcut\n");
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
else if (IsEqualGUID(&IID_IShellLinkW, riid))
|
||||
{
|
||||
FIXME("The IShellLinkW interface is not yet supported by InternetShortcut\n");
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
else
|
||||
{
|
||||
FIXME("Interface with GUID %s not yet implemented by InternetShortcut\n", debugstr_guid(riid));
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
IUnknown_AddRef((IUnknown*)*ppvObject);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static ULONG WINAPI Unknown_AddRef(InternetShortcut *This)
|
||||
{
|
||||
TRACE("(%p)\n", This);
|
||||
return InterlockedIncrement(&This->refCount);
|
||||
}
|
||||
|
||||
static ULONG WINAPI Unknown_Release(InternetShortcut *This)
|
||||
{
|
||||
ULONG count;
|
||||
TRACE("(%p)\n", This);
|
||||
count = InterlockedDecrement(&This->refCount);
|
||||
if (count == 0)
|
||||
{
|
||||
CoTaskMemFree(This->url);
|
||||
CoTaskMemFree(This->currentFile);
|
||||
heap_free(This);
|
||||
SHDOCVW_UnlockModule();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI UniformResourceLocatorW_QueryInterface(IUniformResourceLocatorW *url, REFIID riid, PVOID *ppvObject)
|
||||
{
|
||||
InternetShortcut *This = impl_from_IUniformResourceLocatorW(url);
|
||||
TRACE("(%p, %s, %p)\n", url, debugstr_guid(riid), ppvObject);
|
||||
return Unknown_QueryInterface(This, riid, ppvObject);
|
||||
}
|
||||
|
||||
static ULONG WINAPI UniformResourceLocatorW_AddRef(IUniformResourceLocatorW *url)
|
||||
{
|
||||
InternetShortcut *This = impl_from_IUniformResourceLocatorW(url);
|
||||
TRACE("(%p)\n", url);
|
||||
return Unknown_AddRef(This);
|
||||
}
|
||||
|
||||
static ULONG WINAPI UniformResourceLocatorW_Release(IUniformResourceLocatorW *url)
|
||||
{
|
||||
InternetShortcut *This = impl_from_IUniformResourceLocatorW(url);
|
||||
TRACE("(%p)\n", url);
|
||||
return Unknown_Release(This);
|
||||
}
|
||||
|
||||
static HRESULT WINAPI UniformResourceLocatorW_SetUrl(IUniformResourceLocatorW *url, LPCWSTR pcszURL, DWORD dwInFlags)
|
||||
{
|
||||
WCHAR *newURL = NULL;
|
||||
InternetShortcut *This = impl_from_IUniformResourceLocatorW(url);
|
||||
TRACE("(%p, %s, 0x%x)\n", url, debugstr_w(pcszURL), dwInFlags);
|
||||
if (dwInFlags != 0)
|
||||
FIXME("ignoring unsupported flags 0x%x\n", dwInFlags);
|
||||
if (pcszURL != NULL)
|
||||
{
|
||||
newURL = co_strdupW(pcszURL);
|
||||
if (newURL == NULL)
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
CoTaskMemFree(This->url);
|
||||
This->url = newURL;
|
||||
This->isDirty = TRUE;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI UniformResourceLocatorW_GetUrl(IUniformResourceLocatorW *url, LPWSTR *ppszURL)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
InternetShortcut *This = impl_from_IUniformResourceLocatorW(url);
|
||||
TRACE("(%p, %p)\n", url, ppszURL);
|
||||
if (This->url == NULL)
|
||||
*ppszURL = NULL;
|
||||
else
|
||||
{
|
||||
*ppszURL = co_strdupW(This->url);
|
||||
if (*ppszURL == NULL)
|
||||
hr = E_OUTOFMEMORY;
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI UniformResourceLocatorW_InvokeCommand(IUniformResourceLocatorW *url, PURLINVOKECOMMANDINFOW pCommandInfo)
|
||||
{
|
||||
FIXME("(%p, %p): stub\n", url, pCommandInfo);
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI UniformResourceLocatorA_QueryInterface(IUniformResourceLocatorA *url, REFIID riid, PVOID *ppvObject)
|
||||
{
|
||||
InternetShortcut *This = impl_from_IUniformResourceLocatorA(url);
|
||||
TRACE("(%p, %s, %p)\n", url, debugstr_guid(riid), ppvObject);
|
||||
return Unknown_QueryInterface(This, riid, ppvObject);
|
||||
}
|
||||
|
||||
static ULONG WINAPI UniformResourceLocatorA_AddRef(IUniformResourceLocatorA *url)
|
||||
{
|
||||
InternetShortcut *This = impl_from_IUniformResourceLocatorA(url);
|
||||
TRACE("(%p)\n", url);
|
||||
return Unknown_AddRef(This);
|
||||
}
|
||||
|
||||
static ULONG WINAPI UniformResourceLocatorA_Release(IUniformResourceLocatorA *url)
|
||||
{
|
||||
InternetShortcut *This = impl_from_IUniformResourceLocatorA(url);
|
||||
TRACE("(%p)\n", url);
|
||||
return Unknown_Release(This);
|
||||
}
|
||||
|
||||
static HRESULT WINAPI UniformResourceLocatorA_SetUrl(IUniformResourceLocatorA *url, LPCSTR pcszURL, DWORD dwInFlags)
|
||||
{
|
||||
WCHAR *newURL = NULL;
|
||||
InternetShortcut *This = impl_from_IUniformResourceLocatorA(url);
|
||||
TRACE("(%p, %s, 0x%x)\n", url, debugstr_a(pcszURL), dwInFlags);
|
||||
if (dwInFlags != 0)
|
||||
FIXME("ignoring unsupported flags 0x%x\n", dwInFlags);
|
||||
if (pcszURL != NULL)
|
||||
{
|
||||
newURL = co_strdupAtoW(pcszURL);
|
||||
if (newURL == NULL)
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
CoTaskMemFree(This->url);
|
||||
This->url = newURL;
|
||||
This->isDirty = TRUE;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI UniformResourceLocatorA_GetUrl(IUniformResourceLocatorA *url, LPSTR *ppszURL)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
InternetShortcut *This = impl_from_IUniformResourceLocatorA(url);
|
||||
TRACE("(%p, %p)\n", url, ppszURL);
|
||||
if (This->url == NULL)
|
||||
*ppszURL = NULL;
|
||||
else
|
||||
{
|
||||
*ppszURL = co_strdupWtoA(This->url);
|
||||
if (*ppszURL == NULL)
|
||||
hr = E_OUTOFMEMORY;
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI UniformResourceLocatorA_InvokeCommand(IUniformResourceLocatorA *url, PURLINVOKECOMMANDINFOA pCommandInfo)
|
||||
{
|
||||
FIXME("(%p, %p): stub\n", url, pCommandInfo);
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI PersistFile_QueryInterface(IPersistFile *pFile, REFIID riid, PVOID *ppvObject)
|
||||
{
|
||||
InternetShortcut *This = impl_from_IPersistFile(pFile);
|
||||
TRACE("(%p, %s, %p)\n", pFile, debugstr_guid(riid), ppvObject);
|
||||
return Unknown_QueryInterface(This, riid, ppvObject);
|
||||
}
|
||||
|
||||
static ULONG WINAPI PersistFile_AddRef(IPersistFile *pFile)
|
||||
{
|
||||
InternetShortcut *This = impl_from_IPersistFile(pFile);
|
||||
TRACE("(%p)\n", pFile);
|
||||
return Unknown_AddRef(This);
|
||||
}
|
||||
|
||||
static ULONG WINAPI PersistFile_Release(IPersistFile *pFile)
|
||||
{
|
||||
InternetShortcut *This = impl_from_IPersistFile(pFile);
|
||||
TRACE("(%p)\n", pFile);
|
||||
return Unknown_Release(This);
|
||||
}
|
||||
|
||||
static HRESULT WINAPI PersistFile_GetClassID(IPersistFile *pFile, CLSID *pClassID)
|
||||
{
|
||||
TRACE("(%p, %p)\n", pFile, pClassID);
|
||||
*pClassID = CLSID_InternetShortcut;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI PersistFile_IsDirty(IPersistFile *pFile)
|
||||
{
|
||||
InternetShortcut *This = impl_from_IPersistFile(pFile);
|
||||
TRACE("(%p)\n", pFile);
|
||||
return This->isDirty ? S_OK : S_FALSE;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI PersistFile_Load(IPersistFile *pFile, LPCOLESTR pszFileName, DWORD dwMode)
|
||||
{
|
||||
FIXME("(%p, %p, 0x%x): stub\n", pFile, pszFileName, dwMode);
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI PersistFile_Save(IPersistFile *pFile, LPCOLESTR pszFileName, BOOL fRemember)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
INT len;
|
||||
CHAR *url;
|
||||
InternetShortcut *This = impl_from_IPersistFile(pFile);
|
||||
|
||||
TRACE("(%p, %s, %d)\n", pFile, debugstr_w(pszFileName), fRemember);
|
||||
|
||||
if (pszFileName != NULL && fRemember)
|
||||
{
|
||||
LPOLESTR oldFile = This->currentFile;
|
||||
This->currentFile = co_strdupW(pszFileName);
|
||||
if (This->currentFile == NULL)
|
||||
{
|
||||
This->currentFile = oldFile;
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
CoTaskMemFree(oldFile);
|
||||
}
|
||||
if (This->url == NULL)
|
||||
return E_FAIL;
|
||||
|
||||
/* Windows seems to always write:
|
||||
* ASCII "[InternetShortcut]" headers
|
||||
* ASCII names in "name=value" pairs
|
||||
* An ASCII (probably UTF8?) value in "URL=..."
|
||||
*/
|
||||
len = WideCharToMultiByte(CP_UTF8, 0, This->url, -1, NULL, 0, 0, 0);
|
||||
url = heap_alloc(len);
|
||||
if (url != NULL)
|
||||
{
|
||||
HANDLE file;
|
||||
WideCharToMultiByte(CP_UTF8, 0, This->url, -1, url, len, 0, 0);
|
||||
file = CreateFileW(pszFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (file != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DWORD bytesWritten;
|
||||
char str_header[] = "[InternetShortcut]";
|
||||
char str_URL[] = "URL=";
|
||||
char str_eol[] = "\r\n";
|
||||
|
||||
WriteFile(file, str_header, lstrlenA(str_header), &bytesWritten, NULL);
|
||||
WriteFile(file, str_eol, lstrlenA(str_eol), &bytesWritten, NULL);
|
||||
WriteFile(file, str_URL, lstrlenA(str_URL), &bytesWritten, NULL);
|
||||
WriteFile(file, url, lstrlenA(url), &bytesWritten, NULL);
|
||||
WriteFile(file, str_eol, lstrlenA(str_eol), &bytesWritten, NULL);
|
||||
CloseHandle(file);
|
||||
if (pszFileName == NULL || fRemember)
|
||||
This->isDirty = FALSE;
|
||||
}
|
||||
else
|
||||
hr = E_FAIL;
|
||||
heap_free(url);
|
||||
}
|
||||
else
|
||||
hr = E_OUTOFMEMORY;
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI PersistFile_SaveCompleted(IPersistFile *pFile, LPCOLESTR pszFileName)
|
||||
{
|
||||
FIXME("(%p, %p): stub\n", pFile, pszFileName);
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI PersistFile_GetCurFile(IPersistFile *pFile, LPOLESTR *ppszFileName)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
InternetShortcut *This = impl_from_IPersistFile(pFile);
|
||||
TRACE("(%p, %p)\n", pFile, ppszFileName);
|
||||
if (This->currentFile == NULL)
|
||||
*ppszFileName = NULL;
|
||||
else
|
||||
{
|
||||
*ppszFileName = co_strdupW(This->currentFile);
|
||||
if (*ppszFileName == NULL)
|
||||
hr = E_OUTOFMEMORY;
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static const IUniformResourceLocatorWVtbl uniformResourceLocatorWVtbl = {
|
||||
UniformResourceLocatorW_QueryInterface,
|
||||
UniformResourceLocatorW_AddRef,
|
||||
UniformResourceLocatorW_Release,
|
||||
UniformResourceLocatorW_SetUrl,
|
||||
UniformResourceLocatorW_GetUrl,
|
||||
UniformResourceLocatorW_InvokeCommand
|
||||
};
|
||||
|
||||
static const IUniformResourceLocatorAVtbl uniformResourceLocatorAVtbl = {
|
||||
UniformResourceLocatorA_QueryInterface,
|
||||
UniformResourceLocatorA_AddRef,
|
||||
UniformResourceLocatorA_Release,
|
||||
UniformResourceLocatorA_SetUrl,
|
||||
UniformResourceLocatorA_GetUrl,
|
||||
UniformResourceLocatorA_InvokeCommand
|
||||
};
|
||||
|
||||
static const IPersistFileVtbl persistFileVtbl = {
|
||||
PersistFile_QueryInterface,
|
||||
PersistFile_AddRef,
|
||||
PersistFile_Release,
|
||||
PersistFile_GetClassID,
|
||||
PersistFile_IsDirty,
|
||||
PersistFile_Load,
|
||||
PersistFile_Save,
|
||||
PersistFile_SaveCompleted,
|
||||
PersistFile_GetCurFile
|
||||
};
|
||||
|
||||
HRESULT InternetShortcut_Create(IUnknown *pOuter, REFIID riid, void **ppv)
|
||||
{
|
||||
InternetShortcut *This;
|
||||
HRESULT hr;
|
||||
|
||||
TRACE("(%p, %s, %p)\n", pOuter, debugstr_guid(riid), ppv);
|
||||
|
||||
*ppv = NULL;
|
||||
|
||||
if(pOuter)
|
||||
return CLASS_E_NOAGGREGATION;
|
||||
|
||||
This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(InternetShortcut));
|
||||
if (This)
|
||||
{
|
||||
This->uniformResourceLocatorA.lpVtbl = &uniformResourceLocatorAVtbl;
|
||||
This->uniformResourceLocatorW.lpVtbl = &uniformResourceLocatorWVtbl;
|
||||
This->persistFile.lpVtbl = &persistFileVtbl;
|
||||
This->refCount = 0;
|
||||
hr = Unknown_QueryInterface(This, riid, ppv);
|
||||
if (SUCCEEDED(hr))
|
||||
SHDOCVW_LockModule();
|
||||
else
|
||||
heap_free(This);
|
||||
return hr;
|
||||
}
|
||||
else
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
|
@ -224,6 +224,8 @@ void InternetExplorer_WebBrowser_Init(InternetExplorer*);
|
|||
|
||||
HRESULT CUrlHistory_Create(IUnknown*,REFIID,void**);
|
||||
|
||||
HRESULT InternetShortcut_Create(IUnknown*,REFIID,void**);
|
||||
|
||||
#define DEFINE_THIS(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,lp ## ifc ## Vtbl)))
|
||||
|
||||
/**********************************************************************
|
||||
|
@ -273,4 +275,34 @@ static inline LPWSTR heap_strdupW(LPCWSTR str)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static inline LPWSTR co_strdupW(LPCWSTR str)
|
||||
{
|
||||
WCHAR *ret = CoTaskMemAlloc((strlenW(str) + 1)*sizeof(WCHAR));
|
||||
if (ret)
|
||||
lstrcpyW(ret, str);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline LPWSTR co_strdupAtoW(LPCSTR str)
|
||||
{
|
||||
INT len;
|
||||
WCHAR *ret;
|
||||
len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
|
||||
ret = CoTaskMemAlloc(len*sizeof(WCHAR));
|
||||
if (ret)
|
||||
MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline LPSTR co_strdupWtoA(LPCWSTR str)
|
||||
{
|
||||
INT len;
|
||||
CHAR *ret;
|
||||
len = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, 0, 0);
|
||||
ret = CoTaskMemAlloc(len);
|
||||
if (ret)
|
||||
WideCharToMultiByte(CP_ACP, 0, str, -1, ret, len, 0, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* __WINE_SHDOCVW_H */
|
||||
|
|
|
@ -6,6 +6,7 @@ TESTDLL = shdocvw.dll
|
|||
IMPORTS = shell32 ole32 oleaut32 user32 advapi32 kernel32
|
||||
|
||||
CTESTS = \
|
||||
intshcut.c \
|
||||
shortcut.c \
|
||||
webbrowser.c
|
||||
|
||||
|
|
|
@ -0,0 +1,225 @@
|
|||
/*
|
||||
* Unit tests to document InternetShortcut's behaviour
|
||||
*
|
||||
* Copyright 2008 Damjan Jovanovic
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <wine/test.h>
|
||||
|
||||
#define COBJMACROS
|
||||
|
||||
#include "windef.h"
|
||||
#include "winbase.h"
|
||||
#include "winreg.h"
|
||||
#include "winerror.h"
|
||||
|
||||
#include "shlobj.h"
|
||||
#include "shobjidl.h"
|
||||
#include "shlguid.h"
|
||||
#include "ole2.h"
|
||||
#include "initguid.h"
|
||||
#include "isguids.h"
|
||||
#include "intshcut.h"
|
||||
|
||||
#include "wine/test.h"
|
||||
|
||||
static WINAPI HRESULT Unknown_QueryInterface(IUnknown *pUnknown, REFIID riid, void **ppvObject)
|
||||
{
|
||||
if (IsEqualGUID(&IID_IUnknown, riid))
|
||||
{
|
||||
*ppvObject = pUnknown;
|
||||
return S_OK;
|
||||
}
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
static WINAPI ULONG Unknown_AddRef(IUnknown *pUnknown)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
static WINAPI ULONG Unknown_Release(IUnknown *pUnknown)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static IUnknownVtbl unknownVtbl = {
|
||||
Unknown_QueryInterface,
|
||||
Unknown_AddRef,
|
||||
Unknown_Release
|
||||
};
|
||||
|
||||
static IUnknown unknown = {
|
||||
&unknownVtbl
|
||||
};
|
||||
|
||||
static const char *printGUID(const GUID *guid)
|
||||
{
|
||||
static char guidSTR[39];
|
||||
|
||||
if (!guid) return NULL;
|
||||
|
||||
sprintf(guidSTR, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
|
||||
guid->Data1, guid->Data2, guid->Data3,
|
||||
guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
|
||||
guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
|
||||
return guidSTR;
|
||||
}
|
||||
|
||||
static void test_Aggregability(void)
|
||||
{
|
||||
HRESULT hr;
|
||||
IUnknown *pUnknown = NULL;
|
||||
|
||||
hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL, &IID_IUnknown, (void**)&pUnknown);
|
||||
ok(SUCCEEDED(hr), "could not create instance of CLSID_InternetShortcut with IID_IUnknown, hr = 0x%x\n", hr);
|
||||
if (pUnknown)
|
||||
IUnknown_Release(pUnknown);
|
||||
|
||||
hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL, &IID_IUniformResourceLocatorA, (void**)&pUnknown);
|
||||
ok(SUCCEEDED(hr), "could not create instance of CLSID_InternetShortcut with IID_IUniformResourceLocatorA, hr = 0x%x\n", hr);
|
||||
if (pUnknown)
|
||||
IUnknown_Release(pUnknown);
|
||||
|
||||
hr = CoCreateInstance(&CLSID_InternetShortcut, &unknown, CLSCTX_ALL, &IID_IUnknown, (void**)&pUnknown);
|
||||
ok(FAILED(hr), "aggregation didn't fail like it should, hr = 0x%x\n", hr);
|
||||
if (pUnknown)
|
||||
IUnknown_Release(pUnknown);
|
||||
}
|
||||
|
||||
static void can_query_interface(IUnknown *pUnknown, REFIID riid)
|
||||
{
|
||||
HRESULT hr;
|
||||
IUnknown *newInterface;
|
||||
hr = IUnknown_QueryInterface(pUnknown, riid, (void**)&newInterface);
|
||||
ok(SUCCEEDED(hr), "interface %s could not be queried\n", printGUID(riid));
|
||||
if (SUCCEEDED(hr))
|
||||
IUnknown_Release(newInterface);
|
||||
}
|
||||
|
||||
static void test_QueryInterface(void)
|
||||
{
|
||||
HRESULT hr;
|
||||
IUnknown *pUnknown;
|
||||
|
||||
hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL, &IID_IUnknown, (void**)&pUnknown);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
can_query_interface(pUnknown, &IID_IUniformResourceLocatorA);
|
||||
can_query_interface(pUnknown, &IID_IUniformResourceLocatorW);
|
||||
can_query_interface(pUnknown, &IID_IPersistFile);
|
||||
IUnknown_Release(pUnknown);
|
||||
}
|
||||
else
|
||||
skip("could not create a CLSID_InternetShortcut for QueryInterface tests, hr=0x%x\n", hr);
|
||||
}
|
||||
|
||||
static CHAR *set_and_get_url(IUniformResourceLocatorA *urlA, LPCSTR input, DWORD flags)
|
||||
{
|
||||
HRESULT hr;
|
||||
hr = urlA->lpVtbl->SetURL(urlA, input, flags);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
CHAR *output;
|
||||
hr = urlA->lpVtbl->GetURL(urlA, &output);
|
||||
if (SUCCEEDED(hr))
|
||||
return output;
|
||||
else
|
||||
skip("GetUrl failed, hr=0x%x\n", hr);
|
||||
}
|
||||
else
|
||||
skip("SetUrl (%s, 0x%x) failed, hr=0x%x\n", input, flags, hr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void check_string_transform(IUniformResourceLocatorA *urlA, LPCSTR input, DWORD flags, LPCSTR expectedOutput)
|
||||
{
|
||||
CHAR *output = set_and_get_url(urlA, input, flags);
|
||||
if (output != NULL)
|
||||
{
|
||||
ok(lstrcmpA(output, expectedOutput) == 0, "unexpected URL change %s -> %s (expected %s)\n",
|
||||
input, output, expectedOutput);
|
||||
CoTaskMemFree(output);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_NullURLs(void)
|
||||
{
|
||||
HRESULT hr;
|
||||
IUniformResourceLocatorA *urlA;
|
||||
|
||||
hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL, &IID_IUniformResourceLocatorA, (void**)&urlA);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
LPSTR url = NULL;
|
||||
|
||||
hr = urlA->lpVtbl->GetURL(urlA, &url);
|
||||
ok(SUCCEEDED(hr), "getting uninitialized URL unexpectedly failed, hr=0x%x\n", hr);
|
||||
ok(url == NULL, "unitialized URL is not NULL but %s\n", url);
|
||||
|
||||
hr = urlA->lpVtbl->SetURL(urlA, NULL, 0);
|
||||
ok(SUCCEEDED(hr), "setting NULL URL unexpectedly failed, hr=0x%x\n", hr);
|
||||
|
||||
hr = urlA->lpVtbl->GetURL(urlA, &url);
|
||||
ok(SUCCEEDED(hr), "getting NULL URL unexpectedly failed, hr=0x%x\n", hr);
|
||||
ok(url == NULL, "URL unexpectedly not NULL but %s\n", url);
|
||||
|
||||
urlA->lpVtbl->Release(urlA);
|
||||
}
|
||||
else
|
||||
skip("could not create a CLSID_InternetShortcut for NullURL tests, hr=0x%x\n", hr);
|
||||
}
|
||||
|
||||
static void test_SetURLFlags(void)
|
||||
{
|
||||
HRESULT hr;
|
||||
IUniformResourceLocatorA *urlA;
|
||||
|
||||
hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL, &IID_IUniformResourceLocatorA, (void**)&urlA);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
check_string_transform(urlA, "somerandomstring", 0, "somerandomstring");
|
||||
check_string_transform(urlA, "www.winehq.org", 0, "www.winehq.org");
|
||||
|
||||
todo_wine
|
||||
{
|
||||
check_string_transform(urlA, "www.winehq.org", IURL_SETURL_FL_GUESS_PROTOCOL, "http://www.winehq.org/");
|
||||
check_string_transform(urlA, "ftp.winehq.org", IURL_SETURL_FL_GUESS_PROTOCOL, "ftp://ftp.winehq.org/");
|
||||
}
|
||||
|
||||
urlA->lpVtbl->Release(urlA);
|
||||
}
|
||||
else
|
||||
skip("could not create a CLSID_InternetShortcut for SetUrl tests, hr=0x%x\n", hr);
|
||||
}
|
||||
|
||||
static void test_InternetShortcut(void)
|
||||
{
|
||||
test_Aggregability();
|
||||
test_QueryInterface();
|
||||
test_NullURLs();
|
||||
test_SetURLFlags();
|
||||
}
|
||||
|
||||
START_TEST(intshcut)
|
||||
{
|
||||
OleInitialize(NULL);
|
||||
test_InternetShortcut();
|
||||
OleUninitialize();
|
||||
}
|
Loading…
Reference in New Issue