ofstream problem opening file

From: Alfons (avanzwol_at_zonnet.nl)
Date: 02/06/05


Date: 6 Feb 2005 10:26:32 -0800

Hello,

I have build a program that can do file transferring between a Windows
XP computer and a DOS computer via a serial port. The Windows program
I have build in C++ with Visual Studio 6.0. The DOS program I made in
Turbo C++ 3.0.

At this moment I am in a test phase of sending files and directories.
The code I am using in DOS to open a file for writing looks like this
(forgive me the typos, since I only have my source code at work and
don't have any compiler on this PC):

if (!IsDirectory()) // Check to see if the object is a directory
{
        remove(l_Filename);
}

m_pOfstream = new ofstream;
m_pOfstream->open(l_Filename, ios::binary | ios::in);
if (m_pOfstream->good() == 0)
{
        printf("State: %d\n", m_pOfstream->rdstate());
        return FALSE;
}
else
{
        return TRUE;
}

At the moment I am having a strange problem saving files to disk. If
no files exist yet, then everything works fine. But when the files do
exist, and the program actually has to remove them first, then I am
getting errors.

Let's say I send the following files and directories:
C:\temp\test\
C:\temp\test\a.bat
C:\temp\test\b.com
C:\temp\test\c.bat

The first directory is skipped for removing. The opening of the
directory also returns FALSE, but this is no problem, since I don't
have to write any data to a directory name.
The first file (a.bat) gives an unexplainable error on opening the
file! rdstate() returns 4, which means something like an I/O failure I
believe.
The strange thing is, that the rest of the files don't give any
problem at all.

If I remove the file a.bat on the target side by hand, then everything
works fine.

The opening of the file and assigning a valid value to the m_pOfstream
pointer are done through the constructorof some CFile class I made,
while the closing and deleting of the pointer are done in the
destructor.

Does anyone have any suggestions how to solve this problem?

Alfons van Zwol



Relevant Pages

  • Re: Just started ASM...
    ... The simplest Windows program I know of uses the stack to pass parameters... ... You might want to learn how the stack works, how "call" and "ret" work, *before* you have to use 'em to access your OS. ... I'd agree that it isn't worth spending a lot of time learning the complete workings of dos. ... File I/O routines can be used to get/print from/to the keyboard/screen, as well as disk files - might want to learn them. ...
    (alt.lang.asm)
  • Re: Another easy way.........
    ... Bill H wrote: ... It is a windows program ... disk image to a Apple][that has a disk drive but not software on 5 ... I guess I'll either drop the hard drive in one of my DOS ...
    (comp.sys.ibm.pc.classic)
  • Re: Invalid handle question
    ... is just a pseudo-handle, and opening it does not require Object Manager's ... Concerning DOS and 0, you just misunderstood my question - I was not asking ... services involvement), or just a pseudo-handle under DOS. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: XP Startup Error Message
    ... Amy, you are using an older program designed to work with DOS based OS's ... such as Win9X, Me or ... Windows program. ...
    (microsoft.public.windowsxp.general)
  • Re: freephone number for checking on cumbrian friends & family
    ... DOS computer" - i know i'll have to move to another o.s. ... Did you know there was an open-source DOS project - FreeDos? ... It was just for geeks in those ... I didn't get online at home until I got a pc with win for workgroups. ...
    (uk.local.cumbria)