方法一: 直接使用argv[0]
char chPath[_MAX_PATH];
TcharToChar (argv[0], chPath) ;
string strPath(chPath);
size_t found = strPath.find_last_of('\\');
strPath = strPath.substr(0, found);
方法二:GetModuleFileName函数
TCHAR szFull[_MAX_PATH];
TCHAR szDrive[_MAX_DRIVE];
TCHAR szDir[_MAX_DIR];
::GetModuleFileName(NULL, szFull, sizeof(szFull)/sizeof(TCHAR));
_tsplitpath(szFull, szDrive, szDir, NULL, NULL);
_tcscpy(szFull, szDrive);
_tcscat(szFull, szDir);
如果需要将TCHAR转为char或char转TCHAR,再提供两个函数:
void TcharToChar
{
//获取字节长度
iLength
//将tchar值赋给_char
WideCharToMultiByte(CP_ACP,
}
void CharToTchar
{
int
iLength
}