文章类型: VC&C++
关键词: VC中获取当前exe文件运行路径,VC++,经验总结
内容摘要: VC中获取当前exe文件运行路径

VC中获取当前exe文件运行路径

2017/5/9 15:59:30    来源:apple    阅读:

一、


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++ 6.0 Build配置中没有Release的解决办法 关键词:VC++,6.0,Build配置中没有Release的解.. 发布日期:2017/5/9 14:46:46
↓ 下一篇文章:eclipse问题 import java.io cannot be resolved 关键词:eclipse问题,import,java.io,can.. 发布日期:2017/5/10 14:35:27
相关文章:
VC++中将CString转换成const char*的一种有效方法 关键词:VC++,CString,转换,const,char 发布日期:2016-09-23 15:26
vc++ C函数atoi和itoa的用法总结 关键词:vc++,C函数,atoi,itoa,用法,总结,integer,string,signal,语言 发布日期:2017-09-26 17:32
VC++中delete和delete[] 的区别 关键词:VC++,delete,delete【】,区别 发布日期:2017-08-30 14:56
相关目录:.NETVC&C++软件开发
我要评论
正在加载评论信息......