问题描述
首先,我想说的是我不是指完整的路径,
GetModuleFileName或argv [0] yield。是否有一个更聪明的解决方案,而不是在最后一个反斜杠之前关闭一切?
Firstly, I would like to say that I don't mean the full path, what
GetModuleFileName or argv[0] yield. Is there a smarter solution than dismissing everything before the last backslash?
推荐答案
首先,您想要获取可执行文件的完整路径,方法是调用传递 NULL
作为模块句柄。然后调用
First of all you want to get hold of the full path to the executable by calling
GetModuleFileName
passing NULL
as the module handle. Then call PathFindFileName
to pull out the file name component.
。后者是用于启动进程的名称。它可能缺少完整的路径,但更重要的是,在这里,它可能会缺少 GetModuleFileName
和 argv [0] .exe
扩展。如果你想知道实际的文件名,那么你需要使用 GetModuleFileName
。
There is in fact a difference between
GetModuleFileName
and argv[0]
. The latter is the name used to start the process. It could be missing the full path, but more importantly here, it could be missing the .exe
extension. If you want to know the actual filename then you need to use GetModuleFileName
.
这篇关于提取当前可执行文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!