提取当前可执行文件名 [英] Extracting the current executable name

查看:123
本文介绍了提取当前可执行文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我想说的是我不是指完整的路径,

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?

推荐答案

首先,您想要获取可执行文件的完整路径,方法是调用 GetModuleFileName 传递 NULL 作为模块句柄。然后调用 PathFindFileName

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.

这篇关于提取当前可执行文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆