3

I am using CComboBox::Dir(DDL_READWRITE, path) to populate the contents of a combobox. Everything is fine, but when I reset the Archive flag and set the Index flag, the Dir() returns no files. I am using

attrib -A *.*
attrib +I *.*

in the directory I am listing. I have tried changing the first parameter to Dir() function but it does not help. I have tried FindFirstFile()/FindNextFile() and they are working fine

Any ideas to explain the reason of this behavior? Could this a bug in the Dir() function? If yes, what other functions could it effect? How to solve this problem?

Aamir
  • 14,882
  • 6
  • 45
  • 69
goto
  • 433
  • 3
  • 13

1 Answers1

0

This is quite an interesting issue. I debugged it on Win 7 64 Bit down into comctl32.dll ListBox_DirHandler assembler code and found out that Windows is doing something like this (just some simplified code):

// attr is the low word of the parameter passed to CComboBox::Dir.
attr &= FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_NORMAL;
attr |= FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_NORMAL|FILE_ATTRIBUTE_READONLY;

WIN32_FIND_DATA finddata;
FindFirstFile(..., &finddata)
while(...) {
  if(finddata.dwFileAttributes == FILE_ATTRIBUTE_COMPRESSED)
    finddata.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
  if(finddata.dwFileAttributes & attr) {
    // some more checks and then might add the file name to the control;
  }
  FindNextFile(..., &finddata);
}

The problem is that your file is returned with finddata.dwFileAttributes==FILE_ATTRIBUTE_NOT_CONTENT_INDEXED. At entry of the function attr is changed so that it can never have FILE_ATTRIBUTE_NOT_CONTENT_INDEXED set, so the if inside the loop will never be true and the file name never be added to the control.

Sorry, but as far as I can see you will have to wait for an MS bugfix or do the work yourself.

Werner Henze
  • 16,404
  • 12
  • 44
  • 69