有五个基本的函数:GetLogicalDrives, GetLogicalDriveStrings, GetDriveType , GetVolumeInformation, SetVolumeLabel . 下面分别说下:
1 GetLogicalDrives
DWORD WINAPI GetLogicalDrives(void);
Retrieves a bitmask (位掩码)representing the currently available disk drives. If the function fails, the return value is zero
0位表示A盘,1位表示B盘, 2位表示C盘,以此类推. 我电脑上运行, 返回值是124 ,124转二进制1111100,所以有C ,D, E,F,G五个盘符
2 GetLogicalDriveStringsW
DWORD WINAPI GetLogicalDriveStrings( _In_ DWORD nBufferLength, _Out_ LPTSTR lpBuffer);
以char array 的方式返回盘符信息, 格式是"C:\\<NULL>D:\<NULL>E:\<NULL><NULL>"
注意 :必须用LPTSTR数组接收返回信息,不能用CString . 如果用CString只能接收第一个<NULL>之前的信息.
CStringList ValumeList;
TCHAR buf[100];
CString strDriverList;
LPCTSTR lpRootPathName=TEXT("c:\\"); //取C盘
LPTSTR lpVolumeNameBuffer= new WCHAR[12];//磁盘卷标
DWORD nVolumeNameSize=