Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<DeviceInfos.h>
- QString DisplayVolumePaths( PWCHAR VolumeName )
- {
- DWORD CharCount = MAX_PATH + 1;
- PWCHAR Names = NULL;
- PWCHAR NameIdx = NULL;
- BOOL Success = FALSE;
- for (;;)
- {
- //
- // Allocate a buffer to hold the paths.
- Names = (PWCHAR) new BYTE [CharCount * sizeof(WCHAR)];
- if ( !Names )
- {
- //
- // If memory can't be allocated, return.
- return "memory can't be allocated";
- }
- //
- // Obtain all of the paths
- // for this volume.
- Success = GetVolumePathNamesForVolumeNameW(
- VolumeName, Names, CharCount, &CharCount
- );
- if ( Success )
- {
- qDebug()<<"GetVolumePathNamesForVolumeNameW succeed count"<<CharCount;
- break;
- }
- qDebug()<<"GetVolumePathNamesForVolumeNameW failed count"<<CharCount<<" error "<<GetLastError();
- if ( GetLastError() != ERROR_MORE_DATA )
- {
- break;
- }
- //
- // Try again with the
- // new suggested size.
- delete [] Names;
- Names = NULL;
- }
- if ( Success )
- {
- //
- // Display the various paths.
- for ( NameIdx = Names;
- NameIdx[0] != L'