Windows下磁盘相关操作:
1. 使用FindFirstVolume, FindNextVolume查询所有磁盘;
2. QueryDosDevice获取设备名称;
3. GetVolumePathNamesForVolumeName获取路径信息,如C:, D:;
4. GetDriveType获取磁盘类型,不同返回值代表的类型如下图:
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
void GetVolumePaths(
__in PWCHAR VolumeName,
__out PWCHAR VolumaPath
)
{
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;
}
//
//