diff --git a/reactos/dll/win32/shell32/CShellLink.cpp b/reactos/dll/win32/shell32/CShellLink.cpp index d2208a5b52d..c92a4ad8387 100644 --- a/reactos/dll/win32/shell32/CShellLink.cpp +++ b/reactos/dll/win32/shell32/CShellLink.cpp @@ -76,43 +76,6 @@ struct volume_info #include "poppack.h" -/************************************************************************** -* SH_GetTargetTypeByPath -* -* Function to get target type by passing full path to it -*/ -LPWSTR SH_GetTargetTypeByPath(LPCWSTR lpcwFullPath) -{ - LPCWSTR pwszExt; - static WCHAR wszBuf[MAX_PATH]; - - /* Get file information */ - SHFILEINFO fi; - if (!SHGetFileInfoW(lpcwFullPath, 0, &fi, sizeof(fi), SHGFI_TYPENAME | SHGFI_USEFILEATTRIBUTES )) - { - ERR("SHGetFileInfoW failed for %ls (%lu)\n", lpcwFullPath, GetLastError()); - fi.szTypeName[0] = L'\0'; - fi.hIcon = NULL; - } - - pwszExt = PathFindExtensionW(lpcwFullPath); - if (pwszExt[0]) - { - if (!fi.szTypeName[0]) - { - /* The file type is unknown, so default to string "FileExtension File" */ - size_t cchRemaining = 0; - LPWSTR pwszEnd = NULL; - - StringCchPrintfExW(wszBuf, _countof(wszBuf), &pwszEnd, &cchRemaining, 0, L"%s ", pwszExt + 1); - } - else - StringCbPrintfW(wszBuf, sizeof(wszBuf), L"%s (%s)", fi.szTypeName, pwszExt); /* Update file type */ - } - - return wszBuf; -} - /* IShellLink Implementation */ static HRESULT ShellLink_UpdatePath(LPCWSTR sPathRel, LPCWSTR path, LPCWSTR sWorkDir, LPWSTR* psPath); @@ -145,44 +108,49 @@ static LPWSTR __inline strdupW(LPCWSTR src) CShellLink::CShellLink() { - pPidl = NULL; wHotKey = 0; memset(&time1, 0, sizeof(time1)); memset(&time2, 0, sizeof(time2)); memset(&time3, 0, sizeof(time3)); iShowCmd = SW_SHOWNORMAL; - sIcoPath = NULL; iIcoNdx = 0; - sPath = NULL; - sArgs = NULL; - sWorkDir = NULL; - sDescription = NULL; - sPathRel = NULL; - sProduct = NULL; - sComponent = NULL; - memset(&volume, 0, sizeof(volume)); - sLinkPath = NULL; - bRunAs = FALSE; - bDirty = FALSE; - iIdOpen = -1; + + m_pPidl = NULL; + + m_sPath = NULL; + ZeroMemory(&volume, sizeof(volume)); + + m_sDescription = NULL; + m_sPathRel = NULL; + m_sWorkDir = NULL; + m_sArgs = NULL; + m_sIcoPath = NULL; + m_bRunAs = FALSE; + m_bDirty = FALSE; + + m_sLinkPath = NULL; + m_iIdOpen = -1; + + /**/sProduct = sComponent = NULL;/**/ } CShellLink::~CShellLink() { TRACE("-- destroying IShellLink(%p)\n", this); - HeapFree(GetProcessHeap(), 0, sIcoPath); - HeapFree(GetProcessHeap(), 0, sArgs); - HeapFree(GetProcessHeap(), 0, sWorkDir); - HeapFree(GetProcessHeap(), 0, sDescription); - HeapFree(GetProcessHeap(), 0, sPath); - HeapFree(GetProcessHeap(), 0, sLinkPath); + ILFree(m_pPidl); - if (pPidl) - ILFree(pPidl); + HeapFree(GetProcessHeap(), 0, m_sPath); + + HeapFree(GetProcessHeap(), 0, m_sDescription); + HeapFree(GetProcessHeap(), 0, m_sPathRel); + HeapFree(GetProcessHeap(), 0, m_sWorkDir); + HeapFree(GetProcessHeap(), 0, m_sArgs); + HeapFree(GetProcessHeap(), 0, m_sIcoPath); + HeapFree(GetProcessHeap(), 0, m_sLinkPath); } -HRESULT WINAPI CShellLink::GetClassID(CLSID *pclsid) +HRESULT STDMETHODCALLTYPE CShellLink::GetClassID(CLSID *pclsid) { TRACE("%p %p\n", this, pclsid); @@ -192,17 +160,16 @@ HRESULT WINAPI CShellLink::GetClassID(CLSID *pclsid) return S_OK; } -HRESULT WINAPI CShellLink::IsDirty() +/************************************************************************ + * IPersistStream_IsDirty (IPersistStream) + */ +HRESULT STDMETHODCALLTYPE CShellLink::IsDirty() { TRACE("(%p)\n", this); - - if (bDirty) - return S_OK; - - return S_FALSE; + return (m_bDirty ? S_OK : S_FALSE); } -HRESULT WINAPI CShellLink::Load(LPCOLESTR pszFileName, DWORD dwMode) +HRESULT STDMETHODCALLTYPE CShellLink::Load(LPCOLESTR pszFileName, DWORD dwMode) { TRACE("(%p, %s, %x)\n", this, debugstr_w(pszFileName), dwMode); @@ -213,17 +180,17 @@ HRESULT WINAPI CShellLink::Load(LPCOLESTR pszFileName, DWORD dwMode) HRESULT hr = SHCreateStreamOnFileW(pszFileName, dwMode, &stm); if (SUCCEEDED(hr)) { - HeapFree(GetProcessHeap(), 0, sLinkPath); - sLinkPath = strdupW(pszFileName); + HeapFree(GetProcessHeap(), 0, m_sLinkPath); + m_sLinkPath = strdupW(pszFileName); hr = Load(stm); - ShellLink_UpdatePath(sPathRel, pszFileName, sWorkDir, &sPath); - bDirty = FALSE; + ShellLink_UpdatePath(m_sPathRel, pszFileName, m_sWorkDir, &m_sPath); + m_bDirty = FALSE; } TRACE("-- returning hr %08x\n", hr); return hr; } -HRESULT WINAPI CShellLink::Save(LPCOLESTR pszFileName, BOOL fRemember) +HRESULT STDMETHODCALLTYPE CShellLink::Save(LPCOLESTR pszFileName, BOOL fRemember) { TRACE("(%p)->(%s)\n", this, debugstr_w(pszFileName)); @@ -238,14 +205,14 @@ HRESULT WINAPI CShellLink::Save(LPCOLESTR pszFileName, BOOL fRemember) if (SUCCEEDED(hr)) { - if (sLinkPath) - HeapFree(GetProcessHeap(), 0, sLinkPath); + if (m_sLinkPath) + HeapFree(GetProcessHeap(), 0, m_sLinkPath); - sLinkPath = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (wcslen(pszFileName) + 1) * sizeof(WCHAR)); - if (sLinkPath) - wcscpy(sLinkPath, pszFileName); + m_sLinkPath = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (wcslen(pszFileName) + 1) * sizeof(WCHAR)); + if (m_sLinkPath) + wcscpy(m_sLinkPath, pszFileName); - bDirty = FALSE; + m_bDirty = FALSE; } else { @@ -257,23 +224,23 @@ HRESULT WINAPI CShellLink::Save(LPCOLESTR pszFileName, BOOL fRemember) return hr; } -HRESULT WINAPI CShellLink::SaveCompleted(LPCOLESTR pszFileName) +HRESULT STDMETHODCALLTYPE CShellLink::SaveCompleted(LPCOLESTR pszFileName) { FIXME("(%p)->(%s)\n", this, debugstr_w(pszFileName)); return S_OK; } -HRESULT WINAPI CShellLink::GetCurFile(LPOLESTR *ppszFileName) +HRESULT STDMETHODCALLTYPE CShellLink::GetCurFile(LPOLESTR *ppszFileName) { *ppszFileName = NULL; - if (!sLinkPath) + if (!m_sLinkPath) { /* IPersistFile::GetCurFile called before IPersistFile::Save */ return S_FALSE; } - *ppszFileName = (LPOLESTR)CoTaskMemAlloc((wcslen(sLinkPath) + 1) * sizeof(WCHAR)); + *ppszFileName = (LPOLESTR)CoTaskMemAlloc((wcslen(m_sLinkPath) + 1) * sizeof(WCHAR)); if (!*ppszFileName) { /* out of memory */ @@ -281,15 +248,11 @@ HRESULT WINAPI CShellLink::GetCurFile(LPOLESTR *ppszFileName) } /* copy last saved filename */ - wcscpy(*ppszFileName, sLinkPath); + wcscpy(*ppszFileName, m_sLinkPath); return S_OK; } -/************************************************************************ - * IPersistStream_IsDirty (IPersistStream) - */ - static HRESULT Stream_LoadString(IStream* stm, BOOL unicode, LPWSTR *pstr) { TRACE("%p\n", stm); @@ -301,7 +264,7 @@ static HRESULT Stream_LoadString(IStream* stm, BOOL unicode, LPWSTR *pstr) return E_FAIL; if (unicode) - len *= sizeof (WCHAR); + len *= sizeof(WCHAR); TRACE("reading %d\n", len); LPSTR temp = (LPSTR)HeapAlloc(GetProcessHeap(), 0, len + sizeof(WCHAR)); @@ -309,7 +272,7 @@ static HRESULT Stream_LoadString(IStream* stm, BOOL unicode, LPWSTR *pstr) return E_OUTOFMEMORY; count = 0; hr = stm->Read(temp, len, &count); - if(FAILED(hr) || count != len) + if (FAILED(hr) || count != len) { HeapFree(GetProcessHeap(), 0, temp); return E_FAIL; @@ -322,7 +285,7 @@ static HRESULT Stream_LoadString(IStream* stm, BOOL unicode, LPWSTR *pstr) if (!unicode) { count = MultiByteToWideChar(CP_ACP, 0, temp, len, NULL, 0); - str = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (count + 1) * sizeof (WCHAR)); + str = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (count + 1) * sizeof(WCHAR)); if (!str) { HeapFree(GetProcessHeap(), 0, temp); @@ -333,7 +296,7 @@ static HRESULT Stream_LoadString(IStream* stm, BOOL unicode, LPWSTR *pstr) } else { - count /= 2; + count /= sizeof(WCHAR); str = (LPWSTR)temp; } str[count] = 0; @@ -343,6 +306,21 @@ static HRESULT Stream_LoadString(IStream* stm, BOOL unicode, LPWSTR *pstr) return S_OK; } + +/* + * NOTE: The following 5 functions are part of LINKINFO.DLL + */ +static BOOL ShellLink_GetVolumeInfo(LPCWSTR path, CShellLink::volume_info *volume) +{ + WCHAR drive[4] = { path[0], ':', '\\', 0 }; + + volume->type = GetDriveTypeW(drive); + BOOL bRet = GetVolumeInformationW(drive, volume->label, _countof(volume->label), &volume->serial, NULL, NULL, NULL, 0); + TRACE("ret = %d type %d serial %08x name %s\n", bRet, + volume->type, volume->serial, debugstr_w(volume->label)); + return bRet; +} + static HRESULT Stream_ReadChunk(IStream* stm, LPVOID *data) { struct sized_chunk @@ -414,7 +392,7 @@ static LPWSTR Stream_LoadPath(LPCSTR p, DWORD maxlen) } static HRESULT Stream_LoadLocation(IStream *stm, - CShellLink::volume_info *volume, LPWSTR *path) + CShellLink::volume_info *volume, LPWSTR *path) { char *p = NULL; HRESULT hr = Stream_ReadChunk(stm, (LPVOID*) &p); @@ -462,7 +440,7 @@ static HRESULT Stream_LoadLocation(IStream *stm, * 8+0x104 string data in UNICODE * * In the original Win32 implementation the buffers are not initialized - * to zero, so data trailing the string is random garbage. + * to zero, so data trailing the string is random garbage. */ static HRESULT Stream_LoadAdvertiseInfo(IStream* stm, LPWSTR *str) { @@ -507,7 +485,7 @@ static HRESULT Stream_LoadAdvertiseInfo(IStream* stm, LPWSTR *str) /************************************************************************ * IPersistStream_Load (IPersistStream) */ -HRESULT WINAPI CShellLink::Load(IStream *stm) +HRESULT STDMETHODCALLTYPE CShellLink::Load(IStream *stm) { TRACE("%p %p\n", this, stm); @@ -528,21 +506,21 @@ HRESULT WINAPI CShellLink::Load(IStream *stm) return E_FAIL; /* free all the old stuff */ - ILFree(pPidl); - pPidl = NULL; + ILFree(m_pPidl); + m_pPidl = NULL; memset(&volume, 0, sizeof volume); - HeapFree(GetProcessHeap(), 0, sPath); - sPath = NULL; - HeapFree(GetProcessHeap(), 0, sDescription); - sDescription = NULL; - HeapFree(GetProcessHeap(), 0, sPathRel); - sPathRel = NULL; - HeapFree(GetProcessHeap(), 0, sWorkDir); - sWorkDir = NULL; - HeapFree(GetProcessHeap(), 0, sArgs); - sArgs = NULL; - HeapFree(GetProcessHeap(), 0, sIcoPath); - sIcoPath = NULL; + HeapFree(GetProcessHeap(), 0, m_sPath); + m_sPath = NULL; + HeapFree(GetProcessHeap(), 0, m_sDescription); + m_sDescription = NULL; + HeapFree(GetProcessHeap(), 0, m_sPathRel); + m_sPathRel = NULL; + HeapFree(GetProcessHeap(), 0, m_sWorkDir); + m_sWorkDir = NULL; + HeapFree(GetProcessHeap(), 0, m_sArgs); + m_sArgs = NULL; + HeapFree(GetProcessHeap(), 0, m_sIcoPath); + m_sIcoPath = NULL; HeapFree(GetProcessHeap(), 0, sProduct); sProduct = NULL; HeapFree(GetProcessHeap(), 0, sComponent); @@ -572,15 +550,15 @@ HRESULT WINAPI CShellLink::Load(IStream *stm) /* load all the new stuff */ if (ShlLnkHeader.dwFlags & SLDF_HAS_ID_LIST) { - hr = ILLoadFromStream(stm, &pPidl); + hr = ILLoadFromStream(stm, &m_pPidl); if (FAILED(hr)) return hr; } - pdump(pPidl); + pdump(m_pPidl); /* load the location information */ if (ShlLnkHeader.dwFlags & SLDF_HAS_LINK_INFO) - hr = Stream_LoadLocation(stm, &volume, &sPath); + hr = Stream_LoadLocation(stm, &volume, &m_sPath); if (FAILED(hr)) goto end; @@ -589,41 +567,41 @@ HRESULT WINAPI CShellLink::Load(IStream *stm) if (ShlLnkHeader.dwFlags & SLDF_HAS_NAME) { - hr = Stream_LoadString(stm, unicode, &sDescription); - TRACE("Description -> %s\n", debugstr_w(sDescription)); + hr = Stream_LoadString(stm, unicode, &m_sDescription); + TRACE("Description -> %s\n", debugstr_w(m_sDescription)); } if (FAILED(hr)) goto end; if (ShlLnkHeader.dwFlags & SLDF_HAS_RELPATH) { - hr = Stream_LoadString(stm, unicode, &sPathRel); - TRACE("Relative Path-> %s\n", debugstr_w(sPathRel)); + hr = Stream_LoadString(stm, unicode, &m_sPathRel); + TRACE("Relative Path-> %s\n", debugstr_w(m_sPathRel)); } if (FAILED(hr)) goto end; if (ShlLnkHeader.dwFlags & SLDF_HAS_WORKINGDIR) { - hr = Stream_LoadString(stm, unicode, &sWorkDir); - PathRemoveBackslash(sWorkDir); - TRACE("Working Dir -> %s\n", debugstr_w(sWorkDir)); + hr = Stream_LoadString(stm, unicode, &m_sWorkDir); + PathRemoveBackslash(m_sWorkDir); + TRACE("Working Dir -> %s\n", debugstr_w(m_sWorkDir)); } if (FAILED(hr)) goto end; if (ShlLnkHeader.dwFlags & SLDF_HAS_ARGS) { - hr = Stream_LoadString(stm, unicode, &sArgs); - TRACE("Arguments -> %s\n", debugstr_w(sArgs)); + hr = Stream_LoadString(stm, unicode, &m_sArgs); + TRACE("Arguments -> %s\n", debugstr_w(m_sArgs)); } if (FAILED(hr)) goto end; if (ShlLnkHeader.dwFlags & SLDF_HAS_ICONLOCATION) { - hr = Stream_LoadString(stm, unicode, &sIcoPath); - TRACE("Icon file -> %s\n", debugstr_w(sIcoPath)); + hr = Stream_LoadString(stm, unicode, &m_sIcoPath); + TRACE("Icon file -> %s\n", debugstr_w(m_sIcoPath)); } if (FAILED(hr)) goto end; @@ -645,11 +623,11 @@ HRESULT WINAPI CShellLink::Load(IStream *stm) } if (ShlLnkHeader.dwFlags & SLDF_RUNAS_USER) { - bRunAs = TRUE; + m_bRunAs = TRUE; } else { - bRunAs = FALSE; + m_bRunAs = FALSE; } if (FAILED(hr)) @@ -662,7 +640,7 @@ HRESULT WINAPI CShellLink::Load(IStream *stm) TRACE("OK\n"); - pdump (pPidl); + pdump(m_pPidl); return S_OK; @@ -729,25 +707,25 @@ static HRESULT Stream_WriteLocationInfo(IStream* stm, LPCWSTR path, /* fill in the location information header */ loc->dwTotalSize = total_size; - loc->dwHeaderSize = sizeof (*loc); + loc->dwHeaderSize = sizeof(*loc); loc->dwFlags = 1; - loc->dwVolTableOfs = sizeof (*loc); - loc->dwLocalPathOfs = sizeof (*loc) + volume_info_size; + loc->dwVolTableOfs = sizeof(*loc); + loc->dwLocalPathOfs = sizeof(*loc) + volume_info_size; loc->dwNetworkVolTableOfs = 0; - loc->dwFinalPathOfs = sizeof (*loc) + volume_info_size + path_size; + loc->dwFinalPathOfs = sizeof(*loc) + volume_info_size + path_size; /* fill in the volume information */ vol->dwSize = volume_info_size; vol->dwType = volume->type; vol->dwVolSerial = volume->serial; - vol->dwVolLabelOfs = sizeof (*vol); + vol->dwVolLabelOfs = sizeof(*vol); /* copy in the strings */ WideCharToMultiByte(CP_ACP, 0, volume->label, -1, szLabel, label_size, NULL, NULL); WideCharToMultiByte(CP_ACP, 0, path, -1, szPath, path_size, NULL, NULL); - szFinalPath[0] = 0; + *szFinalPath = 0; ULONG count = 0; HRESULT hr = stm->Write(loc, total_size, &count); @@ -782,7 +760,7 @@ static HRESULT Stream_WriteAdvertiseInfo(IStream* stm, LPCWSTR string, DWORD mag * * FIXME: makes assumptions about byte order */ -HRESULT WINAPI CShellLink::Save(IStream *stm, BOOL fClearDirty) +HRESULT STDMETHODCALLTYPE CShellLink::Save(IStream *stm, BOOL fClearDirty) { TRACE("%p %p %x\n", this, stm, fClearDirty); @@ -795,17 +773,17 @@ HRESULT WINAPI CShellLink::Save(IStream *stm, BOOL fClearDirty) ShlLnkHeader.wHotKey = wHotKey; ShlLnkHeader.nIconIndex = iIcoNdx; ShlLnkHeader.dwFlags = SLDF_UNICODE; /* strings are in unicode */ - if (pPidl) + if (m_pPidl) ShlLnkHeader.dwFlags |= SLDF_HAS_ID_LIST; - if (sPath) + if (m_sPath) ShlLnkHeader.dwFlags |= SLDF_HAS_LINK_INFO; - if (sDescription) + if (m_sDescription) ShlLnkHeader.dwFlags |= SLDF_HAS_NAME; - if (sWorkDir) + if (m_sWorkDir) ShlLnkHeader.dwFlags |= SLDF_HAS_WORKINGDIR; - if (sArgs) + if (m_sArgs) ShlLnkHeader.dwFlags |= SLDF_HAS_ARGS; - if (sIcoPath) + if (m_sIcoPath) ShlLnkHeader.dwFlags |= SLDF_HAS_ICONLOCATION; #if (NTDDI_VERSION < NTDDI_LONGHORN) if (sProduct) @@ -813,7 +791,7 @@ HRESULT WINAPI CShellLink::Save(IStream *stm, BOOL fClearDirty) #endif if (sComponent) ShlLnkHeader.dwFlags |= SLDF_HAS_DARWINID; - if (bRunAs) + if (m_bRunAs) ShlLnkHeader.dwFlags |= SLDF_RUNAS_USER; SystemTimeToFileTime (&time1, &ShlLnkHeader.ftCreationTime); @@ -832,9 +810,9 @@ HRESULT WINAPI CShellLink::Save(IStream *stm, BOOL fClearDirty) TRACE("Writing pidl\n"); /* write the PIDL to the shortcut */ - if (pPidl) + if (m_pPidl) { - hr = ILSaveToStream(stm, pPidl); + hr = ILSaveToStream(stm, m_pPidl); if (FAILED(hr)) { ERR("Failed to write PIDL\n"); @@ -842,23 +820,23 @@ HRESULT WINAPI CShellLink::Save(IStream *stm, BOOL fClearDirty) } } - if (sPath) - Stream_WriteLocationInfo(stm, sPath, &volume); + if (m_sPath) + Stream_WriteLocationInfo(stm, m_sPath, &volume); - if (sDescription) - hr = Stream_WriteString(stm, sDescription); + if (m_sDescription) + hr = Stream_WriteString(stm, m_sDescription); - if (sPathRel) - hr = Stream_WriteString(stm, sPathRel); + if (m_sPathRel) + hr = Stream_WriteString(stm, m_sPathRel); - if (sWorkDir) - hr = Stream_WriteString(stm, sWorkDir); + if (m_sWorkDir) + hr = Stream_WriteString(stm, m_sWorkDir); - if (sArgs) - hr = Stream_WriteString(stm, sArgs); + if (m_sArgs) + hr = Stream_WriteString(stm, m_sArgs); - if (sIcoPath) - hr = Stream_WriteString(stm, sIcoPath); + if (m_sIcoPath) + hr = Stream_WriteString(stm, m_sIcoPath); if (sProduct) hr = Stream_WriteAdvertiseInfo(stm, sProduct, EXP_SZ_ICON_SIG); @@ -876,10 +854,9 @@ HRESULT WINAPI CShellLink::Save(IStream *stm, BOOL fClearDirty) /************************************************************************ * IPersistStream_GetSizeMax (IPersistStream) */ -HRESULT WINAPI CShellLink::GetSizeMax(ULARGE_INTEGER *pcbSize) +HRESULT STDMETHODCALLTYPE CShellLink::GetSizeMax(ULARGE_INTEGER *pcbSize) { TRACE("(%p)\n", this); - return E_NOTIMPL; } @@ -947,10 +924,10 @@ static HRESULT ShellLink_UpdatePath(LPCWSTR sPathRel, LPCWSTR path, LPCWSTR sWor return S_OK; } -HRESULT WINAPI CShellLink::GetPath(LPSTR pszFile, INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags) +HRESULT STDMETHODCALLTYPE CShellLink::GetPath(LPSTR pszFile, INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags) { TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n", - this, pszFile, cchMaxPath, pfd, fFlags, debugstr_w(sPath)); + this, pszFile, cchMaxPath, pfd, fFlags, debugstr_w(m_sPath)); if (sComponent || sProduct) return S_FALSE; @@ -958,8 +935,8 @@ HRESULT WINAPI CShellLink::GetPath(LPSTR pszFile, INT cchMaxPath, WIN32_FIND_DAT if (cchMaxPath) pszFile[0] = 0; - if (sPath) - WideCharToMultiByte(CP_ACP, 0, sPath, -1, + if (m_sPath) + WideCharToMultiByte(CP_ACP, 0, m_sPath, -1, pszFile, cchMaxPath, NULL, NULL); if (pfd) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", this); @@ -967,275 +944,229 @@ HRESULT WINAPI CShellLink::GetPath(LPSTR pszFile, INT cchMaxPath, WIN32_FIND_DAT return S_OK; } -HRESULT WINAPI CShellLink::GetIDList(LPITEMIDLIST * ppidl) +HRESULT STDMETHODCALLTYPE CShellLink::GetIDList(LPITEMIDLIST *ppidl) { TRACE("(%p)->(ppidl=%p)\n", this, ppidl); - if (!pPidl) + if (!m_pPidl) { *ppidl = NULL; return S_FALSE; } - *ppidl = ILClone(pPidl); + *ppidl = ILClone(m_pPidl); return S_OK; } -HRESULT WINAPI CShellLink::SetIDList(LPCITEMIDLIST pidl) +HRESULT STDMETHODCALLTYPE CShellLink::SetIDList(LPCITEMIDLIST pidl) { TRACE("(%p)->(pidl=%p)\n", this, pidl); - if (pPidl) - ILFree(pPidl); + if (m_pPidl) + ILFree(m_pPidl); - pPidl = ILClone(pidl); - if (!pPidl) + m_pPidl = ILClone(pidl); + if (!m_pPidl) return E_FAIL; - bDirty = TRUE; + m_bDirty = TRUE; return S_OK; } -HRESULT WINAPI CShellLink::GetDescription(LPSTR pszName, INT cchMaxName) +HRESULT STDMETHODCALLTYPE CShellLink::GetDescription(LPSTR pszName, INT cchMaxName) { TRACE("(%p)->(%p len=%u)\n", this, pszName, cchMaxName); if (cchMaxName) - pszName[0] = 0; + *pszName = 0; - if (sDescription) - WideCharToMultiByte(CP_ACP, 0, sDescription, -1, + if (m_sDescription) + WideCharToMultiByte(CP_ACP, 0, m_sDescription, -1, pszName, cchMaxName, NULL, NULL); return S_OK; } -HRESULT WINAPI CShellLink::SetDescription(LPCSTR pszName) +HRESULT STDMETHODCALLTYPE CShellLink::SetDescription(LPCSTR pszName) { TRACE("(%p)->(pName=%s)\n", this, pszName); - HeapFree(GetProcessHeap(), 0, sDescription); - sDescription = NULL; + HeapFree(GetProcessHeap(), 0, m_sDescription); + m_sDescription = NULL; if (pszName) { - sDescription = HEAP_strdupAtoW(GetProcessHeap(), 0, pszName); - if (!sDescription) + m_sDescription = HEAP_strdupAtoW(GetProcessHeap(), 0, pszName); + if (!m_sDescription) return E_OUTOFMEMORY; } - bDirty = TRUE; + m_bDirty = TRUE; return S_OK; } -HRESULT WINAPI CShellLink::GetWorkingDirectory(LPSTR pszDir, INT cchMaxPath) +HRESULT STDMETHODCALLTYPE CShellLink::GetWorkingDirectory(LPSTR pszDir, INT cchMaxPath) { TRACE("(%p)->(%p len=%u)\n", this, pszDir, cchMaxPath); if (cchMaxPath) - pszDir[0] = 0; + *pszDir = 0; - if (sWorkDir) - WideCharToMultiByte(CP_ACP, 0, sWorkDir, -1, + if (m_sWorkDir) + WideCharToMultiByte(CP_ACP, 0, m_sWorkDir, -1, pszDir, cchMaxPath, NULL, NULL); return S_OK; } -HRESULT WINAPI CShellLink::SetWorkingDirectory(LPCSTR pszDir) +HRESULT STDMETHODCALLTYPE CShellLink::SetWorkingDirectory(LPCSTR pszDir) { TRACE("(%p)->(dir=%s)\n", this, pszDir); - HeapFree(GetProcessHeap(), 0, sWorkDir); - sWorkDir = NULL; + HeapFree(GetProcessHeap(), 0, m_sWorkDir); + m_sWorkDir = NULL; if (pszDir) { - sWorkDir = HEAP_strdupAtoW(GetProcessHeap(), 0, pszDir); - if (!sWorkDir) + m_sWorkDir = HEAP_strdupAtoW(GetProcessHeap(), 0, pszDir); + if (!m_sWorkDir) return E_OUTOFMEMORY; } - bDirty = TRUE; + m_bDirty = TRUE; return S_OK; } -HRESULT WINAPI CShellLink::GetArguments(LPSTR pszArgs, INT cchMaxPath) +HRESULT STDMETHODCALLTYPE CShellLink::GetArguments(LPSTR pszArgs, INT cchMaxPath) { TRACE("(%p)->(%p len=%u)\n", this, pszArgs, cchMaxPath); if (cchMaxPath) - pszArgs[0] = 0; - if (sArgs) - WideCharToMultiByte(CP_ACP, 0, sArgs, -1, + *pszArgs = 0; + + if (m_sArgs) + WideCharToMultiByte(CP_ACP, 0, m_sArgs, -1, pszArgs, cchMaxPath, NULL, NULL); return S_OK; } -HRESULT WINAPI CShellLink::SetArguments(LPCSTR pszArgs) +HRESULT STDMETHODCALLTYPE CShellLink::SetArguments(LPCSTR pszArgs) { TRACE("(%p)->(args=%s)\n", this, pszArgs); - HeapFree(GetProcessHeap(), 0, sArgs); - sArgs = NULL; + HeapFree(GetProcessHeap(), 0, m_sArgs); + m_sArgs = NULL; if (pszArgs) { - sArgs = HEAP_strdupAtoW(GetProcessHeap(), 0, pszArgs); - if (!sArgs) + m_sArgs = HEAP_strdupAtoW(GetProcessHeap(), 0, pszArgs); + if (!m_sArgs) return E_OUTOFMEMORY; } - bDirty = TRUE; + m_bDirty = TRUE; return S_OK; } -HRESULT WINAPI CShellLink::GetHotkey(WORD *pwHotkey) +HRESULT STDMETHODCALLTYPE CShellLink::GetHotkey(WORD *pwHotkey) { TRACE("(%p)->(%p)(0x%08x)\n", this, pwHotkey, wHotKey); - *pwHotkey = wHotKey; - return S_OK; } -HRESULT WINAPI CShellLink::SetHotkey(WORD wHotkey) +HRESULT STDMETHODCALLTYPE CShellLink::SetHotkey(WORD wHotkey) { TRACE("(%p)->(hotkey=%x)\n", this, wHotkey); wHotKey = wHotkey; - bDirty = TRUE; + m_bDirty = TRUE; return S_OK; } -HRESULT WINAPI CShellLink::GetShowCmd(INT *piShowCmd) +HRESULT STDMETHODCALLTYPE CShellLink::GetShowCmd(INT *piShowCmd) { - TRACE("(%p)->(%p)\n", this, piShowCmd); + TRACE("(%p)->(%p) %d\n", this, piShowCmd, iShowCmd); *piShowCmd = iShowCmd; return S_OK; } -HRESULT WINAPI CShellLink::SetShowCmd(INT iShowCmd) +HRESULT STDMETHODCALLTYPE CShellLink::SetShowCmd(INT iShowCmd) { TRACE("(%p) %d\n", this, iShowCmd); this->iShowCmd = iShowCmd; - bDirty = TRUE; + m_bDirty = TRUE; return S_OK; } -static HRESULT SHELL_PidlGeticonLocationA(IShellFolder* psf, LPCITEMIDLIST pidl, - LPSTR pszIconPath, int cchIconPath, int* piIcon) +HRESULT STDMETHODCALLTYPE CShellLink::GetIconLocation(LPSTR pszIconPath, INT cchIconPath, INT *piIcon) { - LPCITEMIDLIST pidlLast; + HRESULT hr; + LPWSTR pszIconPathW; - HRESULT hr = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &psf), &pidlLast); + TRACE("(%p)->(%p len=%u iicon=%p)\n", this, pszIconPath, cchIconPath, piIcon); - if (SUCCEEDED(hr)) - { - CComPtr pei; + /* Allocate a temporary UNICODE buffer */ + pszIconPathW = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, cchIconPath * sizeof(WCHAR)); + if (!pszIconPathW) + return E_OUTOFMEMORY; - hr = psf->GetUIObjectOf(0, 1, &pidlLast, IID_NULL_PPV_ARG(IExtractIconA, &pei)); + /* Call the UNICODE function */ + hr = GetIconLocation(pszIconPathW, cchIconPath, piIcon); - if (SUCCEEDED(hr)) - hr = pei->GetIconLocation(0, pszIconPath, MAX_PATH, piIcon, NULL); + /* Convert the file path back to ANSI */ + WideCharToMultiByte(CP_ACP, 0, pszIconPathW, -1, + pszIconPath, cchIconPath, NULL, NULL); - psf->Release(); - } + /* Free the temporary buffer */ + HeapFree(GetProcessHeap(), 0, pszIconPathW); return hr; } -HRESULT WINAPI CShellLink::GetIconLocation(LPSTR pszIconPath, INT cchIconPath, INT *piIcon) -{ - TRACE("(%p)->(%p len=%u iicon=%p)\n", this, pszIconPath, cchIconPath, piIcon); - - pszIconPath[0] = 0; - *piIcon = iIcoNdx; - - if (sIcoPath) - { - WideCharToMultiByte(CP_ACP, 0, sIcoPath, -1, pszIconPath, cchIconPath, NULL, NULL); - return S_OK; - } - - if (pPidl || sPath) - { - CComPtr pdsk; - - HRESULT hr = SHGetDesktopFolder(&pdsk); - - if (SUCCEEDED(hr)) - { - /* first look for an icon using the PIDL (if present) */ - if (pPidl) - hr = SHELL_PidlGeticonLocationA(pdsk, pPidl, pszIconPath, cchIconPath, piIcon); - else - hr = E_FAIL; - - /* if we couldn't find an icon yet, look for it using the file system path */ - if (FAILED(hr) && sPath) - { - LPITEMIDLIST pidl; - - hr = pdsk->ParseDisplayName(0, NULL, sPath, NULL, &pidl, NULL); - - if (SUCCEEDED(hr)) - { - hr = SHELL_PidlGeticonLocationA(pdsk, pidl, pszIconPath, cchIconPath, piIcon); - - SHFree(pidl); - } - } - } - - return hr; - } - return S_OK; -} - -HRESULT WINAPI CShellLink::SetIconLocation(LPCSTR pszIconPath, INT iIcon) +HRESULT STDMETHODCALLTYPE CShellLink::SetIconLocation(LPCSTR pszIconPath, INT iIcon) { TRACE("(%p)->(path=%s iicon=%u)\n", this, pszIconPath, iIcon); - HeapFree(GetProcessHeap(), 0, sIcoPath); - sIcoPath = NULL; + HeapFree(GetProcessHeap(), 0, m_sIcoPath); + m_sIcoPath = NULL; if (pszIconPath) { - sIcoPath = HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath); - if (!sIcoPath) + m_sIcoPath = HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath); + if (!m_sIcoPath) return E_OUTOFMEMORY; } iIcoNdx = iIcon; - bDirty = TRUE; + m_bDirty = TRUE; return S_OK; } -HRESULT WINAPI CShellLink::SetRelativePath(LPCSTR pszPathRel, DWORD dwReserved) +HRESULT STDMETHODCALLTYPE CShellLink::SetRelativePath(LPCSTR pszPathRel, DWORD dwReserved) { TRACE("(%p)->(path=%s %x)\n", this, pszPathRel, dwReserved); - HeapFree(GetProcessHeap(), 0, sPathRel); - sPathRel = NULL; + HeapFree(GetProcessHeap(), 0, m_sPathRel); + m_sPathRel = NULL; if (pszPathRel) { - sPathRel = HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel); - bDirty = TRUE; + m_sPathRel = HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel); + m_bDirty = TRUE; } - return ShellLink_UpdatePath(sPathRel, sPath, sWorkDir, &sPath); + return ShellLink_UpdatePath(m_sPathRel, m_sPath, m_sWorkDir, &m_sPath); } -HRESULT WINAPI CShellLink::Resolve(HWND hwnd, DWORD fFlags) +HRESULT STDMETHODCALLTYPE CShellLink::Resolve(HWND hwnd, DWORD fFlags) { HRESULT hr = S_OK; BOOL bSuccess; @@ -1244,47 +1175,48 @@ HRESULT WINAPI CShellLink::Resolve(HWND hwnd, DWORD fFlags) /*FIXME: use IResolveShellLink interface */ - if (!sPath && pPidl) + if (!m_sPath && m_pPidl) { WCHAR buffer[MAX_PATH]; - bSuccess = SHGetPathFromIDListW(pPidl, buffer); + bSuccess = SHGetPathFromIDListW(m_pPidl, buffer); if (bSuccess && *buffer) { - sPath = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (wcslen(buffer) + 1) * sizeof(WCHAR)); + m_sPath = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (wcslen(buffer) + 1) * sizeof(WCHAR)); - if (!sPath) + if (!m_sPath) return E_OUTOFMEMORY; - wcscpy(sPath, buffer); + wcscpy(m_sPath, buffer); - bDirty = TRUE; + m_bDirty = TRUE; } else hr = S_OK; /* don't report an error occurred while just caching information */ } - if (!sIcoPath && sPath) + if (!m_sIcoPath && m_sPath) { - sIcoPath = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (wcslen(sPath) + 1) * sizeof(WCHAR)); + m_sIcoPath = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (wcslen(m_sPath) + 1) * sizeof(WCHAR)); - if (!sIcoPath) + if (!m_sIcoPath) return E_OUTOFMEMORY; - wcscpy(sIcoPath, sPath); + wcscpy(m_sIcoPath, m_sPath); iIcoNdx = 0; - bDirty = TRUE; + m_bDirty = TRUE; } return hr; } -HRESULT WINAPI CShellLink::SetPath(LPCSTR pszFile) +HRESULT STDMETHODCALLTYPE CShellLink::SetPath(LPCSTR pszFile) { TRACE("(%p)->(path=%s)\n", this, pszFile); - if (pszFile == NULL) + + if (!pszFile) return E_INVALIDARG; LPWSTR str = HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile); @@ -1297,141 +1229,141 @@ HRESULT WINAPI CShellLink::SetPath(LPCSTR pszFile) return hr; } -HRESULT WINAPI CShellLink::GetPath(LPWSTR pszFile, INT cchMaxPath, WIN32_FIND_DATAW *pfd, DWORD fFlags) +HRESULT STDMETHODCALLTYPE CShellLink::GetPath(LPWSTR pszFile, INT cchMaxPath, WIN32_FIND_DATAW *pfd, DWORD fFlags) { TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n", - this, pszFile, cchMaxPath, pfd, fFlags, debugstr_w(sPath)); + this, pszFile, cchMaxPath, pfd, fFlags, debugstr_w(m_sPath)); if (sComponent || sProduct) return S_FALSE; if (cchMaxPath) - pszFile[0] = 0; + *pszFile = 0; - if (sPath) - lstrcpynW(pszFile, sPath, cchMaxPath); + if (m_sPath) + lstrcpynW(pszFile, m_sPath, cchMaxPath); if (pfd) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", this); return S_OK; } -HRESULT WINAPI CShellLink::GetDescription(LPWSTR pszName, INT cchMaxName) +HRESULT STDMETHODCALLTYPE CShellLink::GetDescription(LPWSTR pszName, INT cchMaxName) { TRACE("(%p)->(%p len=%u)\n", this, pszName, cchMaxName); - pszName[0] = 0; - if (sDescription) - lstrcpynW(pszName, sDescription, cchMaxName); + *pszName = 0; + if (m_sDescription) + lstrcpynW(pszName, m_sDescription, cchMaxName); return S_OK; } -HRESULT WINAPI CShellLink::SetDescription(LPCWSTR pszName) +HRESULT STDMETHODCALLTYPE CShellLink::SetDescription(LPCWSTR pszName) { TRACE("(%p)->(desc=%s)\n", this, debugstr_w(pszName)); - HeapFree(GetProcessHeap(), 0, sDescription); + HeapFree(GetProcessHeap(), 0, m_sDescription); if (pszName) { - sDescription = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, + m_sDescription = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (wcslen(pszName) + 1) * sizeof(WCHAR)); - if (!sDescription) + if (!m_sDescription) return E_OUTOFMEMORY; - wcscpy(sDescription, pszName); + wcscpy(m_sDescription, pszName); } else - sDescription = NULL; + m_sDescription = NULL; - bDirty = TRUE; + m_bDirty = TRUE; return S_OK; } -HRESULT WINAPI CShellLink::GetWorkingDirectory(LPWSTR pszDir, INT cchMaxPath) +HRESULT STDMETHODCALLTYPE CShellLink::GetWorkingDirectory(LPWSTR pszDir, INT cchMaxPath) { TRACE("(%p)->(%p len %u)\n", this, pszDir, cchMaxPath); if (cchMaxPath) - pszDir[0] = 0; - if (sWorkDir) - lstrcpynW(pszDir, sWorkDir, cchMaxPath); + *pszDir = 0; + + if (m_sWorkDir) + lstrcpynW(pszDir, m_sWorkDir, cchMaxPath); return S_OK; } -HRESULT WINAPI CShellLink::SetWorkingDirectory(LPCWSTR pszDir) +HRESULT STDMETHODCALLTYPE CShellLink::SetWorkingDirectory(LPCWSTR pszDir) { TRACE("(%p)->(dir=%s)\n", this, debugstr_w(pszDir)); - HeapFree(GetProcessHeap(), 0, sWorkDir); + HeapFree(GetProcessHeap(), 0, m_sWorkDir); if (pszDir) { - sWorkDir = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, - (wcslen(pszDir) + 1) * sizeof (WCHAR)); - if (!sWorkDir) + m_sWorkDir = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, + (wcslen(pszDir) + 1) * sizeof(WCHAR)); + if (!m_sWorkDir) return E_OUTOFMEMORY; - wcscpy(sWorkDir, pszDir); + wcscpy(m_sWorkDir, pszDir); } else - sWorkDir = NULL; + m_sWorkDir = NULL; - bDirty = TRUE; + m_bDirty = TRUE; return S_OK; } -HRESULT WINAPI CShellLink::GetArguments(LPWSTR pszArgs, INT cchMaxPath) +HRESULT STDMETHODCALLTYPE CShellLink::GetArguments(LPWSTR pszArgs, INT cchMaxPath) { TRACE("(%p)->(%p len=%u)\n", this, pszArgs, cchMaxPath); if (cchMaxPath) - pszArgs[0] = 0; - if (sArgs) - lstrcpynW(pszArgs, sArgs, cchMaxPath); + *pszArgs = 0; + + if (m_sArgs) + lstrcpynW(pszArgs, m_sArgs, cchMaxPath); return S_OK; } -HRESULT WINAPI CShellLink::SetArguments(LPCWSTR pszArgs) +HRESULT STDMETHODCALLTYPE CShellLink::SetArguments(LPCWSTR pszArgs) { TRACE("(%p)->(args=%s)\n", this, debugstr_w(pszArgs)); - HeapFree(GetProcessHeap(), 0, sArgs); + HeapFree(GetProcessHeap(), 0, m_sArgs); if (pszArgs) { - sArgs = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, - (wcslen(pszArgs) + 1) * sizeof (WCHAR)); - if (!sArgs) + m_sArgs = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, + (wcslen(pszArgs) + 1) * sizeof(WCHAR)); + if (!m_sArgs) return E_OUTOFMEMORY; - wcscpy(sArgs, pszArgs); + wcscpy(m_sArgs, pszArgs); } else - sArgs = NULL; + m_sArgs = NULL; - bDirty = TRUE; + m_bDirty = TRUE; return S_OK; } -static HRESULT SHELL_PidlGeticonLocationW(IShellFolder* psf, LPCITEMIDLIST pidl, - LPWSTR pszIconPath, int cchIconPath, int* piIcon) +static HRESULT SHELL_PidlGetIconLocationW(IShellFolder* psf, LPCITEMIDLIST pidl, + PWSTR pszIconFile, UINT cchMax, int *piIndex) { LPCITEMIDLIST pidlLast; UINT wFlags; HRESULT hr = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &psf), &pidlLast); - if (SUCCEEDED(hr)) { CComPtr pei; hr = psf->GetUIObjectOf(0, 1, &pidlLast, IID_NULL_PPV_ARG(IExtractIconW, &pei)); - if (SUCCEEDED(hr)) - hr = pei->GetIconLocation(0, pszIconPath, MAX_PATH, piIcon, &wFlags); + hr = pei->GetIconLocation(0, pszIconFile, cchMax, piIndex, &wFlags); psf->Release(); } @@ -1439,20 +1371,22 @@ static HRESULT SHELL_PidlGeticonLocationW(IShellFolder* psf, LPCITEMIDLIST pidl, return hr; } -HRESULT WINAPI CShellLink::GetIconLocation(LPWSTR pszIconPath, INT cchIconPath, INT *piIcon) +HRESULT STDMETHODCALLTYPE CShellLink::GetIconLocation(LPWSTR pszIconPath, INT cchIconPath, INT *piIcon) { TRACE("(%p)->(%p len=%u iicon=%p)\n", this, pszIconPath, cchIconPath, piIcon); - pszIconPath[0] = 0; + if (cchIconPath) + *pszIconPath = 0; + *piIcon = iIcoNdx; - if (sIcoPath) + if (m_sIcoPath) { - lstrcpynW(pszIconPath, sIcoPath, cchIconPath); + lstrcpynW(pszIconPath, m_sIcoPath, cchIconPath); return S_OK; } - if (pPidl || sPath) + if (m_pPidl || m_sPath) { CComPtr pdsk; @@ -1461,21 +1395,21 @@ HRESULT WINAPI CShellLink::GetIconLocation(LPWSTR pszIconPath, INT cchIconPath, if (SUCCEEDED(hr)) { /* first look for an icon using the PIDL (if present) */ - if (pPidl) - hr = SHELL_PidlGeticonLocationW(pdsk, pPidl, pszIconPath, cchIconPath, piIcon); + if (m_pPidl) + hr = SHELL_PidlGetIconLocationW(pdsk, m_pPidl, pszIconPath, cchIconPath, piIcon); else hr = E_FAIL; /* if we couldn't find an icon yet, look for it using the file system path */ - if (FAILED(hr) && sPath) + if (FAILED(hr) && m_sPath) { LPITEMIDLIST pidl; - hr = pdsk->ParseDisplayName(0, NULL, sPath, NULL, &pidl, NULL); + hr = pdsk->ParseDisplayName(0, NULL, m_sPath, NULL, &pidl, NULL); if (SUCCEEDED(hr)) { - hr = SHELL_PidlGeticonLocationW(pdsk, pidl, pszIconPath, cchIconPath, piIcon); + hr = SHELL_PidlGetIconLocationW(pdsk, pidl, pszIconPath, cchIconPath, piIcon); SHFree(pidl); } @@ -1486,50 +1420,50 @@ HRESULT WINAPI CShellLink::GetIconLocation(LPWSTR pszIconPath, INT cchIconPath, return S_OK; } -HRESULT WINAPI CShellLink::SetIconLocation(LPCWSTR pszIconPath, INT iIcon) +HRESULT STDMETHODCALLTYPE CShellLink::SetIconLocation(LPCWSTR pszIconPath, INT iIcon) { TRACE("(%p)->(path=%s iicon=%u)\n", this, debugstr_w(pszIconPath), iIcon); - HeapFree(GetProcessHeap(), 0, sIcoPath); + HeapFree(GetProcessHeap(), 0, m_sIcoPath); if (pszIconPath) { - sIcoPath = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, + m_sIcoPath = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (wcslen(pszIconPath) + 1) * sizeof (WCHAR)); - if (!sIcoPath) + if (!m_sIcoPath) return E_OUTOFMEMORY; - wcscpy(sIcoPath, pszIconPath); + wcscpy(m_sIcoPath, pszIconPath); } else - sIcoPath = NULL; + m_sIcoPath = NULL; iIcoNdx = iIcon; - bDirty = TRUE; + m_bDirty = TRUE; return S_OK; } -HRESULT WINAPI CShellLink::SetRelativePath(LPCWSTR pszPathRel, DWORD dwReserved) +HRESULT STDMETHODCALLTYPE CShellLink::SetRelativePath(LPCWSTR pszPathRel, DWORD dwReserved) { TRACE("(%p)->(path=%s %x)\n", this, debugstr_w(pszPathRel), dwReserved); - HeapFree(GetProcessHeap(), 0, sPathRel); + HeapFree(GetProcessHeap(), 0, m_sPathRel); if (pszPathRel) { - sPathRel = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, - (wcslen(pszPathRel) + 1) * sizeof (WCHAR)); - if (!sPathRel) + m_sPathRel = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, + (wcslen(pszPathRel) + 1) * sizeof(WCHAR)); + if (!m_sPathRel) return E_OUTOFMEMORY; - wcscpy(sPathRel, pszPathRel); + wcscpy(m_sPathRel, pszPathRel); } else - sPathRel = NULL; + m_sPathRel = NULL; - bDirty = TRUE; + m_bDirty = TRUE; - return ShellLink_UpdatePath(sPathRel, sPath, sWorkDir, &sPath); + return ShellLink_UpdatePath(m_sPathRel, m_sPath, m_sWorkDir, &m_sPath); } -LPWSTR CShellLink::ShellLink_GetAdvertisedArg(LPCWSTR str) +static LPWSTR GetAdvertisedArg(LPCWSTR str) { if (!str) return NULL; @@ -1537,16 +1471,18 @@ LPWSTR CShellLink::ShellLink_GetAdvertisedArg(LPCWSTR str) LPCWSTR p = wcschr(str, L':'); if (!p) return NULL; + DWORD len = p - str; LPWSTR ret = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * (len + 1)); if (!ret) return ret; + memcpy(ret, str, sizeof(WCHAR)*len); ret[len] = 0; return ret; } -HRESULT CShellLink::ShellLink_SetAdvertiseInfo(LPCWSTR str) +HRESULT CShellLink::SetAdvertiseInfo(LPCWSTR str) { LPCWSTR szComponent = NULL, szProduct = NULL; @@ -1569,7 +1505,7 @@ HRESULT CShellLink::ShellLink_SetAdvertiseInfo(LPCWSTR str) if (len != 38) return E_FAIL; - /* get the guid, and check it's validly formatted */ + /* get the guid, and check if it's validly formatted */ WCHAR szGuid[39]; memcpy(szGuid, str, sizeof(WCHAR)*len); szGuid[len] = 0; @@ -1598,8 +1534,8 @@ HRESULT CShellLink::ShellLink_SetAdvertiseInfo(LPCWSTR str) if (!szComponent) return E_FAIL; - sComponent = ShellLink_GetAdvertisedArg(szComponent); - sProduct = ShellLink_GetAdvertisedArg(szProduct); + sComponent = GetAdvertisedArg(szComponent); + sProduct = GetAdvertisedArg(szProduct); TRACE("Component = %s\n", debugstr_w(sComponent)); TRACE("Product = %s\n", debugstr_w(sProduct)); @@ -1607,18 +1543,7 @@ HRESULT CShellLink::ShellLink_SetAdvertiseInfo(LPCWSTR str) return S_OK; } -static BOOL ShellLink_GetVolumeInfo(LPCWSTR path, CShellLink::volume_info *volume) -{ - WCHAR drive[4] = { path[0], ':', '\\', 0 }; - - volume->type = GetDriveTypeW(drive); - BOOL bRet = GetVolumeInformationW(drive, volume->label, _countof(volume->label), &volume->serial, NULL, NULL, NULL, 0); - TRACE("ret = %d type %d serial %08x name %s\n", bRet, - volume->type, volume->serial, debugstr_w(volume->label)); - return bRet; -} - -HRESULT WINAPI CShellLink::SetPath(LPCWSTR pszFile) +HRESULT STDMETHODCALLTYPE CShellLink::SetPath(LPCWSTR pszFile) { LPWSTR unquoted = NULL; HRESULT hr = S_OK; @@ -1629,8 +1554,8 @@ HRESULT WINAPI CShellLink::SetPath(LPCWSTR pszFile) return E_INVALIDARG; /* quotes at the ends of the string are stripped */ - UINT len = wcslen(pszFile); - if (pszFile[0] == '"' && pszFile[len-1] == '"') + SIZE_T len = wcslen(pszFile); + if (pszFile[0] == L'"' && pszFile[len-1] == L'"') { unquoted = strdupW(pszFile); PathUnquoteSpacesW(unquoted); @@ -1638,23 +1563,23 @@ HRESULT WINAPI CShellLink::SetPath(LPCWSTR pszFile) } /* any other quote marks are invalid */ - if (wcschr(pszFile, '"')) + if (wcschr(pszFile, L'"')) { HeapFree(GetProcessHeap(), 0, unquoted); return S_FALSE; } - HeapFree(GetProcessHeap(), 0, sPath); - sPath = NULL; + HeapFree(GetProcessHeap(), 0, m_sPath); + m_sPath = NULL; HeapFree(GetProcessHeap(), 0, sComponent); sComponent = NULL; - if (pPidl) - ILFree(pPidl); - pPidl = NULL; + if (m_pPidl) + ILFree(m_pPidl); + m_pPidl = NULL; - if (S_OK != ShellLink_SetAdvertiseInfo(pszFile)) + if (S_OK != SetAdvertiseInfo(pszFile)) { WCHAR buffer[MAX_PATH]; LPWSTR fname; @@ -1667,30 +1592,30 @@ HRESULT WINAPI CShellLink::SetPath(LPCWSTR pszFile) !SearchPathW(NULL, pszFile, NULL, MAX_PATH, buffer, NULL)) hr = S_FALSE; - pPidl = SHSimpleIDListFromPathW(pszFile); + m_pPidl = SHSimpleIDListFromPathW(pszFile); ShellLink_GetVolumeInfo(buffer, &volume); - sPath = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, + m_sPath = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (wcslen(buffer) + 1) * sizeof (WCHAR)); - if (!sPath) + if (!m_sPath) return E_OUTOFMEMORY; - wcscpy(sPath, buffer); + wcscpy(m_sPath, buffer); } - bDirty = TRUE; + m_bDirty = TRUE; HeapFree(GetProcessHeap(), 0, unquoted); return hr; } -HRESULT WINAPI CShellLink::AddDataBlock(void* pDataBlock) +HRESULT STDMETHODCALLTYPE CShellLink::AddDataBlock(void* pDataBlock) { FIXME("\n"); return E_NOTIMPL; } -HRESULT WINAPI CShellLink::CopyDataBlock(DWORD dwSig, void** ppDataBlock) +HRESULT STDMETHODCALLTYPE CShellLink::CopyDataBlock(DWORD dwSig, void** ppDataBlock) { LPVOID block = NULL; HRESULT hr = E_FAIL; @@ -1719,30 +1644,30 @@ HRESULT WINAPI CShellLink::CopyDataBlock(DWORD dwSig, void** ppDataBlock) return hr; } -HRESULT WINAPI CShellLink::RemoveDataBlock(DWORD dwSig) +HRESULT STDMETHODCALLTYPE CShellLink::RemoveDataBlock(DWORD dwSig) { FIXME("\n"); return E_NOTIMPL; } -HRESULT WINAPI CShellLink::GetFlags(DWORD *pdwFlags) +HRESULT STDMETHODCALLTYPE CShellLink::GetFlags(DWORD *pdwFlags) { DWORD flags = 0; FIXME("%p %p\n", this, pdwFlags); /* FIXME: add more */ - if (sArgs) + if (m_sArgs) flags |= SLDF_HAS_ARGS; if (sComponent) flags |= SLDF_HAS_DARWINID; - if (sIcoPath) + if (m_sIcoPath) flags |= SLDF_HAS_ICONLOCATION; #if (NTDDI_VERSION < NTDDI_LONGHORN) if (sProduct) flags |= SLDF_HAS_LOGO3ID; #endif - if (pPidl) + if (m_pPidl) flags |= SLDF_HAS_ID_LIST; *pdwFlags = flags; @@ -1750,7 +1675,7 @@ HRESULT WINAPI CShellLink::GetFlags(DWORD *pdwFlags) return S_OK; } -HRESULT WINAPI CShellLink::SetFlags(DWORD dwFlags) +HRESULT STDMETHODCALLTYPE CShellLink::SetFlags(DWORD dwFlags) { FIXME("\n"); return E_NOTIMPL; @@ -1761,7 +1686,7 @@ HRESULT WINAPI CShellLink::SetFlags(DWORD dwFlags) * * Loads the shelllink from the dataobject the shell is pointing to. */ -HRESULT WINAPI CShellLink::Initialize(LPCITEMIDLIST pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID) +HRESULT STDMETHODCALLTYPE CShellLink::Initialize(LPCITEMIDLIST pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID) { TRACE("%p %p %p %p\n", this, pidlFolder, pdtobj, hkeyProgID); @@ -1798,7 +1723,7 @@ HRESULT WINAPI CShellLink::Initialize(LPCITEMIDLIST pidlFolder, IDataObject *pdt return S_OK; } -HRESULT WINAPI CShellLink::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) +HRESULT STDMETHODCALLTYPE CShellLink::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) { int id = 1; @@ -1810,11 +1735,11 @@ HRESULT WINAPI CShellLink::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT id WCHAR wszOpen[20]; if (!LoadStringW(shell32_hInstance, IDS_OPEN_VERB, wszOpen, _countof(wszOpen))) - wszOpen[0] = L'\0'; + *wszOpen = L'\0'; MENUITEMINFOW mii; - memset(&mii, 0, sizeof(mii)); - mii.cbSize = sizeof (mii); + ZeroMemory(&mii, sizeof(mii)); + mii.cbSize = sizeof(mii); mii.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE; mii.dwTypeData = wszOpen; mii.cch = wcslen(mii.dwTypeData); @@ -1823,7 +1748,7 @@ HRESULT WINAPI CShellLink::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT id mii.fType = MFT_STRING; if (!InsertMenuItemW(hMenu, indexMenu, TRUE, &mii)) return E_FAIL; - iIdOpen = 1; + m_iIdOpen = 1; return MAKE_HRESULT(SEVERITY_SUCCESS, 0, id); } @@ -1851,7 +1776,7 @@ shelllink_get_msi_component_path(LPWSTR component) return path; } -HRESULT WINAPI CShellLink::InvokeCommand(LPCMINVOKECOMMANDINFO lpici) +HRESULT STDMETHODCALLTYPE CShellLink::InvokeCommand(LPCMINVOKECOMMANDINFO lpici) { HWND hwnd = NULL; /* FIXME: get using interface set from IObjectWithSite */ LPWSTR args = NULL; @@ -1859,7 +1784,7 @@ HRESULT WINAPI CShellLink::InvokeCommand(LPCMINVOKECOMMANDINFO lpici) TRACE("%p %p\n", this, lpici); - if (lpici->cbSize < sizeof (CMINVOKECOMMANDINFO)) + if (lpici->cbSize < sizeof(CMINVOKECOMMANDINFO)) return E_INVALIDARG; HRESULT hr = Resolve(hwnd, 0); @@ -1875,48 +1800,48 @@ HRESULT WINAPI CShellLink::InvokeCommand(LPCMINVOKECOMMANDINFO lpici) return E_FAIL; } else - path = strdupW(sPath); + path = strdupW(m_sPath); if ( lpici->cbSize == sizeof(CMINVOKECOMMANDINFOEX) && (lpici->fMask & CMIC_MASK_UNICODE) ) { LPCMINVOKECOMMANDINFOEX iciex = (LPCMINVOKECOMMANDINFOEX)lpici; - DWORD len = 2; + SIZE_T len = 2; - if (sArgs) - len += wcslen(sArgs); + if (m_sArgs) + len += wcslen(m_sArgs); if (iciex->lpParametersW) len += wcslen(iciex->lpParametersW); args = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); - args[0] = 0; - if (sArgs) - wcscat(args, sArgs); + *args = 0; + if (m_sArgs) + wcscat(args, m_sArgs); if (iciex->lpParametersW) { wcscat(args, L" "); wcscat(args, iciex->lpParametersW); } } - else if (sArgs != NULL) + else if (m_sArgs != NULL) { - args = strdupW(sArgs); + args = strdupW(m_sArgs); } SHELLEXECUTEINFOW sei; - memset(&sei, 0, sizeof sei); - sei.cbSize = sizeof sei; + ZeroMemory(&sei, sizeof(sei)); + sei.cbSize = sizeof(sei); sei.fMask = SEE_MASK_HASLINKNAME | SEE_MASK_UNICODE | (lpici->fMask & (SEE_MASK_NOASYNC | SEE_MASK_ASYNCOK | SEE_MASK_FLAG_NO_UI)); sei.lpFile = path; - sei.lpClass = sLinkPath; + sei.lpClass = m_sLinkPath; sei.nShow = iShowCmd; - sei.lpDirectory = sWorkDir; + sei.lpDirectory = m_sWorkDir; sei.lpParameters = args; sei.lpVerb = L"open"; // HACK for ShellExecuteExW - if (sPath && wcsstr(sPath, L".cpl")) + if (m_sPath && wcsstr(m_sPath, L".cpl")) sei.lpVerb = L"cplopen"; if (ShellExecuteExW(&sei)) @@ -1930,10 +1855,9 @@ HRESULT WINAPI CShellLink::InvokeCommand(LPCMINVOKECOMMANDINFO lpici) return hr; } -HRESULT WINAPI CShellLink::GetCommandString(UINT_PTR idCmd, UINT uType, UINT* pwReserved, LPSTR pszName, UINT cchMax) +HRESULT STDMETHODCALLTYPE CShellLink::GetCommandString(UINT_PTR idCmd, UINT uType, UINT* pwReserved, LPSTR pszName, UINT cchMax) { FIXME("%p %lu %u %p %p %u\n", this, idCmd, uType, pwReserved, pszName, cchMax); - return E_NOTIMPL; } @@ -1982,6 +1906,43 @@ SHOpenFolderAndSelectItems(LPITEMIDLIST pidlFolder, PCUITEMID_CHILD_ARRAY apidl, DWORD dwFlags); +/************************************************************************** +* SH_GetTargetTypeByPath +* +* Function to get target type by passing full path to it +*/ +LPWSTR SH_GetTargetTypeByPath(LPCWSTR lpcwFullPath) +{ + LPCWSTR pwszExt; + static WCHAR wszBuf[MAX_PATH]; + + /* Get file information */ + SHFILEINFOW fi; + if (!SHGetFileInfoW(lpcwFullPath, 0, &fi, sizeof(fi), SHGFI_TYPENAME | SHGFI_USEFILEATTRIBUTES)) + { + ERR("SHGetFileInfoW failed for %ls (%lu)\n", lpcwFullPath, GetLastError()); + fi.szTypeName[0] = L'\0'; + fi.hIcon = NULL; + } + + pwszExt = PathFindExtensionW(lpcwFullPath); + if (pwszExt[0]) + { + if (!fi.szTypeName[0]) + { + /* The file type is unknown, so default to string "FileExtension File" */ + size_t cchRemaining = 0; + LPWSTR pwszEnd = NULL; + + StringCchPrintfExW(wszBuf, _countof(wszBuf), &pwszEnd, &cchRemaining, 0, L"%s ", pwszExt + 1); + } + else + StringCbPrintfW(wszBuf, sizeof(wszBuf), L"%s (%s)", fi.szTypeName, pwszExt); /* Update file type */ + } + + return wszBuf; +} + /************************************************************************** * SH_ShellLinkDlgProc * @@ -2005,14 +1966,14 @@ INT_PTR CALLBACK CShellLink::SH_ShellLinkDlgProc(HWND hwndDlg, UINT uMsg, WPARAM pThis = reinterpret_cast(ppsp->lParam); SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pThis); - TRACE("sArgs: %S sComponent: %S sDescription: %S sIcoPath: %S sPath: %S sPathRel: %S sProduct: %S sWorkDir: %S\n", pThis->sArgs, pThis->sComponent, pThis->sDescription, - pThis->sIcoPath, pThis->sPath, pThis->sPathRel, pThis->sProduct, pThis->sWorkDir); + TRACE("m_sArgs: %S sComponent: %S m_sDescription: %S m_sIcoPath: %S m_sPath: %S m_sPathRel: %S sProduct: %S m_sWorkDir: %S\n", pThis->m_sArgs, pThis->sComponent, pThis->m_sDescription, + pThis->m_sIcoPath, pThis->m_sPath, pThis->m_sPathRel, pThis->sProduct, pThis->m_sWorkDir); /* Get file information */ - SHFILEINFO fi; - if (!SHGetFileInfoW(pThis->sLinkPath, 0, &fi, sizeof(fi), SHGFI_TYPENAME|SHGFI_ICON)) + SHFILEINFOW fi; + if (!SHGetFileInfoW(pThis->m_sLinkPath, 0, &fi, sizeof(fi), SHGFI_TYPENAME|SHGFI_ICON)) { - ERR("SHGetFileInfoW failed for %ls (%lu)\n", pThis->sLinkPath, GetLastError()); + ERR("SHGetFileInfoW failed for %ls (%lu)\n", pThis->m_sLinkPath, GetLastError()); fi.szTypeName[0] = L'\0'; fi.hIcon = NULL; } @@ -2020,39 +1981,39 @@ INT_PTR CALLBACK CShellLink::SH_ShellLinkDlgProc(HWND hwndDlg, UINT uMsg, WPARAM if (fi.hIcon) // TODO: destroy icon SendDlgItemMessageW(hwndDlg, 14000, STM_SETICON, (WPARAM)fi.hIcon, 0); else - ERR("ExtractIconW failed %ls %u\n", pThis->sIcoPath, pThis->iIcoNdx); + ERR("ExtractIconW failed %ls %u\n", pThis->m_sIcoPath, pThis->iIcoNdx); /* target type */ - if (pThis->sPath) - SetDlgItemTextW(hwndDlg, 14005, SH_GetTargetTypeByPath(pThis->sPath)); + if (pThis->m_sPath) + SetDlgItemTextW(hwndDlg, 14005, SH_GetTargetTypeByPath(pThis->m_sPath)); /* target location */ - if (pThis->sWorkDir) - SetDlgItemTextW(hwndDlg, 14007, PathFindFileName(pThis->sWorkDir)); + if (pThis->m_sWorkDir) + SetDlgItemTextW(hwndDlg, 14007, PathFindFileName(pThis->m_sWorkDir)); /* target path */ - if (pThis->sPath) + if (pThis->m_sPath) { WCHAR newpath[2*MAX_PATH] = L"\0"; - if (wcschr(pThis->sPath, ' ')) - StringCchPrintfExW(newpath, 2*MAX_PATH, NULL, NULL, 0, L"\"%ls\"", pThis->sPath); + if (wcschr(pThis->m_sPath, ' ')) + StringCchPrintfExW(newpath, _countof(newpath), NULL, NULL, 0, L"\"%ls\"", pThis->m_sPath); else - StringCchCopyExW(newpath, 2*MAX_PATH, pThis->sPath, NULL, NULL, 0); + StringCchCopyExW(newpath, _countof(newpath), pThis->m_sPath, NULL, NULL, 0); - if (pThis->sArgs && pThis->sArgs[0]) + if (pThis->m_sArgs && pThis->m_sArgs[0]) { - StringCchCatW(newpath, 2*MAX_PATH, L" "); - StringCchCatW(newpath, 2*MAX_PATH, pThis->sArgs); + StringCchCatW(newpath, _countof(newpath), L" "); + StringCchCatW(newpath, _countof(newpath), pThis->m_sArgs); } SetDlgItemTextW(hwndDlg, 14009, newpath); } /* working dir */ - if (pThis->sWorkDir) - SetDlgItemTextW(hwndDlg, 14011, pThis->sWorkDir); + if (pThis->m_sWorkDir) + SetDlgItemTextW(hwndDlg, 14011, pThis->m_sWorkDir); /* description */ - if (pThis->sDescription) - SetDlgItemTextW(hwndDlg, 14019, pThis->sDescription); + if (pThis->m_sDescription) + SetDlgItemTextW(hwndDlg, 14019, pThis->m_sDescription); return TRUE; } @@ -2063,10 +2024,10 @@ INT_PTR CALLBACK CShellLink::SH_ShellLinkDlgProc(HWND hwndDlg, UINT uMsg, WPARAM { WCHAR wszBuf[MAX_PATH]; /* set working directory */ - GetDlgItemTextW(hwndDlg, 14011, wszBuf, MAX_PATH); + GetDlgItemTextW(hwndDlg, 14011, wszBuf, _countof(wszBuf)); pThis->SetWorkingDirectory(wszBuf); /* set link destination */ - GetDlgItemTextW(hwndDlg, 14009, wszBuf, MAX_PATH); + GetDlgItemTextW(hwndDlg, 14009, wszBuf, _countof(wszBuf)); LPWSTR lpszArgs = NULL; LPWSTR unquoted = strdupW(wszBuf); StrTrimW(unquoted, L" "); @@ -2105,9 +2066,10 @@ INT_PTR CALLBACK CShellLink::SH_ShellLinkDlgProc(HWND hwndDlg, UINT uMsg, WPARAM HeapFree(GetProcessHeap(), 0, unquoted); - TRACE("This %p sLinkPath %S\n", pThis, pThis->sLinkPath); - pThis->Save(pThis->sLinkPath, TRUE); - SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR); return TRUE; + TRACE("This %p m_sLinkPath %S\n", pThis, pThis->m_sLinkPath); + pThis->Save(pThis->m_sLinkPath, TRUE); + SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR); + return TRUE; } break; } @@ -2115,7 +2077,7 @@ INT_PTR CALLBACK CShellLink::SH_ShellLinkDlgProc(HWND hwndDlg, UINT uMsg, WPARAM switch(LOWORD(wParam)) { case 14020: - SHOpenFolderAndSelectItems(pThis->pPidl, 0, NULL, 0); + SHOpenFolderAndSelectItems(pThis->m_pPidl, 0, NULL, 0); /// /// FIXME /// open target directory @@ -2125,10 +2087,10 @@ INT_PTR CALLBACK CShellLink::SH_ShellLinkDlgProc(HWND hwndDlg, UINT uMsg, WPARAM { WCHAR wszPath[MAX_PATH] = L""; - if (pThis->sIcoPath) - wcscpy(wszPath, pThis->sIcoPath); + if (pThis->m_sIcoPath) + wcscpy(wszPath, pThis->m_sIcoPath); INT IconIndex = pThis->iIcoNdx; - if (PickIconDlg(hwndDlg, wszPath, MAX_PATH, &IconIndex)) + if (PickIconDlg(hwndDlg, wszPath, _countof(wszPath), &IconIndex)) { pThis->SetIconLocation(wszPath, IconIndex); /// @@ -2139,20 +2101,20 @@ INT_PTR CALLBACK CShellLink::SH_ShellLinkDlgProc(HWND hwndDlg, UINT uMsg, WPARAM case 14022: { - INT_PTR result = DialogBoxParamW(shell32_hInstance, MAKEINTRESOURCEW(IDD_SHORTCUT_EXTENDED_PROPERTIES), hwndDlg, ExtendedShortcutProc, (LPARAM)pThis->bRunAs); + INT_PTR result = DialogBoxParamW(shell32_hInstance, MAKEINTRESOURCEW(IDD_SHORTCUT_EXTENDED_PROPERTIES), hwndDlg, ExtendedShortcutProc, (LPARAM)pThis->m_bRunAs); if (result == 1 || result == 0) { - if (pThis->bRunAs != result) + if (pThis->m_bRunAs != result) { PropSheet_Changed(GetParent(hwndDlg), hwndDlg); } - pThis->bRunAs = result; + pThis->m_bRunAs = result; } return TRUE; } } - if(HIWORD(wParam) == EN_CHANGE) + if (HIWORD(wParam) == EN_CHANGE) PropSheet_Changed(GetParent(hwndDlg), hwndDlg); break; default: @@ -2165,7 +2127,7 @@ INT_PTR CALLBACK CShellLink::SH_ShellLinkDlgProc(HWND hwndDlg, UINT uMsg, WPARAM * ShellLink_IShellPropSheetExt interface */ -HRESULT WINAPI CShellLink::AddPages(LPFNADDPROPSHEETPAGE pfnAddPage, LPARAM lParam) +HRESULT STDMETHODCALLTYPE CShellLink::AddPages(LPFNADDPROPSHEETPAGE pfnAddPage, LPARAM lParam) { HPROPSHEETPAGE hPage = SH_CreatePropertySheetPage(IDD_SHORTCUT_PROPERTIES, SH_ShellLinkDlgProc, (LPARAM)this, NULL); if (hPage == NULL) @@ -2180,46 +2142,46 @@ HRESULT WINAPI CShellLink::AddPages(LPFNADDPROPSHEETPAGE pfnAddPage, LPARAM lPar return S_OK; } -HRESULT WINAPI CShellLink::ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE pfnReplacePage, LPARAM lParam) +HRESULT STDMETHODCALLTYPE CShellLink::ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE pfnReplacePage, LPARAM lParam) { TRACE("(%p) (uPageID %u, pfnReplacePage %p lParam %p\n", this, uPageID, pfnReplacePage, lParam); return E_NOTIMPL; } -HRESULT WINAPI CShellLink::SetSite(IUnknown *punk) +HRESULT STDMETHODCALLTYPE CShellLink::SetSite(IUnknown *punk) { TRACE("%p %p\n", this, punk); - site = punk; + m_site = punk; return S_OK; } -HRESULT WINAPI CShellLink::GetSite(REFIID iid, void ** ppvSite) +HRESULT STDMETHODCALLTYPE CShellLink::GetSite(REFIID iid, void ** ppvSite) { TRACE("%p %s %p\n", this, debugstr_guid(&iid), ppvSite); - if (site == NULL) + if (m_site == NULL) return E_FAIL; - return site->QueryInterface(iid, ppvSite); + return m_site->QueryInterface(iid, ppvSite); } -HRESULT WINAPI CShellLink::DragEnter(IDataObject *pDataObject, +HRESULT STDMETHODCALLTYPE CShellLink::DragEnter(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect) { TRACE("(%p)->(DataObject=%p)\n", this, pDataObject); LPCITEMIDLIST pidlLast; CComPtr psf; - HRESULT hr = SHBindToParent(pPidl, IID_PPV_ARG(IShellFolder, &psf), &pidlLast); + HRESULT hr = SHBindToParent(m_pPidl, IID_PPV_ARG(IShellFolder, &psf), &pidlLast); if (SUCCEEDED(hr)) { - hr = psf->GetUIObjectOf(0, 1, &pidlLast, IID_NULL_PPV_ARG(IDropTarget, &mDropTarget)); + hr = psf->GetUIObjectOf(0, 1, &pidlLast, IID_NULL_PPV_ARG(IDropTarget, &m_DropTarget)); if (SUCCEEDED(hr)) - hr = mDropTarget->DragEnter(pDataObject, dwKeyState, pt, pdwEffect); + hr = m_DropTarget->DragEnter(pDataObject, dwKeyState, pt, pdwEffect); else *pdwEffect = DROPEFFECT_NONE; } @@ -2229,38 +2191,36 @@ HRESULT WINAPI CShellLink::DragEnter(IDataObject *pDataObject, return S_OK; } - - -HRESULT WINAPI CShellLink::DragOver(DWORD dwKeyState, POINTL pt, +HRESULT STDMETHODCALLTYPE CShellLink::DragOver(DWORD dwKeyState, POINTL pt, DWORD *pdwEffect) { TRACE("(%p)\n", this); HRESULT hr = S_OK; - if (mDropTarget) - hr = mDropTarget->DragOver(dwKeyState, pt, pdwEffect); + if (m_DropTarget) + hr = m_DropTarget->DragOver(dwKeyState, pt, pdwEffect); return hr; } -HRESULT WINAPI CShellLink::DragLeave() +HRESULT STDMETHODCALLTYPE CShellLink::DragLeave() { TRACE("(%p)\n", this); HRESULT hr = S_OK; - if (mDropTarget) + if (m_DropTarget) { - hr = mDropTarget->DragLeave(); - mDropTarget.Release(); + hr = m_DropTarget->DragLeave(); + m_DropTarget.Release(); } return hr; } -HRESULT WINAPI CShellLink::Drop(IDataObject *pDataObject, +HRESULT STDMETHODCALLTYPE CShellLink::Drop(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect) { TRACE("(%p)\n", this); HRESULT hr = S_OK; - if (mDropTarget) - hr = mDropTarget->Drop(pDataObject, dwKeyState, pt, pdwEffect); + if (m_DropTarget) + hr = m_DropTarget->Drop(pDataObject, dwKeyState, pt, pdwEffect); return hr; } diff --git a/reactos/dll/win32/shell32/CShellLink.h b/reactos/dll/win32/shell32/CShellLink.h index 96d3b12dc71..045e34efc96 100644 --- a/reactos/dll/win32/shell32/CShellLink.h +++ b/reactos/dll/win32/shell32/CShellLink.h @@ -39,134 +39,143 @@ class CShellLink : public IShellPropSheetExt { public: - /* link file formats */ + /* Link file formats */ #include "pshpack1.h" struct volume_info { - DWORD type; - DWORD serial; - WCHAR label[12]; /* assume 8.3 */ + DWORD type; + DWORD serial; + WCHAR label[12]; /* assume 8.3 */ }; #include "poppack.h" private: /* data structures according to the information in the link */ - LPITEMIDLIST pPidl; WORD wHotKey; SYSTEMTIME time1; SYSTEMTIME time2; SYSTEMTIME time3; DWORD iShowCmd; - LPWSTR sIcoPath; INT iIcoNdx; - LPWSTR sPath; - LPWSTR sArgs; - LPWSTR sWorkDir; - LPWSTR sDescription; - LPWSTR sPathRel; - LPWSTR sProduct; - LPWSTR sComponent; + + /* Cached data set according to m_Header.dwFlags (SHELL_LINK_DATA_FLAGS) */ + + LPITEMIDLIST m_pPidl; + + /* Link tracker information */ + LPWSTR m_sPath; volume_info volume; - LPWSTR sLinkPath; - BOOL bRunAs; - BOOL bDirty; - INT iIdOpen; /* id of the "Open" entry in the context menu */ - CComPtr site; - CComPtr mDropTarget; + + LPWSTR m_sDescription; + LPWSTR m_sPathRel; + LPWSTR m_sWorkDir; + LPWSTR m_sArgs; + LPWSTR m_sIcoPath; + BOOL m_bRunAs; + BOOL m_bDirty; + + LPWSTR sProduct; + LPWSTR sComponent; + + LPWSTR m_sLinkPath; + INT m_iIdOpen; /* ID of the "Open" entry in the context menu */ + + CComPtr m_site; + CComPtr m_DropTarget; + public: CShellLink(); ~CShellLink(); - LPWSTR ShellLink_GetAdvertisedArg(LPCWSTR str); - HRESULT ShellLink_SetAdvertiseInfo(LPCWSTR str); + HRESULT SetAdvertiseInfo(LPCWSTR str); static INT_PTR CALLBACK SH_ShellLinkDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); // IPersistFile - virtual HRESULT WINAPI GetClassID(CLSID *pclsid); - virtual HRESULT WINAPI IsDirty(); - virtual HRESULT WINAPI Load(LPCOLESTR pszFileName, DWORD dwMode); - virtual HRESULT WINAPI Save(LPCOLESTR pszFileName, BOOL fRemember); - virtual HRESULT WINAPI SaveCompleted(LPCOLESTR pszFileName); - virtual HRESULT WINAPI GetCurFile(LPOLESTR *ppszFileName); + virtual HRESULT STDMETHODCALLTYPE GetClassID(CLSID *pclsid); + virtual HRESULT STDMETHODCALLTYPE IsDirty(); + virtual HRESULT STDMETHODCALLTYPE Load(LPCOLESTR pszFileName, DWORD dwMode); + virtual HRESULT STDMETHODCALLTYPE Save(LPCOLESTR pszFileName, BOOL fRemember); + virtual HRESULT STDMETHODCALLTYPE SaveCompleted(LPCOLESTR pszFileName); + virtual HRESULT STDMETHODCALLTYPE GetCurFile(LPOLESTR *ppszFileName); // IPersistStream - // virtual WINAPI HRESULT GetClassID(CLSID *pclsid); - // virtual HRESULT WINAPI IsDirty(); - virtual HRESULT WINAPI Load(IStream *stm); - virtual HRESULT WINAPI Save(IStream *stm, BOOL fClearDirty); - virtual HRESULT WINAPI GetSizeMax(ULARGE_INTEGER *pcbSize); + // virtual HRESULT STDMETHODCALLTYPE GetClassID(CLSID *pclsid); + // virtual HRESULT STDMETHODCALLTYPE IsDirty(); + virtual HRESULT STDMETHODCALLTYPE Load(IStream *stm); + virtual HRESULT STDMETHODCALLTYPE Save(IStream *stm, BOOL fClearDirty); + virtual HRESULT STDMETHODCALLTYPE GetSizeMax(ULARGE_INTEGER *pcbSize); // IShellLinkA - virtual HRESULT WINAPI GetPath(LPSTR pszFile, INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags); - virtual HRESULT WINAPI GetIDList(LPITEMIDLIST * ppidl); - virtual HRESULT WINAPI SetIDList(LPCITEMIDLIST pidl); - virtual HRESULT WINAPI GetDescription(LPSTR pszName,INT cchMaxName); - virtual HRESULT WINAPI SetDescription(LPCSTR pszName); - virtual HRESULT WINAPI GetWorkingDirectory(LPSTR pszDir,INT cchMaxPath); - virtual HRESULT WINAPI SetWorkingDirectory(LPCSTR pszDir); - virtual HRESULT WINAPI GetArguments(LPSTR pszArgs,INT cchMaxPath); - virtual HRESULT WINAPI SetArguments(LPCSTR pszArgs); - virtual HRESULT WINAPI GetHotkey(WORD *pwHotkey); - virtual HRESULT WINAPI SetHotkey(WORD wHotkey); - virtual HRESULT WINAPI GetShowCmd(INT *piShowCmd); - virtual HRESULT WINAPI SetShowCmd(INT iShowCmd); - virtual HRESULT WINAPI GetIconLocation(LPSTR pszIconPath,INT cchIconPath,INT *piIcon); - virtual HRESULT WINAPI SetIconLocation(LPCSTR pszIconPath,INT iIcon); - virtual HRESULT WINAPI SetRelativePath(LPCSTR pszPathRel, DWORD dwReserved); - virtual HRESULT WINAPI Resolve(HWND hwnd, DWORD fFlags); - virtual HRESULT WINAPI SetPath(LPCSTR pszFile); + virtual HRESULT STDMETHODCALLTYPE GetPath(LPSTR pszFile, INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags); + virtual HRESULT STDMETHODCALLTYPE GetIDList(LPITEMIDLIST *ppidl); + virtual HRESULT STDMETHODCALLTYPE SetIDList(LPCITEMIDLIST pidl); + virtual HRESULT STDMETHODCALLTYPE GetDescription(LPSTR pszName, INT cchMaxName); + virtual HRESULT STDMETHODCALLTYPE SetDescription(LPCSTR pszName); + virtual HRESULT STDMETHODCALLTYPE GetWorkingDirectory(LPSTR pszDir, INT cchMaxPath); + virtual HRESULT STDMETHODCALLTYPE SetWorkingDirectory(LPCSTR pszDir); + virtual HRESULT STDMETHODCALLTYPE GetArguments(LPSTR pszArgs, INT cchMaxPath); + virtual HRESULT STDMETHODCALLTYPE SetArguments(LPCSTR pszArgs); + virtual HRESULT STDMETHODCALLTYPE GetHotkey(WORD *pwHotkey); + virtual HRESULT STDMETHODCALLTYPE SetHotkey(WORD wHotkey); + virtual HRESULT STDMETHODCALLTYPE GetShowCmd(INT *piShowCmd); + virtual HRESULT STDMETHODCALLTYPE SetShowCmd(INT iShowCmd); + virtual HRESULT STDMETHODCALLTYPE GetIconLocation(LPSTR pszIconPath, INT cchIconPath, INT *piIcon); + virtual HRESULT STDMETHODCALLTYPE SetIconLocation(LPCSTR pszIconPath, INT iIcon); + virtual HRESULT STDMETHODCALLTYPE SetRelativePath(LPCSTR pszPathRel, DWORD dwReserved); + virtual HRESULT STDMETHODCALLTYPE Resolve(HWND hwnd, DWORD fFlags); + virtual HRESULT STDMETHODCALLTYPE SetPath(LPCSTR pszFile); // IShellLinkW - virtual HRESULT WINAPI GetPath(LPWSTR pszFile, INT cchMaxPath, WIN32_FIND_DATAW *pfd, DWORD fFlags); - // virtual HRESULT WINAPI GetIDList(LPITEMIDLIST *ppidl); - // virtual HRESULT WINAPI SetIDList(LPCITEMIDLIST pidl); - virtual HRESULT WINAPI GetDescription(LPWSTR pszName, INT cchMaxName); - virtual HRESULT WINAPI SetDescription(LPCWSTR pszName); - virtual HRESULT WINAPI GetWorkingDirectory(LPWSTR pszDir, INT cchMaxPath); - virtual HRESULT WINAPI SetWorkingDirectory(LPCWSTR pszDir); - virtual HRESULT WINAPI GetArguments(LPWSTR pszArgs,INT cchMaxPath); - virtual HRESULT WINAPI SetArguments(LPCWSTR pszArgs); - // virtual HRESULT WINAPI GetHotkey(WORD *pwHotkey); - // virtual HRESULT WINAPI SetHotkey(WORD wHotkey); - // virtual HRESULT WINAPI GetShowCmd(INT *piShowCmd); - // virtual HRESULT WINAPI SetShowCmd(INT iShowCmd); - virtual HRESULT WINAPI GetIconLocation(LPWSTR pszIconPath,INT cchIconPath,INT *piIcon); - virtual HRESULT WINAPI SetIconLocation(LPCWSTR pszIconPath,INT iIcon); - virtual HRESULT WINAPI SetRelativePath(LPCWSTR pszPathRel, DWORD dwReserved); - // virtual HRESULT WINAPI Resolve(HWND hwnd, DWORD fFlags); - virtual HRESULT WINAPI SetPath(LPCWSTR pszFile); + virtual HRESULT STDMETHODCALLTYPE GetPath(LPWSTR pszFile, INT cchMaxPath, WIN32_FIND_DATAW *pfd, DWORD fFlags); + // virtual HRESULT STDMETHODCALLTYPE GetIDList(LPITEMIDLIST *ppidl); + // virtual HRESULT STDMETHODCALLTYPE SetIDList(LPCITEMIDLIST pidl); + virtual HRESULT STDMETHODCALLTYPE GetDescription(LPWSTR pszName, INT cchMaxName); + virtual HRESULT STDMETHODCALLTYPE SetDescription(LPCWSTR pszName); + virtual HRESULT STDMETHODCALLTYPE GetWorkingDirectory(LPWSTR pszDir, INT cchMaxPath); + virtual HRESULT STDMETHODCALLTYPE SetWorkingDirectory(LPCWSTR pszDir); + virtual HRESULT STDMETHODCALLTYPE GetArguments(LPWSTR pszArgs, INT cchMaxPath); + virtual HRESULT STDMETHODCALLTYPE SetArguments(LPCWSTR pszArgs); + // virtual HRESULT STDMETHODCALLTYPE GetHotkey(WORD *pwHotkey); + // virtual HRESULT STDMETHODCALLTYPE SetHotkey(WORD wHotkey); + // virtual HRESULT STDMETHODCALLTYPE GetShowCmd(INT *piShowCmd); + // virtual HRESULT STDMETHODCALLTYPE SetShowCmd(INT iShowCmd); + virtual HRESULT STDMETHODCALLTYPE GetIconLocation(LPWSTR pszIconPath, INT cchIconPath, INT *piIcon); + virtual HRESULT STDMETHODCALLTYPE SetIconLocation(LPCWSTR pszIconPath, INT iIcon); + virtual HRESULT STDMETHODCALLTYPE SetRelativePath(LPCWSTR pszPathRel, DWORD dwReserved); + // virtual HRESULT STDMETHODCALLTYPE Resolve(HWND hwnd, DWORD fFlags); + virtual HRESULT STDMETHODCALLTYPE SetPath(LPCWSTR pszFile); // IShellLinkDataList - virtual HRESULT WINAPI AddDataBlock(void *pDataBlock); - virtual HRESULT WINAPI CopyDataBlock(DWORD dwSig, void **ppDataBlock); - virtual HRESULT WINAPI RemoveDataBlock(DWORD dwSig); - virtual HRESULT WINAPI GetFlags(DWORD *pdwFlags); - virtual HRESULT WINAPI SetFlags(DWORD dwFlags); + virtual HRESULT STDMETHODCALLTYPE AddDataBlock(void *pDataBlock); + virtual HRESULT STDMETHODCALLTYPE CopyDataBlock(DWORD dwSig, void **ppDataBlock); + virtual HRESULT STDMETHODCALLTYPE RemoveDataBlock(DWORD dwSig); + virtual HRESULT STDMETHODCALLTYPE GetFlags(DWORD *pdwFlags); + virtual HRESULT STDMETHODCALLTYPE SetFlags(DWORD dwFlags); // IShellExtInit - virtual HRESULT WINAPI Initialize(LPCITEMIDLIST pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID); + virtual HRESULT STDMETHODCALLTYPE Initialize(LPCITEMIDLIST pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID); // IContextMenu - virtual HRESULT WINAPI QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags); - virtual HRESULT WINAPI InvokeCommand(LPCMINVOKECOMMANDINFO lpici); - virtual HRESULT WINAPI GetCommandString(UINT_PTR idCmd, UINT uType, UINT *pwReserved, LPSTR pszName, UINT cchMax); + virtual HRESULT STDMETHODCALLTYPE QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags); + virtual HRESULT STDMETHODCALLTYPE InvokeCommand(LPCMINVOKECOMMANDINFO lpici); + virtual HRESULT STDMETHODCALLTYPE GetCommandString(UINT_PTR idCmd, UINT uType, UINT *pwReserved, LPSTR pszName, UINT cchMax); // IShellPropSheetExt - virtual HRESULT WINAPI AddPages(LPFNADDPROPSHEETPAGE pfnAddPage, LPARAM lParam); - virtual HRESULT WINAPI ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE pfnReplacePage, LPARAM lParam); + virtual HRESULT STDMETHODCALLTYPE AddPages(LPFNADDPROPSHEETPAGE pfnAddPage, LPARAM lParam); + virtual HRESULT STDMETHODCALLTYPE ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE pfnReplacePage, LPARAM lParam); // IObjectWithSite - virtual HRESULT WINAPI SetSite(IUnknown *punk); - virtual HRESULT WINAPI GetSite(REFIID iid, void **ppvSite); + virtual HRESULT STDMETHODCALLTYPE SetSite(IUnknown *punk); + virtual HRESULT STDMETHODCALLTYPE GetSite(REFIID iid, void **ppvSite); // IDropTarget - virtual HRESULT WINAPI DragEnter(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect); - virtual HRESULT WINAPI DragOver(DWORD dwKeyState, POINTL pt, DWORD *pdwEffect); - virtual HRESULT WINAPI DragLeave(); - virtual HRESULT WINAPI Drop(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect); + virtual HRESULT STDMETHODCALLTYPE DragEnter(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect); + virtual HRESULT STDMETHODCALLTYPE DragOver(DWORD dwKeyState, POINTL pt, DWORD *pdwEffect); + virtual HRESULT STDMETHODCALLTYPE DragLeave(); + virtual HRESULT STDMETHODCALLTYPE Drop(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect); DECLARE_REGISTRY_RESOURCEID(IDR_SHELLLINK) DECLARE_NOT_AGGREGATABLE(CShellLink)