CFile::Read...

I am working with MFC VC++6 and want to read a file that I created and
display the contents of the file to a message box.  The file has one
character 'a' at position 1.

Here is my code:

const int MAX_STRING_LENGTH = 10;
CString MyString;
MyFile.Open("...MyfilePath", CFile::modeNoTruncate | CFile::modeRead   );

char* TempBuf = MyString.GetBuffer(MAX_STRING_LENGTH);
UINT NumChars = MyFile.Read((void FAR*) TempBuf, MAX_STRING_LENGTH - 1);
 MyString.ReleaseBuffer(NumChars);

 AfxMessageBox(MyString);


Unfortunately I get an exception error.  Does anyone know what I am doing
wrong?

Thanks,
RABMissouri


0
drbert (27)
4/5/2004 3:59:40 AM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
1073 Views

Similar Articles

[PageSpeed] 42

When you step through each line of the code (F10), which one causes the
exception?

"RBert" <drbert@microcore.net> wrote in message
news:Oq$SuJsGEHA.2512@TK2MSFTNGP12.phx.gbl...
> I am working with MFC VC++6 and want to read a file that I created and
> display the contents of the file to a message box.  The file has one
> character 'a' at position 1.
>
> Here is my code:
>
> const int MAX_STRING_LENGTH = 10;
> CString MyString;
> MyFile.Open("...MyfilePath", CFile::modeNoTruncate | CFile::modeRead   );
>
> char* TempBuf = MyString.GetBuffer(MAX_STRING_LENGTH);
> UINT NumChars = MyFile.Read((void FAR*) TempBuf, MAX_STRING_LENGTH - 1);
>  MyString.ReleaseBuffer(NumChars);
>
>  AfxMessageBox(MyString);
>
>
> Unfortunately I get an exception error.  Does anyone know what I am doing
> wrong?
>
> Thanks,
> RABMissouri
>
>


0
4/5/2004 1:57:53 PM
Add some error checking to your code.
Does the file open succeed?
What is the value of NumChars after the read?
Step through the code in the debugger to see which line of code is
causing the problem.

"RBert" <drbert@microcore.net> wrote in message news:<Oq$SuJsGEHA.2512@TK2MSFTNGP12.phx.gbl>...
> I am working with MFC VC++6 and want to read a file that I created and
> display the contents of the file to a message box.  The file has one
> character 'a' at position 1.
> 
> Here is my code:
> 
> const int MAX_STRING_LENGTH = 10;
> CString MyString;
> MyFile.Open("...MyfilePath", CFile::modeNoTruncate | CFile::modeRead   );
> 
> char* TempBuf = MyString.GetBuffer(MAX_STRING_LENGTH);
> UINT NumChars = MyFile.Read((void FAR*) TempBuf, MAX_STRING_LENGTH - 1);
>  MyString.ReleaseBuffer(NumChars);
> 
>  AfxMessageBox(MyString);
> 
> 
> Unfortunately I get an exception error.  Does anyone know what I am doing
> wrong?
> 
> Thanks,
> RABMissouri
0
sandkross (6)
4/5/2004 3:12:05 PM
What, exactly, is FAR? Other than being a completely obsolete Win16 construct?

I notice you do not actually check to see that the open succeeded. All bets are off. Until
you know the file opened successfully, there is no chance any of the rest of the code can
be guaranteed to work.

What exception? 0xC00000005. You've submitted the classic "My program doesn't work, what
did I do wrong?" without defining what you mean by "an exception error" (lots of people
call ASSERT failures "exception errors", and they aren't). And you didn't indicate where
it occurred (without a stack backtrace or at least a hint as to which line failed, all we
can say is "you did something wrong, fix it"). But I suspect the open failed, and you
didn't check for it.
					joe

On Sun, 4 Apr 2004 22:59:40 -0500, "RBert" <drbert@microcore.net> wrote:

>I am working with MFC VC++6 and want to read a file that I created and
>display the contents of the file to a message box.  The file has one
>character 'a' at position 1.
>
>Here is my code:
>
>const int MAX_STRING_LENGTH = 10;
>CString MyString;
>MyFile.Open("...MyfilePath", CFile::modeNoTruncate | CFile::modeRead   );
>
>char* TempBuf = MyString.GetBuffer(MAX_STRING_LENGTH);
>UINT NumChars = MyFile.Read((void FAR*) TempBuf, MAX_STRING_LENGTH - 1);
> MyString.ReleaseBuffer(NumChars);
>
> AfxMessageBox(MyString);
>
>
>Unfortunately I get an exception error.  Does anyone know what I am doing
>wrong?
>
>Thanks,
>RABMissouri
>

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
4/5/2004 5:19:14 PM
Thanks for everyones help.  I finally got it to work.  Stepping through the
lines helped locate the assertion error.  My file was already open from
lines preceding it.  Does one need to close a file after writing  and reopen
the file when reading?

Thanks,
RABMissouri

"RBert" <drbert@microcore.net> wrote in message
news:Oq$SuJsGEHA.2512@TK2MSFTNGP12.phx.gbl...
> I am working with MFC VC++6 and want to read a file that I created and
> display the contents of the file to a message box.  The file has one
> character 'a' at position 1.
>
> Here is my code:
>
> const int MAX_STRING_LENGTH = 10;
> CString MyString;
> MyFile.Open("...MyfilePath", CFile::modeNoTruncate | CFile::modeRead   );
>
> char* TempBuf = MyString.GetBuffer(MAX_STRING_LENGTH);
> UINT NumChars = MyFile.Read((void FAR*) TempBuf, MAX_STRING_LENGTH - 1);
>  MyString.ReleaseBuffer(NumChars);
>
>  AfxMessageBox(MyString);
>
>
> Unfortunately I get an exception error.  Does anyone know what I am doing
> wrong?
>
> Thanks,
> RABMissouri
>
>


0
drbert (27)
4/6/2004 12:14:35 PM
Reply:

Similar Artilces:

Use hyperlink to open workbook read only?
Excel 2003 SP3 on XP Pro SP3 I have a workbook I have created to use as an index to infrequently used workbooks using hyperlinks to create a point and click Document Index. It works well for why I created it; now I'd like the ability to encode some of the links to open read-only instead of read-write. I didn't find anything in the help files ... is this possible? Thanks in advance! Clif How many of these do you have and do they all point to same path but different workbook? I'm thinking of an alternative to Hyperlinks. Workbook names only in cells and ...

Read Only field not working
'This is a strange one. We have the estimatedvalue field set as read-only. However, in the UI it always comes up as editable. I thought perhaps it was a caching issue but its not. Has anyone seen this behavior before? This is with 4.0. Thanks! On Apr 5, 4:34 am, MDV1457 <MDV1...@discussions.microsoft.com> wrote: > 'This is a strange one. We have the estimatedvalue field set as read-only. > However, in the UI it always comes up as editable. I thought perhaps it was > a caching issue but its not. Has anyone seen this behavior before? This is > with 4.0. >...

Opens in Read-Only
We have just upgraded from 97 - XP and didn't have any major issues. We have a program that exports files in .DBF format to a network share that we have never had problems with before, until upgrading to XP. What happens is the files open in read-only if they are on the network share, but if you move the file to the local PC, it will open up. We have given full rights the to directory to no avail. Any opinions would greatly be appreciated. I've never used a .dbf file in real life, but there's a FAQ that describes your problem (but with Excel Workbooks). http://www.contextu...

elimiating all read receipts in an Exchange domain
Our Exchange 2003 users access email through the use of Outlook 2003 and Outlook 2000. we would like to eliminate the generation of all READ receipts in our company. Is there a way to globally turn of READ receipts on the exchange server or through the use of security/group policy templates in exchange? On Mon, 31 Oct 2005 14:11:02 -0800, "Civic" <Civic@discussions.microsoft.com> wrote: >Our Exchange 2003 users access email through the use of Outlook 2003 and >Outlook 2000. we would like to eliminate the generation of all READ receipts >in our company...

Read & print (float) double from filestream
Hi, How do I process (display) data from a file which has the type of DOUBLE ? The data in the file is for expl: "CD CC CC CC CC CC DC 3F", in Little Endian format. Thanks, Saya double d; CFile f; f.Open(...); while( f.Read((LPBYTE)&d, sizeof(d) ) { CString s; s.Format(_T("%d"), d); ...show s } f.Close(); (some details and error checking left as an Exercise For The Reader) joe On Thu, 04 Sep 2003 11:36:15 +0200, Saya <> wrote: > >Hi, > >How do I process (display) data from a file which has the type of >DOUBLE ?...

Reading XML into Listview Control
Hi, I have a dataset ds that I populated using ds.readXML(...). The problem I am having is to populate the a listview control with the data from this file. How do I go about doing this? I intent to use details view to allow me multiple columns as the XML file is in the following format: <contacts> <entry> <lastname>abc</lastname> <firstname>xyz</lastname> <entry> <entry> ...... </entry> </contacts> Thank you, Alij this may help http://www.codeproject.com/cs/miscctrl/ListViewApp.asp Cheers, Husam Al-a'araj www.a...

reading wmv files Outlook Express
How do i set up Outlook Express to read wmv files? I just get code characters. I do not know how to engage my media reader. This newsgroup is for support of Outlook 97, 98, 2000, 2002 & 2003 from the Office family for Intel PCs. For Outlook Express (OE) support try posting in one of these newsgroups: microsoft.public.inetexplorer.ie4.outlookexpress for OE 4.x microsoft.public.windows.inetexplorer.ie5.outlookexpress for OE 5.x http://support.microsoft.com/newsgroups/default.aspx?ICP=GSS3&NewsGroup=microsoft.public.windows.inetexplorer.ie5.outlookexpress&SLCID=US&sd=GN&...

Remote read file
I need to read a file on remote machines so I can get information from it. The machines are in two domains. The following line : Set fileItems = objSWbemServices.ExecQuery("Select * FROM CIM_DataFile WHERE Path = '\\' &HostName &'\\Program Files\\ClientBin\\' AND Extension = 'INI'") With Option Explicit on I get the error 500 "Variable is undefined" from error trapping. With option Explicit off I get error 80041017 at the next line which is: for each objItem in fileItems I don't have a problem getting computer names,...

4.4.1 read error
Hello, I have a new Exchange server that I have set up. It work well except it cannot receive Emails from a handful of domains. I have identified 3 domains so far, Roadrunner is one of them. The user that tries to send Email get the following bounceback message: From: "Mail Delivery Subsystem" <MAILER-DAEMON@ms-smtp-05.tampabay.rr.com> To: <0000000@cfl.rr.com> Sent: Sunday, January 14, 2007 1:57 AM Subject: Returned mail: see transcript for details The original message was received at Thu, 11 Jan 2007 20:49:40 -0500 (EST) > from 90.162.205.68.cfl.res.rr.com [68.2...

Delivery & Read Receipt Request
I am not able to find an option to request a mail delivery receipt and also a read receipt. I have always had these options on my system at work with Outlook, and even on Outlook Express on my home PC before I upgraded to Outlook 2002. I have recently updated Outlook with the SP-2 service pack. If someone is aware of how to request a mail delivery and a read receipt please advise. Thank you, Ron DeBruin if you compose a new message, select the "Options" button from the toolbar. (option to set read/delivery receipt should be 1/2 down.) "RJ DeBruin" <rdebruin@...

Add New Record / Make Existing Records Read Only
I would like open a form to add a new record and let the user browse existing records without being able to modify them. How can I accomplish this? Thanks On Sun, 7 Mar 2010 18:37:02 -0800, Ron <Ron@discussions.microsoft.com> wrote: >I would like open a form to add a new record and let the user browse existing >records without being able to modify them. How can I accomplish this? >Thanks Set the Form's Allow Additions property to Yes, and its Allow Edits property to No. -- John W. Vinson [MVP] Ron wrote: > I would like open a form to ad...

Read-only attribute lost when file transferred by email
Vista professional Office Professional 2007 More of a rhetorical question since probably nothing can be done about it... When I transfer via Outlook a Word file set as read-only (i.e., read- only set from the file's desktop icon > Properties, not from within Word), the read-only attribute is lost at the receiving end. I have to remind the recipient to reset the attribute. Why should this be the case? Thanks. wal <ress6oy8@verizon.net> wrote: >When I transfer via Outlook a Word file set as read-only (i.e., read- >only set from the file's deskto...

Excel read only
I work in a office with several other people and we have a spreed sheet or work book I guess you would call it that we all would like to use at the same time. Is there a way to remove the read only if some one else has it open? Thanks -- valrom06 You can set the file to be shared, it's under tools>share workbook. Note that there are some reported problems when you share a workbook like formatting but if you need key in data it can be handy -- Regards, Peo Sjoblom "valrom06" <valrom06@discussions.microsoft.com> wrote in message news:E8CB6E62-20B9-49F6-A1...

Read receipt #9
How to create a rule to move "Read receipt" notifications to another folder automatically? Any help will be appreciated. I am using outlook 2003. ...

read only
I have tried numerour times to set files to read/write. when I change and turn off real only and apply, files are run and after closing down properties, and re-opening read only is back. How to fix? -- L Sarratt Hi L, Log onto the workstation as the administrator and proceed to set the read/write properties on the folder. Thanks Don "wefishmarlin" wrote: > I have tried numerour times to set files to read/write. when I change and > turn off real only and apply, files are run and after closing down > properties, and re-opening > read only is back. How to fix?...

Reading news
Hi wondering if Ishould be using Window Mail, one of the web-base email program,or just use a web brower. What do you think? I think you should use a Web Browser since all MS newsgroups are being shut down... the only access will be with a web browser peter -- If you find a posting or message from me offensive,inappropriate or disruptive,please ignore it. If you dont know how to ignore a posting complain to me and I will be only too happy to demonstrate :-) "Torres K" <maria.ibon@ymail.com> wrote in message news:eVLP$8CALHA.1892@TK2MSFTNGP05.phx.gbl....

Money 2008 Premium
I have downloaded transactions and the import complete window says complete. But the account says "Transactions to read: 6" but when I click on that line nothing happens. I have donwloaded transactions from other accounts just fine. I have updated my Money software to the latest version. In microsoft.public.money, Richard M. wrote: >I have downloaded transactions and the import complete window says complete. >But the account says "Transactions to read: 6" but when I click on that line >nothing happens. I have donwloaded transactions from other accou...

Reading XML attributes with C#
Why do I always get '0' for attribute when i have tags like: <GNRS someAttribute="12">Some Text</GNRS> I read the attribute with: aReader.GetAttribute("someAttribute"); where aReader is a XmlTextReader type Mystique wrote: > Why do I always get '0' for attribute when i have tags like: > <GNRS someAttribute="12">Some Text</GNRS> > > I read the attribute with: > > aReader.GetAttribute("someAttribute"); > > where aReader is a XmlTextReader type Make sure the reader is positioned at G...

OL2K wont send read receipts
Due to the nature of some of the emails I receive, Read Receipts are requested. I have set-up OL2K to automatically reply to these requests, but have stumbled upon a problem. OL2K will reply, and the reply goes to the outbox - but because it does not seem to have a reply to address, it is not sent! How can I overcome this. It seems to work flawlessly in Outlook Express, but i need the full functionality of OL2K. Jason Russell Dotcom Computers Ltd are the receipts always from the same person or domain? -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours C...

Transaction to Read: 8 Every time!
I've been using Money 2005 Home and Business for a month or so now getting everything manually migrated from 7 years of Quickbooks. I've gotten everything connected online with my bank and most everything seems to be working ok. However, every time I download from my bank (Washington Mutual) the same sets of transactions show in the "Transaction to read: X". I accept the transactions, matched to an earlier entry, the register shows fine and the next time I start M2K5 and try to do a download they show up again as needing to be read. What gives? Is this a feature? ...

Outlook cannot read script
I am using Outlook 2002 and it is completely updated. I forwarded a copy of a web page to a group to which I belong. I added some text at the top of the page. When it came back to me and I opened the message, I did not see the text in the message. There was a banner up top that said, "This HTML message contains script, which Outlook cannot display. This may affect how the message appears." I have my security settings set to Internet. I have allowed script in all cases except the one which says "Allow scripting of Internet Explorer webbrowser [sic] control" is disabled...

Shared Workbook opens as read-only
I have a shared workbook which seems to work fine sometimes (multiple users can edit at the same time) but other times when I try to open it I get a message saying "file is locked for editing. Open as Read-Only". Why is this happening? How do I fix it? Thanks ...

how do I SET UP outlook 2003 for hebrew headers reading
Using Windows Vista Premium Familiar Edition with Outlook 2003 and Outlook 2003 Multilingual User Interface (MUI). Email messages downloaded from gmail via imap. Headers look like ??????? or giberish. ...

Make an entire Tab Read only
Hello Guys, I know how to disable the entire Form and how to make a Tab hidden, but how do I make all the fields on a Tab read only. Almost like a combination of those two. I think I'm close, but man, I just need a hint. thanks Hi, In the form customization view, double click the field and select the checkbox "disable on form". That will set the field to read only. Best Regards, Donna "CPI_CRM" wrote: > Hello Guys, > > I know how to disable the entire Form and how to make a Tab hidden, but how > do I make all the fields on a Tab read only. Al...

Read XHTML into XML
Hi all, I need to read/parse XHTML aspx pages and look for certain tokens and content. How can I use a XmlTextReader for this? If not, any other ideas? Thanks in advance, JA Reyes. Jose Antonio Reyes wrote: > I need to read/parse XHTML aspx pages and look for certain tokens and > content. How can I use a XmlTextReader for this? If not, any other ideas? If the pages are well-formed XHTML then it is possible to use XmlReader (in .NET 2.0/3.0) or XmlTextReader (in .NET 1.x) to parse the XHTML documents. You can also use the other XML APIs .NET provides so using XPathNavigator and/o...