yaroni188
asked on
tryin to GetErrorMessage(...) from CFileException cause an assertion.
catch(CFileException *ex)
{
TCHAR szCause[255];
ex->GetErrorMessage(szCaus e,255);
ex->Delete();
}
when the program enter the catch block and try to execute GetErrorMessage then an exception occur which cause a popup message "Debug assertion failed!" to appear.
I am using a console application project with MFC in DLL.
{
TCHAR szCause[255];
ex->GetErrorMessage(szCaus
ex->Delete();
}
when the program enter the catch block and try to execute GetErrorMessage then an exception occur which cause a popup message "Debug assertion failed!" to appear.
I am using a console application project with MFC in DLL.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If nothing helps, you might want to try this wrapper for FormatMessage I coded a while ago and pass the error code to it. Not sure if this would solve your problem:
CString GetLastErrorMessage(DWORD dwErr)
{
try
{
LPVOID lpMsgBuf;
DWORD dwError = dwErr ? dwErr : GetLastError();
DWORD dwFlags = FORMAT_MESSAGE_ALLOCATE_BU FFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSE RTS;
DWORD dwLang = MAKELANGID(LANG_NEUTRAL,SU BLANG_DEFA ULT);
DWORD dwBytes = FormatMessage(dwFlags,NULL ,dwError,d wLang,
(LPTSTR) &lpMsgBuf, 0, NULL);
if (dwBytes == 0) {
return CString("Unknown");
}
CString sMessage((char*)lpMsgBuf);
LocalFree(lpMsgBuf);
return sMessage;
}
catch (...)
{
return CString("Unknown");
}
}
And then:
catch(CFileException *e)
{
CString err = GetLastErrorMessage(e->m_l OsError);
}
CString GetLastErrorMessage(DWORD dwErr)
{
try
{
LPVOID lpMsgBuf;
DWORD dwError = dwErr ? dwErr : GetLastError();
DWORD dwFlags = FORMAT_MESSAGE_ALLOCATE_BU
FORMAT_MESSAGE_FROM_SYSTEM
FORMAT_MESSAGE_IGNORE_INSE
DWORD dwLang = MAKELANGID(LANG_NEUTRAL,SU
DWORD dwBytes = FormatMessage(dwFlags,NULL
(LPTSTR) &lpMsgBuf, 0, NULL);
if (dwBytes == 0) {
return CString("Unknown");
}
CString sMessage((char*)lpMsgBuf);
LocalFree(lpMsgBuf);
return sMessage;
}
catch (...)
{
return CString("Unknown");
}
}
And then:
catch(CFileException *e)
{
CString err = GetLastErrorMessage(e->m_l
}
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: Kocil
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Tinchos
EE Cleanup Volunteer
{
TCHAR szCause[255];
ex.GetErrorMessage(szCause
}