📄 runtimeexception.cpp
字号:
#include "StdAfx.h"
#include "RuntimeException.h"
#ifndef _WINERROR_
#pragma message("To avoid this message, please put WinError.h in your PCH (normally stdafx.h)")
#include <WinError.h>
#endif
BOOL CRuntimeException::GetErrorMessage(LPTSTR pstrError, UINT nMaxError, PUINT pnHelpContext)
{
ASSERT(pstrError != NULL && AfxIsValidString(pstrError, nMaxError));
if (pnHelpContext != NULL)
*pnHelpContext = 0;
if(m_dwError!=0)
{
LPTSTR lpBuffer;
BOOL bRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, m_dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT),
reinterpret_cast<LPTSTR>(&lpBuffer), 0, NULL);
if (bRet == FALSE)
*pstrError = '\0';
else
{
//StringCchCopyN(pstrError, nMaxError, lpBuffer, nMaxError);
lstrcpyn(pstrError, lpBuffer, nMaxError);
bRet = TRUE;
LocalFree(lpBuffer);
}
return bRet;
}
else
{
ASSERT(m_lpszErrorMessage!= NULL);
lstrcpyn(pstrError, m_lpszErrorMessage, nMaxError);
//StringCchCopyN(pstrError, nMaxError, m_lpszErrorMessage, nMaxError);
return TRUE;
}
TRACE(_T("Error:%s\n"),pstrError);
}
CString CRuntimeException::GetErrorMessage()
{
CString rVal;
LPTSTR pstrError = rVal.GetBuffer(4096);
GetErrorMessage(pstrError, 4096, NULL);
rVal.ReleaseBuffer();
return rVal;
}
DWORD CRuntimeException::GetErrorCode() const
{
return m_dwError;
}
CRuntimeException::CRuntimeException(DWORD dwError)
{
ASSERT(dwError!=0);
m_dwError = dwError;
m_lpszErrorMessage = NULL;
}
CRuntimeException::CRuntimeException(LPCTSTR lpszErrorMessage)
{
ASSERT(lpszErrorMessage!=NULL);
m_lpszErrorMessage = lpszErrorMessage;
m_dwError =0;
}
IMPLEMENT_DYNAMIC(CRuntimeException, CException)
#ifdef _DEBUG
void CRuntimeException::Dump(CDumpContext& dc) const
{
CObject::Dump(dc);
dc << "m_dwError = " << m_dwError;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -