相关函数:
HANDLE FindFirstVolumeMountPoint(
LPTSTR lpszRootPathName, // volume name
LPTSTR lpszVolumeMountPoint, // output buffer
DWORD cchBufferLength // size of output buffer
);
BOOL FindNextVolumeMountPoint(
HANDLE hFindVolumeMountPoint, // search handle
LPTSTR lpszVolumeMountPoint, // output buffer
DWORD cchBufferLength // size of output buffer
);
BOOL FindVolumeMountPointClose(
HANDLE hFindVolumeMountPoint // search handle
);
说明:
这几个函数都是与驱动器挂载点操作相关的,关于挂载点就不多介绍了,可以在磁盘管理中,选择更改驱动器号和路径里设置,设置后自己看看效果就理解挂载点的意思了。
这三个函数的使用和FindFirstVolume, FindNextVolume, FindVolumeClose函数的使用差不多,而这里用FindFirstVolume函数找到的卷名恰好可以做为FindFirstVolumeMountPoint的第一个参数,
所以他们可以一起使用,不过我测试过直接拿诸如“C:\\”的参数传到FindFirstVolumeMountPoint的第一个参数里也是可以成功的。
下面写一个测试代码:
int _tmain(int argc, _TCHAR* argv[])
{
CHAR szVolumeName[MAX_PATH] = { 0 };
CHAR szVolumeMountPoint[MAX_PATH] = { 0 };
HANDLE hVolume;
HANDLE hVolumeMountPoint;
//查找第一个驱动器名字
hVolume = FindFirstVolumeA(szVolumeName, MAX_PATH);
if (INVALID_HANDLE_VALUE == hVolume)
return 0;
printf("%s \n", szVolumeName);
//根据名字找挂载点
hVolumeMountPoint = FindFirstVolumeMountPointA(szVolumeName, szVolumeMountPoint, MAX_PATH);
if (INVALID_HANDLE_VALUE == hVolumeMountPoint)
{
FindVolumeClose(hVolume);
return 0;
}
while (FindNextVolumeMountPointA(hVolumeMountPoint, szVolumeMountPoint, MAX_PATH))
{
printf("%s \n", szVolumeMountPoint);
}
while (FindNextVolumeA(hVolume, szVolumeName, MAX_PATH))
{
printf("%s \n", szVolumeName);
hVolumeMountPoint = FindFirstVolumeMountPointA(szVolumeName, szVolumeMountPoint, MAX_PATH);
do
{
if (INVALID_HANDLE_VALUE == hVolumeMountPoint)
{
break;
}
printf("%s \n", szVolumeMountPoint);
}
while (FindNextVolumeMountPointA(hVolumeMountPoint, szVolumeMountPoint, MAX_PATH));
}
FindVolumeClose(hVolume);
FindVolumeMountPointClose(hVolumeMountPoint);
}
分析:一般我们的机上子没有挂载点,所以上面的程序找不到挂载点,只能看到GetFirstVolume函数有返回值。不过可以手动设置挂载点,只要你设置挂载点后就会看到GetFirstVolumeMountPoint也会返回有效句柄了