-
September 19th, 2001, 01:54 PM
#1
Opening a Read Only File with CFile
Hi,
I'm trying to open a read only file with CFile. I thought that it would be possible with CFile::modeRead and CFile::shareDenyNone, but I get an access violation when I try and open the file. What am I missing?
Thanks
Chris Rombach
-
September 19th, 2001, 03:00 PM
#2
Re: Opening a Read Only File with CFile
Can't think of anything off hand, but if you Post Some Code and Maybe I can help....
++Jyvilian
-
September 19th, 2001, 03:11 PM
#3
Re: Opening a Read Only File with CFile
Ok, here's the bit I'm having trouble with. Its the beginning of a function that compares 2 files. I'll post the part that I think is the problem, and if you need more let me know.
for (int k = i; k < 15; k++)
{
CFile ControlFile;
ControlFile.Open (m_strPathName[0], CFile::modeRead | CFile::shareDenyNone);
CFile Testfile;
TestFile.Open (m_strPathName[k], CFile::modeRead | CFile::shareDenyNone);
...
This works great when I'm dealing with non read-only files, but I get an access violation on read-only. Unfortunately my manager wants to use my app on CD's which have read-only files.
Thanks in advance.
Chris Rombach
-
September 19th, 2001, 04:25 PM
#4
Re: Opening a Read Only File with CFile
2 things to try:
// #1 -- Maybe you need the Exception Parameter?
CFileException e;
ControlFile.Open (m_strPathName[0], CFile::modeRead | CFile::shareDenyNone, &e);
// #2 -- Maybe you need modeReadWrite
ControlFile.Open (m_strPathName[0], CFile::modeReadWrite, &e);
++Jyvilian
-
September 20th, 2001, 12:30 PM
#5
Re: Opening a Read Only File with CFile
I tried it and no luck. Any other ideas?
Chris
-
December 21st, 2001, 01:16 AM
#6
Re: Opening a Read Only File with CFile
ControlFile.Open (m_strPathName[0], CFile::modeRead | CFile::shareDenyNone);
Obviously the CFile::shareDenyNone is the problem.
You want CFile::modeRead but at the same time you want to write and read also??
Check the CFIle constructor for detail.
-
August 14th, 2009, 03:06 PM
#7
Re: Opening a Read Only File with CFile
Sorry to be bumping up this old thread but I seem to be having a similar problem. The above post seems to indicate that opening a CFile with shareDenyNone and modeRead would not work properly. I was under the impression that this would just mean this instance of the open file would be open for reading only but others could still be opened to write. Is this correct? I've done it in my code and it opens the file, however are there some cases where this would cause errors? Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|