Qter 发表于 2020-1-27 21:40:14

常用功能

获取应用程序路径

TCHAR exeFullPath; // MAX_PATH
GetModuleFileName(NULL,exeFullPath,MAX_PATH);//得到程序模块名称,全路径

//解析路径,得到当前运行程序所在目录
char drive;
char dir;

_splitpath(strAppName, drive, dir, NULL,NULL);
CString strPath;
strPath.Format("%s%s", drive, dir);
//strPath即为得到的当前运行程序所在目录


char 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);

页: [1]
查看完整版本: 常用功能