How can I calculate the complete buffer size for GetModuleFileName?

后端 未结 8 2059
花落未央
花落未央 2020-12-17 17:08

The GetModuleFileName() takes a buffer and size of buffer as input; however its return value can only tell us how many characters is has copied, and if the size is not enoug

8条回答
  •  星月不相逢
    2020-12-17 17:45

    Using

    extern char* _pgmptr
    

    might work.

    From the documentation of GetModuleFileName:

    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.

    But if I read about _pgmptr:

    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.

    Anyone who knows how _pgmptr is initialized? If SO had support for follow-up questions I would posted this question as a follow up.

提交回复
热议问题