CListCtrl::InsertItem() causes deadlock when given iIcon of icon that app can't get on WIndows 11

Viewed 49

I have a legacy app that have a dialog with CListCtrl that represents files(with icons) in some folder. And when folder contains files of specific extentions(whitch affects icon) App got stuck after I call InsertItem() for that file.

What can I do to prevent that deadlock or can I use icon handlers instead of indexes?

There is what i do:

In background thread I get vector with files info and do foreach. On each iteration I call SHGetFileInfo for given filename to get a system index of an icon that associate with that filename and call m_pListCtrl->InsertItem()

sample code:

m_fiVector = getFilesInfo();
for (int i = 0; i < m_fiVector.size; ++i){

  SHFILEINFO sfi;
  sfi.iIcon = 0;

  SHGetFileInfo(m_fiVector[i].Name,
    (m_fiVector[i].isDir) ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL,
    &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_USERFILEATTRIBUTES | SHGFI_SMALLICON
  );

  int pos = m_pListCtrl->InsertItem(m_pListCtrl->GetItemCount(),
    m_fiVector[i].Name,
    sfi.iIcon
  );
  
  m_pListCtrl->SetItemText(pos, 0, m_fiVector[i].Name.c_str());
}

That worked fine until I updated to Windows 11 and opened folder with some .ps1 files, thats where deadlock happend.

I figured out that on windows 10(and earlier, i suppose) SHGetFileInfo returns sfi.iIcon from some system index list, but on windows 11 it return some SHGetFileInfo-Caller-App-based index. I wrote simple cosole app to demonstrate that behavior. There is screenshots of two runs with different SHGetFileInfo call orders:

Also as you can see on Windows11 screenshot - icon index for .ps1 for some reason is 0, but in my legacy app it's not. (idk why on console app it's 0 cause i have pwsh installed and in explorer file icon is not blank, so there should be an icon index)

And after I pass that non-zero index to CListCtrl - app stucks. With no errors or something. Also it's stucks not in that background thread on InsertItem but on main thread. I put some logging and can see that all filenames on vector being processed fine. I guess it stucks in some internal mfc screenUpdate\paint function because visually .ps1 file doesn't apper on a list(and so does not any of files that processed after it)

So my question is how to prevent that deadlock or is there is another way to get or way to chech\validate icon.

Also it would be nice to have a link to some info about that new icon index behavior on win11, thanks.

0 Answers
Related