您的位置:首页 > 其它

VC 获取可执行文件的路径

2010-12-16 13:04 211 查看
c语言获取可执行文件路径

#include<direct.h>

char path[1024] = {0};

getcwd(path,sizeof(path));

获取exe文件的路径,并且将.exe的文件名替换成新的文件名

1、通过GetModuleFileName

CString filePath;

GetModuleFileName(NULL,filePath.GetBuffer(Max_PATH),MAX_PATH);

filePath.ReleaseBuffer();//获取带.exe文件名的路径

filePath=filePath.Left(filePath.ReverseFind('//')); //注意是单引号

//用双引号会报错(希望有人能解答下)

filePath+=_T("//新的文件名");

CString CProcess::GetExePath()

{

CString filePath;

GetModuleFileName(NULL,filePath.GetBuffer(255),MAX_PATH);

filePath.ReleaseBuffer();//获取带.exe文件名的路径

filePath = filePath.Left(filePath.ReverseFind('//'));

filePath += _T("//");

return filePath;

}

2、

CString filePath;

filePath=theApp.m_pszHelpFilePath;

filePath=filePath.Left(filePath.ReverseFind( '// '));

filePath+= _T("// ");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: