简体   繁体   中英

Executable path

I need to find the path of where my program is running. Using argv[0] doesn't seem to work because the program has to be run on the windows console, for example, C:\\ >player parameter1 parameter2 and I only get player on argv[0].

How can I accomplish this?

您可以通过将hModule参数设置为NULL来使用Windows的GetModuleFileName函数来获取可执行文件的路径。

Not sure exactly what you mean by "path of where my program is running" ... if you mean the current working directory, getcwd in c/c++ would get you what you want.

EDIT : As was also mentioned, GetModuleFileName will retrieve the actual EXE name ... see here for similar question posted on another Q&A site.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM