I am trying to make a wrapper class that contains the GetLogicalDriveStrings() function. Is there a way to
1) Get this buffer copyed into a CString
2) Use the CString in the same manner that the buffer is being used.

The problem i am running into is the format of the buff string that is returned from
GetLogicalDriveStrings(). It has the terminating character seperating the
Drive Letters.
A:/'\0'C:/'\0'...
This seems to be doing something to the functionality of the
CString.

Here is the code.

TCHAR * buff = NULL;
buff = new TCHAR[nBuffSize];
GetLogicalDriveStrings(nBuffSize,buff);

for(DWORD i = 0; i < nBuffSize; i += 4){
RecurseDirs(&buff[i]);
}

Any better suggestions on how to implement this would be
great also if there is a better way.

Re: CString problem by Scott

Scott
Tue Jun 22 18:36:30 CDT 2004

mikem wrote:

> I am trying to make a wrapper class that contains the GetLogicalDriveStrings() function. Is there a way to
> 1) Get this buffer copyed into a CString
> 2) Use the CString in the same manner that the buffer is being used.
>
> The problem i am running into is the format of the buff string that is returned from
> GetLogicalDriveStrings(). It has the terminating character seperating the
> Drive Letters.
> A:/'\0'C:/'\0'...
> This seems to be doing something to the functionality of the
> CString.
>
> Here is the code.
>
> TCHAR * buff = NULL;
> buff = new TCHAR[nBuffSize];
> GetLogicalDriveStrings(nBuffSize,buff);
>
> for(DWORD i = 0; i < nBuffSize; i += 4){
> RecurseDirs(&buff[i]);
> }
>
> Any better suggestions on how to implement this would be
> great also if there is a better way.

You can use GetBuffer to allocate this buffer:

CString str;
int ActualLen = GetLogicalDriveStrings(nBuffSize,
str.GetBuffer(nBuffSize]);
str.ReleaseBuffer(ActualLen);

Presumably you do not need to modify the string in RecurseDirs, so you
can access the locations within the string buffer using the CString
LPCTSTR operator:

for(DWORD i = 0; i < ActualLen; i += 4){
RecurseDirs((LPCTSTR)str + i);
}

--
Scott McPhillips [VC++ MVP]