C++获取可执行文件的路径

来源:互联网 发布:光学设计软件 编辑:程序博客网 时间:2024/05/16 08:48
//获取文件的EXE路径
CString CAmpStateSetCheckDlg::GetModuleDirectory()
{
char szModule[MAX_PATH] = {0};
CString str;
str.Format(_T("%s"),szModule);
if (lstrlen(str)>0)
{
return NULL;
}
::GetModuleFileName(::AfxGetInstanceHandle(),szModule,sizeof(szModule));
char *pBacklash = strrchr(szModule,_T('\\'));
if (pBacklash)
{
(*pBacklash) = _T('\0');

}
CString strModulePath(szModule);
return strModulePath;
}
0 0