diff --git a/src/modules/imageresizer/ImageResizerContextMenu/dllmain.cpp b/src/modules/imageresizer/ImageResizerContextMenu/dllmain.cpp index 83a53cd373..8849371eec 100644 --- a/src/modules/imageresizer/ImageResizerContextMenu/dllmain.cpp +++ b/src/modules/imageresizer/ImageResizerContextMenu/dllmain.cpp @@ -255,14 +255,20 @@ private: for (DWORD i = 0; i < fileCount; i++) { IShellItem* shellItem; - psiItemArray->GetItemAt(i, &shellItem); - LPWSTR itemName; - // Retrieves the entire file system path of the file from its shell item - shellItem->GetDisplayName(SIGDN_FILESYSPATH, &itemName); - CString fileName(itemName); - fileName.Append(_T("\r\n")); - // Write the file path into the input stream for image resizer - writePipe.Write(fileName, fileName.GetLength() * sizeof(TCHAR)); + HRESULT getItemAtResult = psiItemArray->GetItemAt(i, &shellItem); + if (SUCCEEDED(getItemAtResult)) + { + LPWSTR itemName; + // Retrieves the entire file system path of the file from its shell item + HRESULT getDisplayResult = shellItem->GetDisplayName(SIGDN_FILESYSPATH, &itemName); + if (SUCCEEDED(getDisplayResult)) + { + CString fileName(itemName); + fileName.Append(_T("\r\n")); + // Write the file path into the input stream for image resizer + writePipe.Write(fileName, fileName.GetLength() * sizeof(TCHAR)); + } + } } writePipe.Close(); } diff --git a/src/modules/imageresizer/dll/ContextMenuHandler.cpp b/src/modules/imageresizer/dll/ContextMenuHandler.cpp index fddf2b4497..db679df4ad 100644 --- a/src/modules/imageresizer/dll/ContextMenuHandler.cpp +++ b/src/modules/imageresizer/dll/ContextMenuHandler.cpp @@ -386,8 +386,14 @@ HRESULT __stdcall CContextMenuHandler::GetState(IShellItemArray* psiItemArray, B PERCEIVED type; PERCEIVEDFLAG flag; IShellItem* shellItem; + //Check extension of first item in the list (the item which is right-clicked on) - psiItemArray->GetItemAt(0, &shellItem); + HRESULT getItemAtResult = psiItemArray->GetItemAt(0, &shellItem); + if(!SUCCEEDED(getItemAtResult)) { + // Avoid crashes in the following code. + return E_FAIL; + } + LPTSTR pszPath; // Retrieves the entire file system path of the file from its shell item HRESULT getDisplayResult = shellItem->GetDisplayName(SIGDN_FILESYSPATH, &pszPath);