cprogrammer
cprogrammer

Reputation: 5675

GetModuleFileName returns path in 8.3 format

I call this function to get path to exe. GetModuleFileName(NULL, ... The problem is that sometimes it returns the short path (8.3) instead of a normal long path.

MSDN specifies that

The string returned will use the same format that was specified when the module was loaded. Therefore, the path can be a long or short file name, and can use the prefix "\\?\".

How can I avoid this behavior and force Api to return full path ?

Upvotes: 3

Views: 2465

Answers (2)

Erik
Erik

Reputation: 91270

You cannot avoid it - if the dll is loaded with a short name, that's what you get.

Use GetLongPathName to convert if needed.

Upvotes: 4

Yakov Galka
Yakov Galka

Reputation: 72479

You cannot. Use GetFullPathName to get the full path.

See also the Remarks section in the page you linked to:

The global variable _pgmptr is automatically initialized to the full path of the executable file, and can be used to retrieve the full path name of an executable file.

Upvotes: 1

Related Questions