diff --git a/src/common/utils/HDropIterator.h b/src/common/utils/HDropIterator.h index 7fbc0d7173ca..3b52d65babf1 100644 --- a/src/common/utils/HDropIterator.h +++ b/src/common/utils/HDropIterator.h @@ -7,6 +7,7 @@ class HDropIterator HDropIterator(IDataObject* pDataObject) { _current = 0; + _listCount = 0; FORMATETC formatetc = { CF_HDROP, @@ -16,14 +17,22 @@ class HDropIterator TYMED_HGLOBAL }; - pDataObject->GetData(&formatetc, &m_medium); - - _listCount = DragQueryFile((HDROP)m_medium.hGlobal, 0xFFFFFFFF, NULL, 0); + if (SUCCEEDED(pDataObject->GetData(&formatetc, &m_medium))) + { + _listCount = DragQueryFile((HDROP)m_medium.hGlobal, 0xFFFFFFFF, NULL, 0); + } + else + { + m_medium = {}; + } } ~HDropIterator() { - ReleaseStgMedium(&m_medium); + if (m_medium.tymed) + { + ReleaseStgMedium(&m_medium); + } } void First() diff --git a/src/modules/imageresizer/dll/ContextMenuHandler.cpp b/src/modules/imageresizer/dll/ContextMenuHandler.cpp index dec860dcccd0..d9a7ad939082 100644 --- a/src/modules/imageresizer/dll/ContextMenuHandler.cpp +++ b/src/modules/imageresizer/dll/ContextMenuHandler.cpp @@ -72,6 +72,11 @@ HRESULT CContextMenuHandler::QueryContextMenu(_In_ HMENU hmenu, UINT indexMenu, // NB: We just check the first item. We could iterate through more if the first one doesn't meet the criteria HDropIterator i(m_pdtobj); i.First(); + if (i.IsDone()) + { + return S_OK; + } + // Suppressing C26812 warning as the issue is in the shtypes.h library #pragma warning(suppress : 26812) PERCEIVED type;