Hi all,
I am writing a gui library in Python with ctypes. So far so good. Currently I am writing the common dialog boxes like file open, file save and folder browser. Windows will allow us to open more than one file with OFN_ALLOWMULTISELECT
flag. But if we use this flag, the lpstrFile
member of the OPENFILENAMEW
struct behaves quite differently. The lpstrFile
member is an array with 260 wchar character length. The documentation says this ;
If the user selects more than one file, the lpstrFile buffer returns the path to the current directory
followed by the file names of the selected files.
The nFileOffset member is the offset, in bytes or characters,
to the first file name, and the nFileExtension member is not used.
For Explorer-style dialog boxes, the directory and file name strings
are NULL separated, with an extra NULL character after the last file name.
So this is what i am using for D programming language.
void extractFileNames(wchar[] buff, int startPos) {
int offset = startPos;
for (int i = startPos; i < MAX_PATH; i++) {
wchar wc = buff[i];
if (wc == '\u0000') {
wchar[] slice = buff[offset..i];
offset = i + 1;
this.mSelFiles ~= slice.to!string; // Adding sliced file name to array.
if (buff[offset] == '\u0000') break;
}
}
}
I am using Explorer-style dialog box. So I have a buffer which should contain the directory path and all selected file names separated by null character. But buffer.value
only returns the directory path. Is the rest of the data missing because of the null character after the directory path? So how to retrieve the data after the first null character?