zoukankan      html  css  js  c++  java
  • 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也会返回有效句柄了

  • 相关阅读:
    20120621第一天_复习与测试\05方法
    20120621第一天_复习与测试
    转义字符符号及对应的含义
    如何判断一个窗体是否打开
    out 和ref 的小结
    20120621第一天_复习与测试\03循环控制
    详解C#break ,continue, return
    往xptable控件中添加数据
    校内网的设计。
    iPhone不再孤独,Palm Pre为伴——互联网的未来在手中。
  • 原文地址:https://www.cnblogs.com/priarieNew/p/9755437.html
Copyright © 2011-2022 走看看