2
votes

What difference is there (if any) between these two? MSDN is very unclear.

Here it sounds like they are equivalent: https://msdn.microsoft.com/en-us/library/windows/desktop/ms683197%28v=vs.85%29.aspx

But here it sounds like _pgmptr may not always give me a full path, but it doesn't really explain under what circumstances. https://msdn.microsoft.com/en-us/library/tza1y5f7.aspx

_pgmptr Seems far more attractive to me because I don't have to play buffer size guessing games with it.

2
_pgmptr, _wpgmptr: "When a program is not run from the command line, _pgmptr might be initialized to the program name (the file's base name without the file name extension) or to a file name, relative path, or full path." Does that not explicitly name the circumstances? - IInspectable
No it does not. "Might be" is literally not explicit. - BigSandwich
As far as documentation goes, you won't get any more explicit than this: When a program is not run from the command line, _wpgmptr may not contain a full path. If you don't care about contracts, and would rather develop against a particular implementation, you can dive right into reading the CRT source. - IInspectable
@BigSandwich MSDN documentation is often contradictory :) - Jonathan Potter
@BigSandwich: note that you do not need a buffer to use _get_pgmptr so that should be your preferred method. (It doesn't copy the string into a buffer you provide, it copies a pointer to the string into a pointer you provide.) - Harry Johnston

2 Answers

3
votes

_pgmptr is initialised using GetModuleFileName internally, so the answer is there's no difference - they will return the same string.

3
votes

There at least one difference: _get_pgmptr() isn't available early in an application initialization, whilst GetModuleFileName() is. I've just been bitten by the Static Initialization Order Fiasco because of this :(