getdrivetype.cpp

来自「浏览所有的PCI设备」· C++ 代码 · 共 54 行

CPP
54
字号
#include "stdafx.h"

/****************************************************************************
*                                getDriveType
* Inputs:
*       LPCTSTR fullpath: Full path to some destination
* Result: UINT
*       DRIVE_ value as returned by GetDriveType
* Effect: 
*       Properly splits up the input string and figures out how to call
*       GetDriveType 
* Notes:
*	Handles the special case of \\.\name\, and a path that includes
*	a file name
****************************************************************************/

UINT getDriveType(LPCTSTR fullpath)
    {
     TCHAR drv[_MAX_PATH];
     TCHAR path[_MAX_PATH];
     TCHAR filename[_MAX_PATH];
     TCHAR ext[_MAX_PATH];

     _splitpath(fullpath, drv, path, filename, ext);
     if(lstrlen(drv) != 0)
        { /* drv */
	 return GetDriveType(drv);
	} /* drv */
     else
        { /* what else? */
	 // The trick here is that if the path starts with \\, we try 
	 // GetDeviceType. If it returns DRIVE_NO_ROOT_DIR, we call
	 // this function recursively
	 // If it does not start with \\, we return the result directly
	 UINT result = GetDriveType(path);
	 if(lstrlen(path) > 4 && path[0] == _T('\\') && path[1] == _T('\\')
                              && path[2] == _T('.') && path[3] == _T('\\'))
	    { /* \\. */
	     LPTSTR p = &path[4]; //  \\.\c
	     			  //      ^
             LPTSTR b = strchr(p, _T('\\'));
	     if(b != NULL)
		*b = _T(':');
             else
		lstrcat(p, _T(":"));
	     return GetDriveType(p);
	    } /* \\. */
	 if(lstrlen(path) < 2 || path[0] != _T('\\') || path[1] != _T('\\'))
	    return result;
         return GetDriveType(path);
	} /* what else? */
	    
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?