|
获取应用程序路径
TCHAR exeFullPath[MAX_PATH]; // MAX_PATH
GetModuleFileName(NULL,exeFullPath,MAX_PATH);//得到程序模块名称,全路径
//解析路径,得到当前运行程序所在目录
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
_splitpath(strAppName, drive, dir, NULL,NULL);
CString strPath;
strPath.Format("%s%s", drive, dir);
//strPath即为得到的当前运行程序所在目录
char path[MAX_PATH];
GetCurrentDirectory(MAX_PATH,path);
bool AlreadyRunning;
CString strPath=path;
strPath = strPath + AfxGetApp()->m_pszExeName;
strPath.Replace("\\","_");
g_hMutexOneInstance = ::CreateMutex( NULL, TRUE, strPath);
AlreadyRunning = ( ::GetLastError() == ERROR_ALREADY_EXISTS ||
::GetLastError() == ERROR_ACCESS_DENIED);
|
|