VC中获取当前exe文件运行路径
2009-07-13 17:36
447 查看
一、
TCHAR szFilePath[MAX_PATH + 1];
GetModuleFileName(NULL, szFilePath, MAX_PATH);
(_tcsrchr(szFilePath, _T('//')))[1] = 0;//删除文件名,只获得路径
CString str_url = szFilePath;
AfxMessageBox(str_url);
二、
String
path=AfxGetApp()->m_pszHelpFilePath;
String
str=AfxGetApp()->m_pszExeName;
path=path.Left(path.GetLength()-str.GetLength()-4);
三、
//Get Run-directory
TCHAR szLongPathName[_MAX_PATH];
GetModuleFileName(NULL, szLongPathName, _MAX_PATH);
RunDir = szLongPathName;
int nPos = RunDir.ReverseFind('//');
if(nPos != -1) RunDir = RunDir.Left(nPos+1);
if(RunDir.IsEmpty()){
char szPath[144];
GetCurrentDirectory(144,szPath);
strcat(szPath,"//"); RunDir=szPath;
}
四、
#include < windows.h
>
#include < string.h
>
HINSTANCE hInst;
char szBuf[256];
char *p;
GetModuleFileName(hInst,szBuf,sizeof(szBuf));//拿到全部路径
p = szBuf;
while(strchr(p,'//')) //分离路径和文件名。
{
p
= strchr(p,'//');
p++;
}
*p = '/0'; //路径在szBuf理了
TCHAR szFilePath[MAX_PATH + 1];
GetModuleFileName(NULL, szFilePath, MAX_PATH);
(_tcsrchr(szFilePath, _T('//')))[1] = 0;//删除文件名,只获得路径
CString str_url = szFilePath;
AfxMessageBox(str_url);
二、
String
path=AfxGetApp()->m_pszHelpFilePath;
String
str=AfxGetApp()->m_pszExeName;
path=path.Left(path.GetLength()-str.GetLength()-4);
三、
//Get Run-directory
TCHAR szLongPathName[_MAX_PATH];
GetModuleFileName(NULL, szLongPathName, _MAX_PATH);
RunDir = szLongPathName;
int nPos = RunDir.ReverseFind('//');
if(nPos != -1) RunDir = RunDir.Left(nPos+1);
if(RunDir.IsEmpty()){
char szPath[144];
GetCurrentDirectory(144,szPath);
strcat(szPath,"//"); RunDir=szPath;
}
四、
#include < windows.h
>
#include < string.h
>
HINSTANCE hInst;
char szBuf[256];
char *p;
GetModuleFileName(hInst,szBuf,sizeof(szBuf));//拿到全部路径
p = szBuf;
while(strchr(p,'//')) //分离路径和文件名。
{
p
= strchr(p,'//');
p++;
}
*p = '/0'; //路径在szBuf理了
相关文章推荐
- VC中获取当前exe文件运行路径
- vs中获取当前exe文件运行路径几种方法
- 在Linux下获取当前运行程序可执行文件全路径(不使用real_path()函数)
- VC获取当前程序文件的路径,文件名以及路径+文件名
- vc 获取程序版本号,当前程序路径,文件修改时间 等
- VC获取当前程序文件的路径,文件名以及路径+文件名
- 获取当前python正在运行的文件的路径
- C/C++获取相对当前启动路径(.exe)下的文件全路径名
- C#(WPF)程序将Debug中的.exe文件放入注册表中启动,获取错误的当前路径--解决方案
- VC获取当前文件路径---比较
- 使用VC++获取文件路径,已获取当前路径为基础
- 关于VC获取当前程序运行路径的几种方法
- C#(WPF)程序将Debug中的.exe文件放入注册表中启动,获取错误的当前路径--解决方案
- 在指定路径创建文件夹, 获取EXE文件的当前目录
- vc下 获取工程exe文件的相对路径
- VC获取当前程序文件的路径,文件名以及路径+文件名
- Linux下获取当前进程的执行文件的绝对路径和所在目录(通过/proc/self/exe链接)
- [VB.NET]如何改变当前exe文件的运行路径?
- [转]VC获取当前程序文件的路径,文件名以及路径+文件名
- vc 获取程序版本号,当前程序路径,文件修改时间 等