DVD

Acest forum este dedicat intrebarilor de Windows API, folosing C/C++
Post Reply
User avatar
Zeros
Membru
Membru
Posts: 54
Joined: 12 Jul 2007, 12:34
Location: Waslooy

DVD

Post by Zeros » 12 Jul 2007, 13:09

Cum pot afla la ce litera A: B: etc e unitatea mea de DVD?
Cu API bineiteles nu uitandu-ma in explorer :mrgreen:



User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3778
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: DVD

Post by Ovidiu Cucu » 12 Jul 2007, 16:49

Sorry pentru intarziere... dar erau ceva mai multe de "povestit".
In primul rand, daca te intereseaza numai daca drive-ul e de tip CDROM (CD sau DVD) ai la indemana si foarte usor de folosit GetDriveType.
Exemplu:

Code: Select all

BOOL IsCDRomDrive(char chDrive)
{
   CString strDrive;
   strDrive.Format(_T("%c:\\"), chDrive);
   return (DRIVE_CDROM == ::GetDriveType(strDrive));
}
Aditional, o functie de "cautare" ar arata cam asa:

Code: Select all

bool FindFirstCDRomDrive(char& chDrive)
{
   bool bFound = false;
   for(chDrive = 'D'; chDrive <= 'Z'; chDrive++)
   {
      if(IsCDRomDrive(chDrive))
      {
         bFound = true;
         break;
      }
   }
   return bFound;
}
Ai mai putea "rafina" functia de mai sus folosind GetLogicalDrives dar nu cred ca merita "efortul".

Acuma, daca musa-i sa gasim DVD-ul, GetDriveType nu face distinctie intre CD si DVD.
Scaparea e sa folosesti DeviceIoControl care-i un pic mai nashpa:

Code: Select all

bool IsDVDDrive(char chDrive)
{
   bool bIsDVD = false;
   
   CString strDrive;
   strDrive.Format(_T("\\\\.\\%c:"), chDrive);
   HANDLE hDevice = ::CreateFile(strDrive, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
   if(INVALID_HANDLE_VALUE != hDevice)
   {
      LPBYTE pBuffer = new BYTE[512];
      DWORD dwReturned = 0;
      
      if(::DeviceIoControl(hDevice, IOCTL_STORAGE_GET_MEDIA_TYPES_EX, NULL, 0, pBuffer, 512, 
                                                                    &dwReturned, NULL))
      {
         PGET_MEDIA_TYPES pGmt = (PGET_MEDIA_TYPES)pBuffer;
         if(FILE_DEVICE_DVD == pGmt->DeviceType) 
            bIsDVD = true;
      }
      delete []pBuffer;
      ::CloseHandle(hDevice);
   }
   return bIsDVD;
}
[ Rog nu criticati modul cum e scrisa functia. Nu handluieste erorile doar pentru a fi mai usor de prins "ideea" ]

User avatar
Zeros
Membru
Membru
Posts: 54
Joined: 12 Jul 2007, 12:34
Location: Waslooy

Re: DVD

Post by Zeros » 15 Jul 2007, 01:32

Merge!
Multumesc!
Am folosit si GetLogicalDrives :thumbup:
V-am pupat! :-)

Post Reply