// // If there is a error, give the right message // void CSerialPort::ProcessErrorMessage(char* ErrorText) { TCHAR Temp[260] = { 0 }; LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR)&lpMsgBuf, 0, NULL ); #if defined(_UNICODE) || defined(UNICODE) wchar_t *wt = AnsiToUtf16(ErrorText); _stprintf_s(Temp, _T("WARNING: %s Failed with the following error: \n%s\nPort: %d\n"), wt, lpMsgBuf, m_nPortNr); MessageBox(NULL, Temp, _T("Application Error"), MB_ICONSTOP); #else _stprintf_s(Temp, _T("WARNING: %s Failed with the following error: \n%s\nPort: %d\n"), ErrorText, lpMsgBuf, m_nPortNr); MessageBox(NULL, Temp, _T("Application Error"), MB_ICONSTOP); #endif LocalFree(lpMsgBuf); }
void CLoggingImp::WriteLogging(int level, char* szString) { //construct message header wchar_t* wszString = 0; AnsiToUtf16(szString, &wszString); WriteLogging(level, wszString ? wszString : L""); delete[] wszString; //no harm to delete null }
void CheckAndUpgradeCiCache() { if (0 == share_segment->ci_cache.length || CI_CACHE_V66_SIGNATURE == share_segment->ci_cache.signature) return; if (CI_CACHE_SIGNATURE == share_segment->ci_cache.signature) { int pos = 0; int item_length = (char)share_segment->ci_cache.cache[pos] * sizeof(HZ); share_segment->ci_cache.signature = CI_CACHE_V66_SIGNATURE; //遍历词的cache while(pos + item_length <= share_segment->ci_cache.length) //需要判定最后一个词条不越界 { char ci_ansi[MAX_WORD_LENGTH * sizeof(HZ)] = {0}; TCHAR ci_uc[MAX_WORD_LENGTH] = {0}; memcpy_s(ci_ansi, MAX_WORD_LENGTH * sizeof(HZ), &share_segment->ci_cache.cache[pos + WORDLIB_FEATURE_LENGTH], item_length); AnsiToUtf16(ci_ansi, ci_uc, MAX_WORD_LENGTH); memcpy_s(&share_segment->ci_cache.cache[pos + WORDLIB_FEATURE_LENGTH], item_length, ci_uc, item_length); //下一个词 pos += WORDLIB_FEATURE_LENGTH + share_segment->ci_cache.cache[pos] * sizeof(HZ); item_length = (char)share_segment->ci_cache.cache[pos] * sizeof(HZ); } } else { share_segment->ci_cache.signature = CI_CACHE_V66_SIGNATURE; share_segment->ci_cache.length = 0; share_segment->ci_cache.max_used_id = 0; } return; }