GetCurrentDirectory用于启动应用程序。 C ++ [英] GetCurrentDirectory for startup App. c++

查看:201
本文介绍了GetCurrentDirectory用于启动应用程序。 C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能显示的文件:结果
  <一href=\"http://stackoverflow.com/questions/3364589/win32-find-what-directory-the-running-process-exe-is-stored-in\">Win32:查找内容目录中运行的进程EXE存储在结果
  <一href=\"http://stackoverflow.com/questions/124886/how-to-get-the-application-executable-name-in-windows-c-win32-or-c-cli\">How在Windows(C ++的Win32或C ++ / CLI)来获取应用程序的可执行文件名称?

喜,
我想就我的statup应用程序运行,它使用了一些文件在同一directory.it工作很好,但是,当它启动时开始的GetCurrentDirectory是c:\\的Documents and Settings \\用户\\..但我想实际exe文件fil​​e.how我可以得到它在C ++中的路径。
请帮帮我。
谢谢。

i want to make my application run on statup,it uses some of files in the same directory.it works good but when it start at startup the GetCurrentDirectory is "c:\Documents and Settings\User\"..but i want the actual path of the exe file.how i can get it in c++. please help me. thanks.

推荐答案

尝试使用的 GetModuleFileName 或的 GetModuleFileNameEx

Try using GetModuleFileName or 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说:

Note I'm passing NULL as first argument, because MSDN says,

如果这个参数为NULL,
  GetModuleFileName检索路径
  当前的可执行文件的
  过程。

"If this parameter is NULL, GetModuleFileName retrieves the path of the executable file of the current process."

这是你想要的。对吧?

这篇关于GetCurrentDirectory用于启动应用程序。 C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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