1 代码
#ifdef _WIN32
std::string GetAppPathA();
#else
bool GetAppPathA(char* processdir, size_t len, string &excuDir);
#endif
#ifdef _WIN32
std::string InputVideoInfo::GetAppPathA() {
char szFilePath[MAX_PATH] = { 0 };
char szDrive[MAX_PATH] = { 0 };
char szDir[MAX_PATH] = { 0 };
char szFileName[MAX_PATH] = { 0 };
char szExt[MAX_PATH] = { 0 };
GetModuleFileNameA(NULL, szFilePath, sizeof(szFilePath));
_splitpath_s(szFilePath, szDrive, szDir, szFileName, szExt);
std::string str(szDrive);
str.append(szDir);
return str;
}
#else
bool InputVideoInfo::GetAppPathA(char* processdir, size_t len, string &excuDir){
string p;
int pos;
p.clear();
memset(processdir,0x00,len);
excuDir.clear();
size_t s = readlink("/proc/self/exe", processdir, len);
if(s <= 0){
return false;
}
p = processdir;
pos = p.find_last_of('/');
if(std::string::npos == pos){
return false;
}
excuDir = p.substr(0, pos + 1);
return true;
}
#endif