//NTPath 转 DosPath
BOOL NtPathToDosPath(LPTSTR pszDosPath, LPTSTR pszNtPath)
{
_TCHAR tzDevName[MAX_PATH] = { 0 };
_TCHAR tzDrive[4] = { 0 };
//检查参数
if (!pszDosPath || !pszNtPath)
{
return FALSE;
}
if ((*pszNtPath) >= _T('C') && (*pszNtPath) <= _T('Z'))
{
memset(tzDrive, 0, sizeof(tzDrive));
_tcsncpy(tzDrive, pszNtPath, sizeof(WORD));
if (!QueryDosDevice(tzDrive, tzDevName, MAX_PATH))//查询设备名,这里是重点
{
return FALSE;
}
_stprintf_s(pszDosPath, MAX_PATH, _T("%s%s"), tzDevName, pszNtPath + sizeof(WORD));
return TRUE;
}
_stprintf_s(pszDosPath, MAX_PATH, _T("%s"), pszNtPath);
return FALSE;
}
//DosPath 转 NTPath
BOOL DosPathToNtPath(LPTSTR pszNtPath, LPTSTR pszDosPath)
{
_TCHAR tzDriveStrings[MAX_PATH] = { 0 };
_TCHAR tzDevName[MAX_PATH] = { 0 };
_TCHAR tzDrive[4] = { 0 };
//检查参数
if (!pszDosPath || !pszNtPath)
{
return FALSE;
}
//获取本地磁盘字符串
if (GetLogicalDriveStrings(sizeof(tzDriveStrings)/sizeof(*tzDriveStrings), tzDriveStrings))
{
for (auto nIndex = 0; tzDriveStrings[nIndex]; nIndex += sizeof(tzDrive) / sizeof(*tzDrive))
{
if (tzDriveStrings[nIndex] >= _T('C') && tzDriveStrings[nIndex] <= _T('Z'))
{
memset(tzDrive, 0, sizeof(tzDrive));
_tcsncpy(tzDrive, &tzDriveStrings[nIndex], sizeof(WORD));
if (!QueryDosDevice(tzDrive, tzDevName, MAX_PATH))//查询 Dos 设备名
{
return FALSE;
}
if (!_tcsnicmp(pszDosPath, tzDevName, _tcslen(tzDevName)))//命中
{
_stprintf_s(pszNtPath, MAX_PATH, _T("%s%s"), tzDrive, pszDosPath + _tcslen(tzDevName));
return TRUE;
}
}
}
}
_stprintf_s(pszNtPath, MAX_PATH, _T("%s"), pszDosPath);
return FALSE;
}