来源(null)
typedef struct _PA_SE_ERR_DESCRIPTION{ int nCode; char * szErrMacro; char * szErrDescription; } typePASEE; typePASEE A_ShellExecuteErrors[15] = { {0, "0", "The operating system is out of memory or resources"}, {2, "ERROR_FILE_NOT_FOUND", "The specified file was not found."}, {3, "ERROR_PATH_NOT_FOUND", "The specified path was not found."}, {11,"ERROR_BAD_FORMAT", "The .exe file is invalid (non-Win32(R).exe or error in .exe image)."}, {5, "SE_ERR_ACCESSDENIED", "The operating system denied access to the specified file."}, {27,"SE_ERR_ASSOCINCOMPLETE","The file name association is incomplete or invalid."}, {30,"SE_ERR_DDEBUSY", "The DDE transaction could not be completed because other DDE transactions were being processed."}, {29,"SE_ERR_DDEFAIL", "The DDE transaction failed."}, {28,"SE_ERR_DDETIMEOUT", "The DDE transaction could not be completed because the request timed out."}, {32,"SE_ERR_DLLNOTFOUND", "The specified dynamic-link library was not found."}, {2, "SE_ERR_FNF", "The specified file was not found."}, {31,"SE_ERR_NOASSOC", "There is no application associated with the given file name extension."}, {8, "SE_ERR_OOM", "There was not enough memory to complete the operation."}, {3, "SE_ERR_PNF", "The specified path was not found."}, {26,"SE_ERR_SHARE", "A sharing violation occurred."} }; typePASEE A_ShellExecuteExErrors[9] = { {ERROR_FILE_NOT_FOUND, "ERROR_FILE_NOT_FOUND", "The specified file was not found."}, {ERROR_PATH_NOT_FOUND, "ERROR_PATH_NOT_FOUND", "The specified path was not found."}, {ERROR_DDE_FAIL, "ERROR_DDE_FAIL", "The DDE transaction failed."}, {ERROR_NO_ASSOCIATION, "ERROR_NO_ASSOCIATION", "There is no application associated with the given file name extension."}, {ERROR_ACCESS_DENIED, "ERROR_ACCESS_DENIED", "Access to the specified file is denied."}, {ERROR_DLL_NOT_FOUND, "ERROR_DLL_NOT_FOUND", "One of the library files necessary to run the application can't be found."}, {ERROR_CANCELLED, "ERROR_CANCELLED", "The function prompted the user for the location of the application, but the user canceled the request."}, {ERROR_NOT_ENOUGH_MEMORY, "ERROR_NOT_ENOUGH_MEMORY", "There is not enough memory to perform the specified action."}, {ERROR_SHARING_VIOLATION, "ERROR_SHARING_VIOLATION", "A sharing violation occurred."} }; ////////////////////////////////////////////////////////////////////////////////////// void PA_ParseFileFolder(LPCTSTR m_szFile, LPTSTR m_pszFolder){ char * m_pszPos=strrchr(m_szFile, '\\'); if(m_pszPos) strncpy(m_pszFolder, m_szFile, m_pszPos-m_szFile); else strcpy(m_pszFolder, ""); } void PA_ExecuteApplication(LPCTSTR m_szCommand){ char m_szFile[MAX_PATH]={0}; char m_szFolder[MAX_PATH]={0}; char m_szParameter[512]={0}; // Get Command Folder / File / Parameter int m_iLen=0; char * m_pszValue=(char *)m_szCommand; char * m_pszPos=NULL; if(PA_FileExists(m_szCommand)){ strcpy(m_szFile, m_pszValue); strcpy(m_szParameter, ""); } else { if(m_szCommand[0]=='\"'){ m_pszValue++; // 跳过 字符打头字符["] m_pszPos = strchr(m_pszValue, '\"'); if(m_pszPos){ m_iLen = m_pszPos-m_pszValue+1; strncpy(m_szFile, m_pszValue, m_iLen-1); strcpy(m_szParameter, m_pszPos+1); } else { sprintf(szBuffer, "Error in Command\r\n %s", m_szCommand); PA_AlertInfo(szBuffer); return; } } else { m_pszPos = strchr(m_pszValue, ' '); if(m_pszPos){ m_iLen = m_pszPos-m_pszValue; strncpy(m_szFile, m_pszValue, m_iLen); strcpy(m_szParameter, m_pszPos+1); } else { strcpy(m_szFile, m_pszValue); strcpy(m_szParameter, ""); } } } PA_ParseFileFolder(m_szFile, m_szFolder); // sprintf(szBuffer, "[%s]\r\n[%s]\r\n[%s]", m_szFile, m_szFolder, m_szParameter); // PA_AlertInfo(szBuffer); PA_ExecuteFileX(NULL, m_szFile, m_szParameter, m_szFolder); } BOOL PA_FileExists(LPCTSTR m_szFile){ WIN32_FIND_DATA wfd; if(INVALID_HANDLE_VALUE==FindFirstFile(m_szFile, &wfd)) return FALSE; else return TRUE; } void PA_ExecuteFile(LPCTSTR szOperate, LPCTSTR szFile){ PA_ExecuteFileX(szOperate, szFile, NULL, NULL); } void PA_ExecuteFileX(LPCTSTR szOperate, LPCTSTR szFile, LPCTSTR szParametes, LPCTSTR szFolder){ int m_nResult; m_nResult=(int)ShellExecute(NULL, szOperate, szFile, szParametes, szFolder, SW_SHOWNORMAL); // Check And Display Runtime Error, ignore if execute succeed for(int i=0; i<15; i++){ if (m_nResult == A_ShellExecuteErrors[i].nCode) { sprintf(szBuffer, "Error Occupied\n\nCode:\t%d\nMacro:\t%s\nDescription:\n %s", A_ShellExecuteErrors[i].nCode, A_ShellExecuteErrors[i].szErrMacro, A_ShellExecuteErrors[i].szErrDescription); PA_AlertInfo(szBuffer); break; } } m_nResult = NULL; return; }