方法一:
//获得应用程序路径
char szFilePath[MAX_PATH + 1]={0};
GetModuleFileNameA(NULL, szFilePath, MAX_PATH);
(strrchr(szFilePath, '\\'))[1] = 0; // 删除文件名,只获得路径字串
//输出显示
string paths = szFilePath;
size_t origsize =paths.length() + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
wchar_t *wcstring = (wchar_t *) malloc(sizeof(wchar_t) *(paths.length() - 1));
mbstowcs_s(&convertedChars, wcstring, origsize, paths.c_str(), _TRUNCATE);
MessageBox(NULL, wcstring, L"paths" , MB_OK);
方法二:
CString strPath;
//获得应用程序路径
TCHAR strExeFullDir[MAX_PATH];
if ( GetModuleFileName( NULL, strExeFullDir,MAX_PATH ) )
{
(_tcsrchr(strExeFullDir,_T('\\')))[1] = 0;
}
strPath = strExeFullDir;
strPath = strPath + "Config.ini" ;