Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-08-2008, 12:43 PM
tootypegs tootypegs is offline
Newbie
 
Join Date: Nov 2007
Posts: 4
Rep Power: 0
tootypegs is on a distinguished road
Default CreateFile function C++

Hi i have the follwoing code but i am experiancing a lot of problems. I am to read a specific number of bytes (Size_of_the_file) from a fileand store them in a newly created file (OUTPUT_FILE).

I seem to be experiancing a number of errors regarding the use of my own variable for file paths in the CreateFile and WriteFile functions and the buffer.


can anyone see where ive gone wrong?


Code:
// Creating a file. OUTPUT_FILE contains a string for the path and file name
HANDLE FileCreate;
FileCreate = CreateFile("OUTPUT_FILE", GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);


char buffer[Size_of_the_file];       //buffer set to size of variable 'Size_of_the_file'

Reading_file.seekg (start_byte,std::ios::beg) ;  //positiong the ReadFile funstion at the correct place in the file to start

Reading_file = ReadFile("C:\\temp\\usbimage2.txt", &buffer, nBytesToRead, Size_of_the_file, NULL) ;  // Reading file

// Check for end of buffer. If complete write to OUTPUT_FILE 
if (Reading_file &&  nBytesRead == 0, ) 
{ 

WriteFile(OUTPUT_FILE, buffer, nBytesToRead, numBytesWritten)

}

thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 01-21-2008, 02:17 PM
dargueta dargueta is offline
Guru
 
Join Date: Oct 2007
Age: 18
Posts: 793
Last Blog:
Programs Under the Hoo...
Rep Power: 13
dargueta is a jewel in the roughdargueta is a jewel in the roughdargueta is a jewel in the roughdargueta is a jewel in the rough
Default

You're using CreateFile to open a file called "OUTPUT_FILE" instead of using the contents of OUTPUT_FILE as the file name. Just get rid of the quotes in the third line and you'll be fine.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-22-2008, 11:48 PM
dargueta dargueta is offline
Guru
 
Join Date: Oct 2007
Age: 18
Posts: 793
Last Blog:
Programs Under the Hoo...
Rep Power: 13
dargueta is a jewel in the roughdargueta is a jewel in the roughdargueta is a jewel in the roughdargueta is a jewel in the rough
Default

I also spotted several other problems:

(1) You're destroying the file handle by setting the read to the return value of ReadFile.
Code:
Reading_file = ReadFile("C:\\temp\\usbimage2.txt", &buffer, nBytesToRead, Size_of_the_file, NULL) ;

//should be
BOOL bSuccess = FALSE;
bSuccess = ReadFile(Reading_file,&buffer, Size_of_the_file, &nBytesToRead,  NULL) ;
(2) WriteFile takes the file handle as the first parameter, not the file path:

Code:
WriteFile(OUTPUT_FILE,&buffer, nBytesToRead, numBytesWritten)

//should be
WriteFile(FileCreate,&buffer,nBytesToRead,&numBytesWritten);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SecurityAudit vinay Visual Basic Programming 27 01-07-2008 01:14 PM
multi-pass preprocessing kenna C and C++ 11 08-14-2007 11:45 AM
Reg Fucntion pointers sowmi C and C++ 9 07-29-2007 04:29 AM
small help in this generator function plz SamehSpiky C and C++ 3 06-22-2007 12:47 PM


All times are GMT -5. The time now is 11:43 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 101%


Complete - Celebrate!

Ads