简体   繁体   English

可执行路径

[英]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]. 使用argv [0]似乎无效,因为该程序必须在Windows控制台上运行,例如C:\\> player parameter1 parameter2,而我只能在argv [0]上获取player。

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. 不确定“程序运行的路径”到底是什么意思……如果您是指当前的工作目录,则使用c / c ++的getcwd将获得所需的内容。

EDIT : As was also mentioned, GetModuleFileName will retrieve the actual EXE name ... see here for similar question posted on another Q&A site. 编辑 :如前所述, GetModuleFileName将检索实际的EXE名称...有关其他问题与解答网站上发布的类似问题,请参见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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