yangyin
2024-08-20 98e49c0dd42840a094837f7acae532bc237a719a
Hydro/Yw.Hydraulic.Core/src/epanet.cpp
@@ -1063,6 +1063,52 @@
        return 0;
}
int DLLEXPORT EN_geterrormsg(EN_Project pr, char* errmsg, int maxLen)
/*----------------------------------------------------------------
**  Input:   errcode = an error or warnng code
**           maxLen = maximum characters that errmsg can hold
**  Output:  errmsg = text of error/warning message
**  Returns: error code
**  Purpose: retrieves the text of the message associated with
**           a particular error/warning code
**----------------------------------------------------------------
*/
{
    // 检查errmsg是否为NULL
    if (errmsg == NULL) {
        return 252; // 返回错误码,表示errmsg为NULL
    }
    // 获取pr->MsgText的长度
    int msgLen = strlen(pr->MsgText);
    // 确保errmsg有足够的空间来存储pr->MsgText
    if (msgLen >= maxLen) {
        return 253; // 返回错误码,表示errmsg空间不足
    }
    //为errmsg分配足够的空间
    /*errmsg = (char*)malloc(msgLen + 1);*/
    // 初始化errmsg为空字符串
    errmsg[0] = '\0';
    // 将pr->MsgText的内容放入errmsg中
    strncpy(errmsg, pr->MsgText, msgLen);
    // 确保errmsg是以NULL结尾的字符串
    errmsg[msgLen] = '\0';
    if (strlen(errmsg) == 0)
        return 251;
    else
        return 0;
}
int DLLEXPORT EN_getstatistic(EN_Project p, int type, double *value)
/*----------------------------------------------------------------
**  Input:   type = type of simulation statistic (see EN_AnalysisStatistic)