'GetFullPathNameA Returns Project's Path

When I tried the following code:

char pathStr[MAX_PATH];
DWORD pathLen = GetFullPathNameA("notepad++.exe", MAX_PATH, pathStr, NULL);

I got in "pathStr" the current directory's path with the "notepad++.exe" at the end of it instead of the real path of the file... Am I missing something here?



Solution 1:[1]

You have misunderstood what the function is for. The Microsoft documentation (https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfullpathnamea) for the function states:

GetFullPathName merges the name of the current drive and directory with a specified file name to determine the full path and file name of a specified file.

You could try the SearchPath function (https://docs.microsoft.com/en-us/windows/win32/api/processenv/nf-processenv-searchpatha) to try to find an executable within the current search path from just the filename.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tinman