C++ Windows API DlgDirList sometimes don't return the correct listing

169 views Asked by At

I have 2 List Box, one always listing directories from a path and other listing the files from the selected directory.

The first time i select a directory, the files are shown properly, but if i select another directory, it lists nothing.

That's my current main.cpp, where all GUI stuff happens: http://pastebin.com/PjSb8aKy

List Box codes goes from lines 31 to 45 and 150 to 165.

Thanks in advance.

--------------------------------------------------EDIT---------------------------------------------------------------

I put a simple std::cout on the sel string, the result is that on the first directory i select, it's "", then it becomes "DirectoryName\", i tried changing the sel string to be "./DirectoryName", didn't managed to do it, the "\" still appears, but that isn't what bothers me, the real weird stuff is the first selection returning "" to the sel string...

1

There are 1 answers

4
Jonathan Potter On BEST ANSWER

I think the clue is in the docs for the DlgDirList function:

If lpPathSpec specifies a directory, DlgDirListComboBox changes the current directory to the specified directory before filling the list box.

I've never used these functions myself but I'd bet that your current directory is being modified and so subsequent calls to DlgDirList are looking in the wrong place.