Programming Stumper...

The following code wasted 20 minutes of my time... Find the BUG!

// m_DEBUGFILE is in the class header as a CFile*
m_DEBUGFILE = new CFile();
CFileException fileException;

if ( !m_DEBUGFILE->Open( pszFileName, CFile::modeCreate | CFile::modeNoTruncate |
          CFile::modeReadWrite ), &fileException )
      // fileException.m_cause;
      delete m_DEBUGFILE;
      CString msg = "START DEBUGGING";
      m_DEBUGFILE->Write(msg,  msg.GetLength());
      m_DEBUGFILE->Write("\r\n", 2);

-- Thanks to microsoft for their wonderful API docs:

-- Bubba
Who is Participating?
CoolBreezeConnect With a Mentor Commented:
this part does looks funny :)

if ( !m_DEBUGFILE->Open( pszFileName, CFile::modeCreate | CFile::modeNoTruncate |
          CFile::modeReadWrite ), &fileException )

the extra bracket
MercantilumConnect With a Mentor Commented:
In you if, the default 3rd argument of Open (exception) was set to NULL, and your if was always true, as in

  if (a, b, c)

the condition to be evaluated will be c.

The &fileException should have been in the Open statement,

  m_DEBUGFILE->Open( pszFileName, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite, &fileException)
bganoushAuthor Commented:

Good replies... and quick too!

Did you look at the sample code from Microsoft?   I always wondered why I can't copy some files ...  maybe microsoft actually based Windows on that sample?

-- Bubba
Improved Protection from Phishing Attacks

WatchGuard DNSWatch reduces malware infections by detecting and blocking malicious DNS requests, improving your ability to protect employees from phishing attacks. Learn more about our newest service included in Total Security Suite today!

yup, looked at the sample code, the mistake was from the it.
I guess, probably they won't be basing on that code sample? after all, the documentation group is a different group from the coding group (I think).
Lol :)
It seems their sample are specifically written for the doc, as the Open would be always in error!
☠ MASQ ☠Commented:
The bug is here ----->

M :o)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.