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("// ");
本文介绍了两种在Windows环境下获取可执行文件(.exe)路径的方法:一是使用GetModuleFileName函数直接获取;二是通过特定字符串操作替换文件名。这些方法对于Windows应用程序开发非常有用。
1338

被折叠的 条评论
为什么被折叠?



