GetFinalPathNameByHandle() 结果不带 '\\?\' [英] GetFinalPathNameByHandle() result without prepended '\\?\'
问题描述
这是我的代码片段:
char existingTarget[MAX_PATH];
HANDLE hFile = CreateFile(linkPath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (INVALID_HANDLE_VALUE != hFile)
{
GetFinalPathNameByHandle(hFile, existingTarget, MAX_PATH, FILE_NAME_OPENED);
CloseHandle(hFile);
}
然而,existingTarget
会变成 \\?\C:\mydir\etc
.我怎样才能让它只返回 C:\mydir\etc
?
However, existingTarget
is coming out to be \\?\C:\mydir\etc
. How can I get it to return just C:\mydir\etc
?
注意:我不想检查字符串 \\?\
而只是 memmove
它,这有点太hackish此程序的解决方案.
Note: I don't want to check for the string \\?\
and just memmove
it, it's a bit too hackish of a solution for this program.
推荐答案
我怎样才能让它只返回 C:\mydir\etc
how can I get it to return just C:\mydir\etc
你不能.VOLUME_NAME_DOS
和 VOLUME_NAME_GUID
总是 使用这种格式,并记录如下:
You cannot. VOLUME_NAME_DOS
and VOLUME_NAME_GUID
always use that format, and is documented as such:
此函数返回的字符串使用 \\?\
语法.
The string that is returned by this function uses the
\\?\
syntax.
See the example results in the Community Additions section of the documentation.
注意:我不想检查字符串 \\?\
并且只是记住它,它对于这个程序的解决方案有点太hackish了.
Note: I don't want to check for the string
\\?\
and just memmove it, its a bit too hackish of a solution for this program.
这是最简单的解决方案.否则,您必须使用其他 API 将返回的路径转换为更易读的路径.例如将 VOLUME_NAME_NT
的结果与 QueryDosDevice()
,或使用 VOLUME_NAME_GUID
的结果和 GetVolumePathNamesForVolumeName()
.
That is the easiest solution. Otherwise, you have to use other APIs to translate the returned path into a more human-readable path. Such as using the result of VOLUME_NAME_NT
with QueryDosDevice()
, or using the result of VOLUME_NAME_GUID
with GetVolumePathNamesForVolumeName()
.
这篇关于GetFinalPathNameByHandle() 结果不带 '\\?\'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!