MFC获取可执行文件(exe)所在文件目录

可以应用函数GetModuleFileName(),举一个例子:

CString strexe;
::GetModuleFileName(NULL,strexe.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
int nexe = strexe.GetLength();
for(i=nexe-1;i>=0;i--)
{
       if(strexe[i]=='\')
       break;
}
strtmp = strexe.Left(i+1);

strtmp存储的就是exe文件所在的目录,而strexe会包含文件名

原文地址:https://www.cnblogs.com/sgdd123/p/7875222.html