1. void CDialogDlg::GetLogicalDrives()  
  2. {  
  3.     //get the length of drive strings not include the last terminating null character  
  4.     int nBufferLength = GetLogicalDriveStrings(0, NULL);  
  5.  
  6.     //the size must plus the last terminating null character  
  7.     TCHAR* pBuffer = new TCHAR[nBufferLength + 1];  
  8.       
  9.     //Get the actually DriveStrings  
  10.     GetLogicalDriveStrings(nBufferLength, pBuffer);  
  11.  
  12.     TCHAR* pBegin = pBuffer;  
  13.     size_t nLength = _tcslen(pBuffer);  
  14.  
  15.     while(nLength > 0)  
  16.     {  
  17.         TRACE(_T("%s\n"), pBuffer);  
  18.         pBuffer += nLength + 1;  
  19.         nLength = _tcslen(pBuffer);  
  20.     }  
  21.           
  22.     delete [] pBegin;  
  23.     pBegin = NULL;  
  24. }  
  25.  
  26. //Output:  
  27. //C:\  
  28. //D:\  
  29. //E:\  
  30. //F:\  
  31. //G:\  
  32. //H:\