Post again: open file fail! 
Author Message
 Post again: open file fail!

Dear VC experts,

I developed a program to open and edit some type of files. But the problem
is that if I open a Windows Explore, and put selection on the file, then I
can not open the file in my program, the error message is "A sharing
voilation occured while accessing my_file."

I use Win2K. Following is the code, could you please figure out what's wrong
in the code.

Thanks in advance!
Evan

//========================================
  CFile file;
  CFileException e;
  if (!file.Open(strCurrentFile,
                 CFile::typeBinary |
                 CFile::modeReadWrite,
                 &e))
  {
   char buf[2048];
   char err[1024];
   e.GetErrorMessage(err, 1024);
   sprintf(buf, "Open file fail.\n%s", err);
   this->MessageBox(buf);
   return;
  }
//=========================================



Mon, 05 Sep 2005 01:40:22 GMT  
 Post again: open file fail!
Did you try with different types of files?
Do you mean that if the same file is not selected in Explorer, you can open
it?
Can you open it with an editor like NotePad from Explorer?



Quote:
> Dear VC experts,

> I developed a program to open and edit some type of files. But the problem
> is that if I open a Windows Explore, and put selection on the file, then I
> can not open the file in my program, the error message is "A sharing
> voilation occured while accessing my_file."

> I use Win2K. Following is the code, could you please figure out what's
wrong
> in the code.

> Thanks in advance!
> Evan

> //========================================
>   CFile file;
>   CFileException e;
>   if (!file.Open(strCurrentFile,
>                  CFile::typeBinary |
>                  CFile::modeReadWrite,
>                  &e))
>   {
>    char buf[2048];
>    char err[1024];
>    e.GetErrorMessage(err, 1024);
>    sprintf(buf, "Open file fail.\n%s", err);
>    this->MessageBox(buf);
>    return;
>   }
> //=========================================



Mon, 05 Sep 2005 05:34:27 GMT  
 Post again: open file fail!

Quote:
> Did you try with different types of files?

My program is used to edit certian type of file.

Quote:
> Do you mean that if the same file is not selected in Explorer, you can
open
> it?

Yes, if it's not selected in Explorer, I can open it in my program.

Quote:
> Can you open it with an editor like NotePad from Explorer?

Yes, I can open it with UltraEdit.

Quote:



> > Dear VC experts,

> > I developed a program to open and edit some type of files. But the
problem
> > is that if I open a Windows Explore, and put selection on the file, then
I
> > can not open the file in my program, the error message is "A sharing
> > voilation occured while accessing my_file."

> > I use Win2K. Following is the code, could you please figure out what's
> wrong
> > in the code.

> > Thanks in advance!
> > Evan

> > //========================================
> >   CFile file;
> >   CFileException e;
> >   if (!file.Open(strCurrentFile,
> >                  CFile::typeBinary |
> >                  CFile::modeReadWrite,
> >                  &e))
> >   {
> >    char buf[2048];
> >    char err[1024];
> >    e.GetErrorMessage(err, 1024);
> >    sprintf(buf, "Open file fail.\n%s", err);
> >    this->MessageBox(buf);
> >    return;
> >   }
> > //=========================================



Mon, 05 Sep 2005 07:48:26 GMT  
 Post again: open file fail!

Quote:

>I use Win2K. Following is the code, could you please figure out what's wrong

What happens if you add CFile::shareDenyWrite to the flags you have
used ? i.e. :

 if (!file.Open(strCurrentFile,
                 CFile::typeBinary |
                 CFile::modeReadWrite |
                 CFile::shareDenyWrite,
                 &e))



Mon, 05 Sep 2005 14:02:48 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Post Again: Overwrite default File Save As Dlg

2. Open Html File(sorry for long post)

3. Limit on concurrent open files in C (again)

4. Double-Click to open data file failed

5. Double Click to Open Data File Failed

6. Help - code using fopen() failing on production system - file may already be open

7. Double Click To Open Data File Failed

8. Open file fail: share voilation

9. File open failed!a strange problem.

10. MRU file open fails ?

11. Double-Click to open data file failed

12. SqlConnection - Open - Close - Open - fails

 

 
Powered by phpBB® Forum Software