Solved

Programming Stumper...

Posted on 2004-04-28
6
473 Views
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;
      m_DEBUGFILE = NULL;
}
else
{
      m_DEBUGFILE->SeekToEnd();
      CString msg = "START DEBUGGING";
      m_DEBUGFILE->Write(msg,  msg.GetLength());
      m_DEBUGFILE->Write("\r\n", 2);
}

-- Thanks to microsoft for their wonderful API docs:
See: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_core_opening_files.asp

-- Bubba
0
Comment
Question by:bganoush
6 Comments
 
LVL 3

Accepted Solution

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

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

the extra bracket
0
 
LVL 10

Assisted Solution

by:Mercantilum
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)
0
 

Author Comment

by:bganoush
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
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:CoolBreeze
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).
0
 
LVL 10

Expert Comment

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

Expert Comment

by:☠ MASQ ☠
ID: 10943696
lol!
The bug is here -----> microsoft.com

M :o)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now