#include "Common.h" /// /// 析构函数 /// ErrorMsg::~ErrorMsg() { if (_errorMsg) { delete _errorMsg; _errorMsg = nullptr; } } /// /// 设置错误信息 /// /// /// void ErrorMsg::SetErrorMsg(ErrorCode code, std::vector errorMsgs) { if (_errorMsg) { delete _errorMsg; _errorMsg = NULL; } int count = errorMsgs.size(); std::stringstream ss; for (int ni = 0; ni < count; ni++) { ss << errorMsgs[ni]; } std::string msgCombined = ss.str(); int len = msgCombined.length(); _errorMsg = new char[msgCombined.length() + 1]; msgCombined.copy(_errorMsg, len, 0); *(_errorMsg + len) = '\0'; _errorCode = code; } /// /// 获取错误信息 /// /// /// /// void ErrorMsg::GetErrorMsg(ErrorCode& errorCode, char* errorMsg, const int errorMaxLen) { errorCode = _errorCode; if (!_errorMsg) { return; } int errorLen = strlen(_errorMsg); if (errorMaxLen > errorLen) { wcscpy_s(errorMsg, errorLen + 1, _errorMsg); } else { wcscpy_s(errorMsg, errorMaxLen, _errorMsg, errorMaxLen - 1); } } /// /// 初始化静态成员变量_errorMsg /// char* ErrorMsg::_errorMsg = nullptr; /// /// 初始化静态成员变量 _errorCode /// ErrorCode ErrorMsg::_errorCode = None;