That is because here:
FoundDrive->DriveLetter = pBuffer;
you store a pointer at pBuffer. So each and every instance of
DriveInfo
will have a pointer in it's
DriveLetter
member at the very same buffer. This buffer,
pBuffer
is overwritten in each itearion of the
while
loop that iterates the drives, thus, after the loop,
pBuffer
will contain the very last drive letter (e.g. Z), and since each and every
DriveInfo
has a pointer at this buffer, they will all "report" this very last drive.
Try changing
DriveLetter
from
char *
to
CString
, or
std::string
, or at least allocate a new char buffer for every
DriveInfo
instance and copy the buffer into them. Or make it simply a
char
and copy that one particular letter from the buffer into them.