如何获取应用程序安装目录 [英] How to get Application Installation Directory

查看:88
本文介绍了如何获取应用程序安装目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要获取应用程序安装目录的绝对路径.有什么方法可以得到它吗?

如果我是正确的,则:: GetCurrentDirectory不会这样做,因为如果我从cmd行或其他应用程序中调用该应用程序的exe;它失败. _getcwd()也是如此
问候,
Shishir

Hi,

I need to get the absolute path of the application installation directory. Is there any method to obtain it ?

If I am correct, ::GetCurrentDirectory won''t do because if I am calling the exe of the application from cmd line or another application; it fails. same goes with _getcwd()

Regards,
Shishir

推荐答案

GetModuleFileName是您所需要的.


使用GetModuleFileName函数(Windows) [PathRemoveFileSpec函数(Windows) [
Use the GetModuleFileName Function (Windows)[^] to get the full pathname of the application executable, then use the PathRemoveFileSpec Function (Windows)[^] to remove the trailing file name and backslash from that path, as shown below:

TCHAR szFilename[MAX_PATH];
VERIFY(GetModuleFileName(NULL, szFilename, MAX_PATH) < MAX_PATH);
VERIFY(PathRemoveFileSpec(szFilename));


感谢您的回复.我会尝试的.
Thanks for the reply. I will try it out.


这篇关于如何获取应用程序安装目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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