• 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 
    ", szVolumeName);
            //根据名字找挂载点
    	hVolumeMountPoint = FindFirstVolumeMountPointA(szVolumeName, szVolumeMountPoint, MAX_PATH);
    	if (INVALID_HANDLE_VALUE == hVolumeMountPoint)
    	{
    		FindVolumeClose(hVolume);
                    return 0;
    	}
    	while (FindNextVolumeMountPointA(hVolumeMountPoint, szVolumeMountPoint, MAX_PATH))
    	{
    		printf("%s 
    ", szVolumeMountPoint);
    	}
    
    	
    	while (FindNextVolumeA(hVolume, szVolumeName, MAX_PATH))
    	{
    		printf("%s 
    ", szVolumeName);
    
    		hVolumeMountPoint = FindFirstVolumeMountPointA(szVolumeName, szVolumeMountPoint, MAX_PATH);
    		do
    		{
    			if (INVALID_HANDLE_VALUE == hVolumeMountPoint)
    			{
    				break;
    			}
    
    			printf("%s 
    ", szVolumeMountPoint);
    		}
    		while (FindNextVolumeMountPointA(hVolumeMountPoint, szVolumeMountPoint, MAX_PATH));
    	}
    	FindVolumeClose(hVolume);
    	FindVolumeMountPointClose(hVolumeMountPoint);
    }
    

     分析:一般我们的机上子没有挂载点,所以上面的程序找不到挂载点,只能看到GetFirstVolume函数有返回值。不过可以手动设置挂载点,只要你设置挂载点后就会看到GetFirstVolumeMountPoint也会返回有效句柄了

  • 相关阅读:
    6 docker-harbor仓库搭建
    4 dockerfile介绍及其实例应用
    1 docker 介绍和安装
    2 docker镜像
    PAT甲级1075 PAT Judge
    PAT甲级1139 First Contact【离散化】
    PAT甲级1055 The World's Richest【排序】
    PAT甲级1013-1014-1015
    洛谷P1135 奇怪的电梯【bfs】
    洛谷P1182 数列分段【二分】【贪心】
  • 原文地址:https://www.cnblogs.com/priarieNew/p/9755437.html
Copyright © 2020-2023  润新知