Here is my code snippet:
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);
}
However, existingTarget
is coming out to be \\?\C:\mydir\etc
. How can I get it to return just C:\mydir\etc
?
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.
how can I get it to return just C:\mydir\etc
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.
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.
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()
.