Windows API 第19篇 FindFirstVolumeMountPoint FindNextVolumeMountPoint

相关函数:
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也会返回有效句柄了

转载于:https://www.cnblogs.com/priarieNew/p/9755437.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值