Click here to Skip to main content
15,925,113 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralDatabase ( table Update/Delete) Pin
26-Jun-02 6:15
suss26-Jun-02 6:15 
GeneralRe: Database ( table Update/Delete) Pin
Ramu Pulipati26-Jun-02 8:30
Ramu Pulipati26-Jun-02 8:30 
GeneralON_UPDATE_COMMAND_UI and CDialog's Pin
Sprudling26-Jun-02 6:11
Sprudling26-Jun-02 6:11 
GeneralRe: ON_UPDATE_COMMAND_UI and CDialog's Pin
udayGovekar26-Jun-02 6:42
udayGovekar26-Jun-02 6:42 
GeneralRe: ON_UPDATE_COMMAND_UI and CDialog's Pin
Ernest Laurentin26-Jun-02 8:41
Ernest Laurentin26-Jun-02 8:41 
GeneralRe: ON_UPDATE_COMMAND_UI and CDialog's Pin
Sprudling26-Jun-02 22:20
Sprudling26-Jun-02 22:20 
GeneralArray to.bmp file Pin
Knowledge Seeker26-Jun-02 6:06
Knowledge Seeker26-Jun-02 6:06 
GeneralCException::GetErrorMessage causing an ASSERT Pin
Navin26-Jun-02 5:52
Navin26-Jun-02 5:52 
I have a console app that uses MFC. I am doing some testing on a class that I have that utilizes CStdioFile. I know that the CStdioFile constructor will throw an exception if something goes wrong (e.g., it can't create the file.)

I try to catch this exception in the standard manner, and that part seems to work. But when I call its GetErrorMessage function, it triggers an ASSERT deep in MFC code. It appears that it is trying to load a string from a resource, but can't seem to get at the resource.

Below is the relevant fragment of code. I looked at an MSDN article TEAR (I think) and it did the exact same thing - try to call MFC functions from a console app, and I can't see why my code would be any different. (NOTE: I have also tried catching a CFileException instead of a CException, but that caused the same problem.)

try
{
  CStdioFile file(realFileName, CFile::modeCreate | CFile::modeWrite);

  ...
}

catch(CException *e)
{
  TCHAR buff[201];
  bRet = false;
  e->GetErrorMessage(buff, 200);   // <-- THIS LINE ASSERTS!
  TRACE("Writing to file %s failed:\n\t%s", fileName, buff);
  e->Delete();
}


Also, in my main function, this is how I initialize MFC (appwizard generated code):
// initialize MFC and print and error on failure
if(!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
  // TODO: change error code to suit your needs
  cerr << _T("Fatal Error: MFC initialization failed") << endl;
  return 1;
}





Even if you win the rat race, you're still a rat.
GeneralRe: CException::GetErrorMessage causing an ASSERT Pin
Joaquín M López Muñoz26-Jun-02 7:13
Joaquín M López Muñoz26-Jun-02 7:13 
GeneralRe: CException::GetErrorMessage causing an ASSERT Pin
Navin26-Jun-02 7:20
Navin26-Jun-02 7:20 
GeneralRe: CException::GetErrorMessage causing an ASSERT Pin
Joaquín M López Muñoz26-Jun-02 7:52
Joaquín M López Muñoz26-Jun-02 7:52 
GeneralRe: CException::GetErrorMessage causing an ASSERT Pin
Navin26-Jun-02 8:03
Navin26-Jun-02 8:03 
GeneralAHA! Pin
Navin26-Jun-02 8:16
Navin26-Jun-02 8:16 
GeneralMs Word Automation margins Pin
Braulio Dez26-Jun-02 5:47
Braulio Dez26-Jun-02 5:47 
GeneralSAFEARRAY in Variant Pin
Hans Ruck26-Jun-02 5:43
Hans Ruck26-Jun-02 5:43 
GeneralRe: SAFEARRAY in Variant Pin
Jeremy Falcon26-Jun-02 5:48
professionalJeremy Falcon26-Jun-02 5:48 
GeneralRe: SAFEARRAY in Variant Pin
Hans Ruck26-Jun-02 5:59
Hans Ruck26-Jun-02 5:59 
GeneralRe: SAFEARRAY in Variant Pin
Jeremy Falcon26-Jun-02 6:17
professionalJeremy Falcon26-Jun-02 6:17 
GeneralMutex Pin
Anthony988726-Jun-02 5:38
Anthony988726-Jun-02 5:38 
GeneralRe: Mutex Pin
Navin26-Jun-02 5:44
Navin26-Jun-02 5:44 
GeneralRe: Mutex Pin
Jeremy Falcon26-Jun-02 5:45
professionalJeremy Falcon26-Jun-02 5:45 
GeneralRe: Mutex Pin
Dean Michaud26-Jun-02 7:05
Dean Michaud26-Jun-02 7:05 
GeneralRe: Mutex Pin
Jeremy Falcon26-Jun-02 7:23
professionalJeremy Falcon26-Jun-02 7:23 
GeneralRe: Mutex Pin
Scott H. Settlemier27-Jun-02 9:04
Scott H. Settlemier27-Jun-02 9:04 
GeneralForm objects limit Pin
RuiSantiago26-Jun-02 5:27
RuiSantiago26-Jun-02 5:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.