|
-
May 22nd, 2007, 07:31 AM
#1
Unhandled exception: 0xC0000005: Access violation
hi all,
i am new to MFC programming, i am Creating an object of CString to store an filename opened through dialog box.... If i pass this CString object as filename to fopen() function, I am getting Unhandled exception: 0xC0000005: Access violation..... so please help me out in this.....
i.e.
CString Filename;
if( FileDlg.DoModal() == IDOK )
{
Filename = FileDlg.GetFileName();
}
And if i pass this Filename object to fopen() as
fopen(Filename, "r");
When I debug I get the violation exception at this line.....
-
May 22nd, 2007, 07:40 AM
#2
Re: Unhandled exception: 0xC0000005: Access violation
Are you using UNICODE and does fopen support UNICODE filenames ??
btw : You are using MFC, so why use fopen ?? CFile is a better alternative.
-
May 22nd, 2007, 07:52 AM
#3
Re: Unhandled exception: 0xC0000005: Access violation
i am using this same code of lines in another project... it's working fine......
i am using fopen instead of using CFile class bcoz i am reading it character by character & also byte by byte after some condition..... So can u help me out of this......
-
May 22nd, 2007, 08:25 AM
#4
Re: Unhandled exception: 0xC0000005: Access violation
i am using fopen instead of using CFile class bcoz i am reading it character by character & also byte by byte after some condition..... So can u help me out of this......
Byte by byte is very slow, because this creates a lot of disk access. Personally I would advice you to read the entire file (if it is not TOO big), and process your data in memory.
btw : your crash is a mystery to me. Is there some code in between that uses/modifies the Filename string ? And is the file not locked by something else ?
-
May 22nd, 2007, 08:43 AM
#5
Re: Unhandled exception: 0xC0000005: Access violation
-
May 22nd, 2007, 08:45 AM
#6
Re: Unhandled exception: 0xC0000005: Access violation
Code:
char szBuf[BUFLEN];
CString sFilename;
if( FileDlg.DoModal() == IDOK )
{
sFilename = FileDlg.GetFileName();
CFile file;
if(file.Open(sFileName, CFile::modeRead))
{
DWORD dwSize = file.GetLength();
if(dwSize < BUFLEN)
file.Read(szBuf, (UINT)dwSize);
file.Close();
}
Time is fun when you're having flies 
-
May 22nd, 2007, 09:16 AM
#7
Re: Unhandled exception: 0xC0000005: Access violation
thank you guys.....
i finally got it.......
Actually.. I created same code in another project, and it worked..... I really don't know what is the problem with my Visual Studio 6, so sorry guys for wasting your precious time.
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
|