获取我的exe&ŧ039;目录。WinBase API

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取我的exe&ŧ039;目录。WinBase API相关的知识,希望对你有一定的参考价值。

Determine directory where the .exe is running from. Usually it's CWD - but not always, such as MsiExec Custom Actions.

Windows. non-dot.net, with or without MFC.
  1. CString sThisDir; // in atlstr.h
  2.  
  3.  
  4. ::GetModuleFileName( // In WinBase.h.
  5. 0, // retrieve path of .exe file for the current process.
  6. sThisDir.GetBufferSetLength(MAX_PATH),
  7. MAX_PATH);
  8.  
  9. sThisDir.Truncate( sThisDir.ReverseFind('\') + 1 ); // Chop off the app.exe portion.
  10.  
  11.  
  12. // Alternative to create a myApp.ini file name:
  13.  
  14. CString thisExe; // in atlstr.h
  15.  
  16. ::GetModuleFileName( // In WinBase.h.
  17. 0, // retrieve path of .exe file for the current process.
  18. thisExe.GetBufferSetLength(MAX_PATH),
  19. MAX_PATH);
  20.  
  21. thisExe.Truncate( thisExe.ReverseFind('.') ); // Chop off the .exe.
  22.  
  23. CString iniFile = thisExe;
  24. iniFile.Append( ".ini" ); // Replace .exe with .ini.
  25.  
  26. // I didn't use CString::Replace because there could be multiple embedded ".exe" in the path.
  27. // I found that Vista wanted to store INIs in the Windows directory rather than the CWD.

以上是关于获取我的exe&ŧ039;目录。WinBase API的主要内容,如果未能解决你的问题,请参考以下文章

使用两个表的并集获取Count&ŧ039;s

从Google&ŧ039;的CDN获取jQuery库如果失败,则拉取本地版本

从命令行通过dbus获取exail&ŧ039;的当前歌曲

检索给定年份的所有&ŧ039;星期一&ŧ039;的。

Bresenham&ŧ039;s线算法

检查是否安装了Apache&ŧ039;的modŧu rewrite。