The idea is as follows: I have a ConfirmDisk button on a dialog (in Visual C++). When you click the button, the handler calls a ConfirmDisk() function which is supposed to write some files within a directory structure to floppy. If the user has its floppy into the drive all its fine. If it doesn't the function is trying to write in vain so I want to display a MessageBox prompting the user for the floppy.
Now, look at what I tried to do:
static LPCTSTR getErrMessage(DWORD win_err)
{
static TCHAR errMessage[500] = {0};
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, win_err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), errMessage, sizeof(errMessage) / sizeof(TCHAR), 0);
return errMessage;
}
void ErrMsg(CException* pe)
{
MessageBox(NULL, getErrMessage(GetLastError()), _T("Error") , MB_OK | MB_ICONINFORMATION);
}
// these are global function
Now, when I'm calling my ConfirmDisk() function within a class:
try
{
ConfirmDisk();
}
catch (CException* pe)
{
::ErrMsg(pe);
pe->Delete();
return;
}
The idea was as follow: get any possible error message from the system with 'FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM...'
then display it with Win32 API MessageBox from within ErrMsg, then attemp to execute my ConfirmDisk() from within a try/catch block. However, it doesn't work because the execution blocks on ConfirmDisk() function. When you use the debugger, you can see that the yellow arrow stops at this function. No message box is displayed.
Thank you for any suggestions,
Mullah, Romania