获得U盘的信息,直接代码:
INT GetUDiskInfo(void)
{
CString szUDiskRoot;
UINT unDiskType;
size_t nAllDriverStr=GetLogicalDriveStringsW(0,NULL);
TCHAR *pDriverStr=new TCHAR[nAllDriverStr+sizeof(_T(""))];
TCHAR *pSavePoint=pDriverStr;
GetLogicalDriveStringsW(nAllDriverStr,pDriverStr);
size_t nSize=_tcslen(pDriverStr);
while (nSize>0)
{
unDiskType=GetDriveTypeW(pDriverStr);
switch (unDiskType)
{
case DRIVE_NO_ROOT_DIR:
break;
case DRIVE_REMOVABLE:
szUDiskRoot=pDriverStr;
//AfxMessageBox(szUDiskRoot);
case DRIVE_FIXED:
break;
case DRIVE_REMOTE:
break;
case DRIVE_CDROM:
break;
}
pDriverStr += (nSize + 1)*sizeof(_T(""));
nSize=_tcslen(pDriverStr);
}
delete []pSavePoint;
DWORD nVolumeNameSize = _MAX_FNAME;
LPTSTR lpVolumeNameBuffer = new TCHAR[_MAX_FNAME];
DWORD nVolumeSerialNumber = 0;
DWORD nMaximumComponentLength;
DWORD nFileSystemFlags;
LPTSTR lpFileSystemNameBuffer = new TCHAR[40];
GetVolumeInformationW(szUDiskRoot,lpVolumeNameBuffer,nVolumeNameSize,&nVolumeSerialNumber,&nMaximumComponentLength,&nFileSystemFlags,lpFileSystemNameBuffer,40);
delete[]lpVolumeNameBuffer;
delete[]lpFileSystemNameBuffer;
return 0;
}