• 1400阅读
  • 2回复

DosPath与NtPath的转换(搞驱动的经常能用到的) [复制链接]

上一主题 下一主题
离线天道酬勤
 

只看楼主 倒序阅读 使用道具 楼主  发表于: 2016-03-04
BOOL DosPathToNtPath(LPTSTR pszDosPath, LPTSTR pszNtPath)

{
    TCHAR           szDriveStr[500];
    TCHAR           szDrive[3];
    TCHAR           szDevName[100];
    INT             i;
    INT             cchDosName;
    //检查参数  
    if (!pszDosPath || !pszNtPath)
        return FALSE;


    //获取本地磁盘字符串  
    if (GetLogicalDriveStrings(sizeof(szDriveStr), szDriveStr))
    {
        for (i = 0; szDriveStr; i += 4)
        {
            if (!lstrcmpi(&(szDriveStr), _T("A:\\")) || !lstrcmpi(&(szDriveStr), _T("B:\\")))
                continue;


            szDrive[0] = szDriveStr;
            szDrive[1] = szDriveStr[i + 1];
            szDrive[2] = '\0';
            if (!QueryDosDevice(szDrive, szDevName, 100))//查询 Dos 设备名  
                return FALSE;


            cchDosName = lstrlen(szDrive);
            if (_tcsnicmp(pszDosPath, szDrive, cchDosName) == 0)//命中
            {
                lstrcpy(pszNtPath, szDevName);
                lstrcat(pszNtPath, pszDosPath + cchDosName);//复制路径
                return TRUE;
            }
        }
    }


    lstrcpy(pszNtPath, pszDosPath);


    return FALSE;
}


BOOL NtPathToDosPath(LPTSTR pszDosPath, LPTSTR pszNtPath)
{
    TCHAR           szDriveStr[500];
    TCHAR           szDrive[3];
    TCHAR           szDevName[100];
    INT             cchDevName;
    INT             i;


    //检查参数  
    if (!pszDosPath || !pszNtPath)
        return FALSE;


    //获取本地磁盘字符串  
    if (GetLogicalDriveStrings(sizeof(szDriveStr), szDriveStr))
    {
        for (i = 0; szDriveStr; i += 4)
        {
            if (!lstrcmpi(&(szDriveStr), _T("A:\\")) || !lstrcmpi(&(szDriveStr), _T("B:\\")))
                continue;


            szDrive[0] = szDriveStr;
            szDrive[1] = szDriveStr[i + 1];
            szDrive[2] = '\0';
            if (!QueryDosDevice(szDrive, szDevName, 100))//查询 Dos 设备名  
                return FALSE;


            cchDevName = lstrlen(szDevName);
            _DbgPrint("%s %s %d", pszDosPath, szDevName, cchDevName);
            if (_tcsnicmp(pszDosPath, szDevName, cchDevName) == 0)//命中  
            {
                _DbgPrint("命中了\n");
                lstrcpy(pszNtPath, szDrive);//复制驱动器  
                lstrcat(pszNtPath, pszDosPath + cchDevName);//复制路径  


                return TRUE;
            }
            else
            {
                _DbgPrint("没有命中\n");
            }
        }
    }


    lstrcpy(pszNtPath, pszDosPath);


    return FALSE;
}

离线v2680267313

只看该作者 沙发  发表于: 2016-04-30
用户被禁言,该主题自动屏蔽!
离线qq1156136807

只看该作者 板凳  发表于: 2017-12-29
快速回复
限100 字节
如果您在写长篇帖子又不马上发表,建议存为草稿
 
上一个 下一个