可能重复:
Win32:查找正在运行的进程EXE所在的目录
如何在Windows(C ++ Win32或C ++ / CLI)中获取应用程序可执行文件名?
嗨,我想让我的应用程序在statup上运行,它使用同一个目录中的一些文件。它运行良好但是当它在启动时启动时,GetCurrentDirectory是“c: Documents and Settings User ”..但我想要exe文件的实际路径。我可以用c ++获取它。 请帮我。 谢谢。
尝试使用GetModuleFileName
或GetModuleFileNameEx
。
做这个:
wchar_t exeDirectory[1024]; //to store the directory DWORD ret = GetModuleFileName(NULL, exeDirectory, 1024); if ( ret ) { /*the path to your EXE is stored in the variable "exeDirectory" - use it */ }
注意我作为第一个参数传递NULL,因为MSDN说,
“如果此参数为NULL,则GetModuleFileName将检索当前进程的可执行文件的路径。”
这就是你想要的。 对?
使用argv可能:
int main(int argc, char* argv[]) { // argv[0] is the path to binary file you're running // ... return 0; }
利润是这种方法独立于平台,不需要任何系统调用。
以上就是c/c++开发分享用于启动App的GetCurrentDirectory。 c ++相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/522516.html