mfc >> Having Problems with CFile

by jim » Mon, 01 Dec 2003 20:15:56 GMT

Hello I am new at this . But CFile is giving me trouble. I got visual
studio 6 and . The CFile is in a function. that starts a file that
will be a report file. The program compiles ok, but runs and gives a
debug error and crashes help



int write_rpt(void)
{
// begin Report function


CFile fileMyFile;
char initFile[200];


fileMyFile.Open("c:\rept.html", CFile::modeCreate);


fileMyFile.Write(initFile, 15);


fileMyFile.Close();

return 0;

}




Thanks
Jim


mfc >> Having Problems with CFile

by Boben » Mon, 01 Dec 2003 20:50:22 GMT


Problem is you didnt give permission to write while opening the file
(CFile::modeCreate | CFile::modeWrite).
catch the CFileException while using CFile.

Regards
-Boben








mfc >> Having Problems with CFile

by number 94 » Tue, 02 Dec 2003 18:06:56 GMT

In addition to what Boben said, be careful with your filename as well.
"C:\rept.html" is likely to be interpreted as "C:" followed by escape
character '\r' (carriage return).







Having Problems with CFile

by Charles Brown » Wed, 03 Dec 2003 21:39:37 GMT

I think you should also use "c:\\rept.html" in the call (\r in a string is
translated as a carriage return which could lead you program to think the
file name in question is simply "C:").

Be careful (as Boben says) to track all errors and exceptions when playing
with disk files or you can get some very unpleasant results.

Charlie







Similar Threads

1. CFile::Open gives sharing violation with CFile::modeRead flag

Rui Oliveira schrieb:
> CFile::Open gives sharing violation with CFile::modeRead flag

Add the CFile::shareDenyNone flag. The open functions use the "compatibility 
mode" for sharing by default, and that means the file can not be shared with any 
other process.

Norbert

2. Problem with CFile::GetStatus?

3. CFile::GetStatus problem with .net mfc 7.1

I'm running MFC 7.1.
When I do CFile::GetStatus for a file on a mapped disk on the network
(h:\test.txt), if the file does not exists the function creates a
directory with that name!
This problem happens only for some users, not for all.

Environment is .Net Framework 1.1 on Windows 2000 Terminal Server with
all service packs.

Suggestion, anyone?
B.r.
Johan

4. CFile::GetStatus problem

5. CFile::Read problem ???

Hi,

On WinXP, the CStdioFile::ReadString(CString& rString) is supported.
On WinCE it's not, so I attempted to write my own.

I subclassed CTextFile from CFile :

BOOL CTextFile::ReadString(CString& rString)
{
 ASSERT_VALID(this);

 TCHAR ch;
 while( Read(&ch,1)>0 && ch!='\n' )
  rString += ch;

 return ( !rString.IsEmpty() );
}

However, rString always contains garbage. How come? I can't even read 1
byte? (Yes, file opens successfully).
CFile::textFile is not supported under CE, so it's binary, but that should
be no problem.

Can someone tell me why the above doesn't work?

Lisa


6. Is it any point having shared assemblies without having them in the GAC - CSharp/C#

7. Having problem in Process.Getprocesses()

Hi

I've a simple web application where I need to list all the processes
running in the local system.

First, my code was generating error:
System.ComponentModel.Win32Exception: Access is denied.

According to some suggestions found in the Internet, I've given
permission of the registry key "HKLM/Software/Microsoft/Windows
NT/Current/Version/Perflib" to "everyone". And the error went away.

But, however, for a while only. As now the code is generating error:
Couldn't get process information from remote machine.

I have tried the code in a simple Console Application as well. There
also I'm facing the similar error.

This is driving me crazy. What permission is needed for running this
functions? The current windows user is an administrator and I'm using
Windows Authentication(i.e. Anonymous login disabled in IIS).
Obviously, this hardly matters in case of Console Application where
also I'm experiencing the same problem.

Can anybody help me out please?

Thanks.

8. Problem in using c# dll having resources(forms) in VC++