- void CDialogDlg::GetLogicalDrives()
- {
- //get the length of drive strings not include the last terminating null character
- int nBufferLength = GetLogicalDriveStrings(0, NULL);
- //the size must plus the last terminating null character
- TCHAR* pBuffer = new TCHAR[nBufferLength + 1];
- //Get the actually DriveStrings
- GetLogicalDriveStrings(nBufferLength, pBuffer);
- TCHAR* pBegin = pBuffer;
- size_t nLength = _tcslen(pBuffer);
- while(nLength > 0)
- {
- TRACE(_T("%s\n"), pBuffer);
- pBuffer += nLength + 1;
- nLength = _tcslen(pBuffer);
- }
- delete [] pBegin;
- pBegin = NULL;
- }
- //Output:
- //C:\
- //D:\
- //E:\
- //F:\
- //G:\
- //H:\
转载于:https://blog.51cto.com/qsjming/530583