BOOL GetVolumeInformation( LPCTSTR lpRootPathName, // address of root directory of the // file system LPTSTR lpVolumeNameBuffer, // address of name of the volume DWORD nVolumeNameSize, // length of lpVolumeNameBuffer LPDWORD lpVolumeSerialNumber, // address of volume serial number LPDWORD lpMaximumComponentLength, // address of system's maximum // filename length LPDWORD lpFileSystemFlags, // address of file system flags LPTSTR lpFileSystemNameBuffer, // address of name of file system DWORD nFileSystemNameSize // length of lpFileSystemNameBuffer );和 UINT GetDriveType( LPCTSTR lpRootPathName // root directory );可以搞定,你自己看看msdn吧
UINT GetDriveType( LPCTSTR lpRootPathName );lpRootPathName [in] Pointer to a null-terminated string that specifies the root directory of the disk to return information about. A trailing backslash is required. If this parameter is NULL, the function uses the root of the current directory. Return Values The return value specifies the type of drive. It can be one of the following values. Value Meaning DRIVE_UNKNOWN The drive type cannot be determined. DRIVE_NO_ROOT_DIR The root path is invalid. For example, no volume is mounted at the path. DRIVE_REMOVABLE The disk can be removed from the drive. DRIVE_FIXED The disk cannot be removed from the drive. DRIVE_REMOTE The drive is a remote (network) drive. DRIVE_CDROM The drive is a CD-ROM drive. DRIVE_RAMDISK The drive is a RAM disk.
LPCTSTR lpRootPathName // root directory
);
LPCTSTR lpRootPathName, // address of root directory of the
// file system
LPTSTR lpVolumeNameBuffer, // address of name of the volume
DWORD nVolumeNameSize, // length of lpVolumeNameBuffer
LPDWORD lpVolumeSerialNumber, // address of volume serial number
LPDWORD lpMaximumComponentLength,
// address of system's maximum
// filename length
LPDWORD lpFileSystemFlags, // address of file system flags
LPTSTR lpFileSystemNameBuffer, // address of name of file system
DWORD nFileSystemNameSize // length of lpFileSystemNameBuffer
);和
UINT GetDriveType(
LPCTSTR lpRootPathName // root directory
);可以搞定,你自己看看msdn吧
LPCTSTR lpRootPathName
);lpRootPathName
[in] Pointer to a null-terminated string that specifies the root directory of the disk to return information about. A trailing backslash is required. If this parameter is NULL, the function uses the root of the current directory.
Return Values
The return value specifies the type of drive. It can be one of the following values.
Value Meaning
DRIVE_UNKNOWN The drive type cannot be determined.
DRIVE_NO_ROOT_DIR The root path is invalid. For example, no volume
is mounted at the path.
DRIVE_REMOVABLE The disk can be removed from the drive.
DRIVE_FIXED The disk cannot be removed from the drive.
DRIVE_REMOTE The drive is a remote (network) drive.
DRIVE_CDROM The drive is a CD-ROM drive.
DRIVE_RAMDISK The drive is a RAM disk.
LPCTSTR lpRootPathName
);具体查下msdn
转载人们的机器上的光驱往往不止一个,有普通的CDROM、有CDR、有DVD,还有穷人使用的虚拟光驱:)。这样一来,对于编写多媒体软件的程序员就出了个难题:如何能在软件中加入多光驱的支持。要解决这个问题,首先要学会两个API函数,其目的是获得目标电脑的光驱数。
GetLogicalDrives()
该函数功能是返回一个代表当前变量磁盘驱动器的位掩码;
该函数原型为:DWORD GetLogicalDrives(VOID);
该函数如果调用成功,返回值为一个代表当前变量磁盘驱动器的位屏蔽掩码,位的位置0为驱动器A,1为驱动器B,2为驱动器C等。如果函数调用失败,返回值为0。 举例:如果某台电脑上驱动器为A、C、D、E,则函数调用成功后的返回值是00011101,其中最低位代表驱动器A,由A存在所以该位掩码为1,而由于B不存在,所以倒数第二位掩码为0。
GetDriveType()
该函数功能是获得一个磁盘驱动器的类型;
该函数原型为:UINT GetDriveType(LPCTSTR lpRootPathName);
参数lpRootPathName:指向一个以NULL结束的指定要返回有关信息的磁盘根目录的字符串指针。如果该参数为NULL,则函数用当前根目录。
返回值:返回值返回指定驱动器的类型,它是下列值中的一个:
DRIVE_UNKNOWN 不能决定驱动器类型
DRIVE_NO_ROOT_DIR 不存在根目录
DRIVE_REMOVABLE 磁盘能从驱动器中删除
DRIVE_FIXED 磁盘不能从驱动器中删除
DRIVE_REMOTE 驱动器是一个远程(网络)驱动器
DRIVE_CDROM 驱动器是一个CDROM驱动器
DRIVE_RAMDISK 驱动器是一个RAM磁盘
举例:判断F盘是否为光驱
UINT IsCDRom;
LPCTSTR Drive;
Drive="F:\\";
IsCDRom=GetDriveType(Drive);
if (IsCDRom==DRIVE_CDROM) printf("F盘是光驱");
else printf("F盘不是光驱");
以上是两个API函数的介绍,通过这两个函数的组合,我们就可以获得光驱数。
下面简单的给出源程序:
DWORD DriveTemp; LPCTSTR DriveItem;
unsigned short DriveNum=0,itemp;
UINT IsLogicalCDROM;
int CDS=0; //光驱数
DriveTemp=GetLogicalDrives(); //获得磁盘驱动器位掩码
while(DriveTemp)` //获得驱动器数目
{
DriveTemp>>=1;
DriveNum++;
};
for(itemp=4; itemp<=DriveNum;itemp++)
{
switch(itemp)
{
case 4:
DriveItem="D:\\";
break;
case 5:
DriveItem="E:\\";
break;
case 6:
DriveItem="F:\\";
break;
case 7:
DriveItem="G:\\";
break;
...
case 26:
DriveItem="Z:\\";
}
IsLogicalCDROM=GetDriveType(DriveItem);
if (IsLogicalCDROM==DRIVE_CDROM) //获得光驱数目
{
CDName[CDS]=DriveItem;
CDS++;
}
}希望对你有所帮助
我们原来做的一个软件,没能解决这个问题,后来要求驱动厂家的SDK提供了这个功能