Programming Stumper...

Posted on 2004-04-28
Last Modified: 2006-11-17
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
Question by:bganoush
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

CoolBreeze earned 30 total points
ID: 10938440
this part does looks funny :)

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

the extra bracket
LVL 10

Assisted Solution

Mercantilum earned 20 total points
ID: 10938856
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)

Author Comment

ID: 10939214

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
What, When and Where - Security Threats from Q1

Join Corey Nachreiner, CTO, and Marc Laliberte, Information Security Threat Analyst, on July 26th as they explore their key findings from the first quarter of 2017.


Expert Comment

ID: 10939357
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).
LVL 10

Expert Comment

ID: 10940099
Lol :)
It seems their sample are specifically written for the doc, as the Open would be always in error!
LVL 62

Expert Comment

by:☠ MASQ ☠
ID: 10943696
The bug is here ----->

M :o)

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Successful collaboration among team members is essential for the growth of your business. When employees work together on projects, share ideas and communicate effectively they get better results.
First of all let me say that the only language that I speak is English, but in answering questions here I often come across people whose English skills are not the best and I’d like to be able to communicate better with them, and the following descr…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor ( Top Charts is a view in which you can set seve…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question