Click here to Skip to main content
15,895,084 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: troubles in making a filecopy program in visual c++ Pin
Stlan12-Jul-05 23:26
Stlan12-Jul-05 23:26 
GeneralRe: troubles in making a filecopy program in visual c++ Pin
firebolt7713-Jul-05 3:53
firebolt7713-Jul-05 3:53 
GeneralRe: troubles in making a filecopy program in visual c++ Pin
Stlan13-Jul-05 3:59
Stlan13-Jul-05 3:59 
GeneralRe: troubles in making a filecopy program in visual c++ Pin
David Crow13-Jul-05 5:45
David Crow13-Jul-05 5:45 
GeneralRe: troubles in making a filecopy program in visual c++ Pin
David Crow13-Jul-05 3:18
David Crow13-Jul-05 3:18 
GeneralRe: troubles in making a filecopy program in visual c++ Pin
Joe Woodbury13-Jul-05 8:10
professionalJoe Woodbury13-Jul-05 8:10 
GeneralRe: troubles in making a filecopy program in visual c++ Pin
firebolt7713-Jul-05 16:27
firebolt7713-Jul-05 16:27 
GeneralRe: troubles in making a filecopy program in visual c++ Pin
Joe Woodbury13-Jul-05 17:44
professionalJoe Woodbury13-Jul-05 17:44 
Interesting, since it doesn't compile, you couldn't have tried my code. For one, you didn't include the right headers so the call to AfxWinInit would fail when compiling. Second you would need to declare an instance of CWinApp. Third CFile::Write() is a void function.

The problem actually likely lies with the failure to check for failure with the dataFile.Open call if e:/data.txt doesn't exist or can't be otherwise opened.

I simplified it and compiled the file below.

An additional possibility is that your project is not set up correctly. So, before continuing, close the project and create a new one with Visual Studio. Assuming you are using VS 2003, On the File menu, click New and then Project. In the left pane, open Visual C++ Projects and the Win32 folder. In the right pane Select Win32 Console Project and enter a project name in the Name edit control, and then click OK.

In the wizard, select Application Settings and then click the MFC checkbox in the right, and then "Finish."

When the project opens, select everything in Main between the two outer braces, then paste the code below into it. Compile and run.

Here is the code as I compiled in a console project:

if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
    _tprintf(_T("Fatal Error: MFC initialization failed\n"));
    return 1;
}

CFile logFile, dataFile;

CFileException err;

if (!dataFile.Open("e:/data.txt", CFile::modeRead | CFile::shareDenyWrite, &err))
{
    err.ReportError();
    return 1;
}

if (!logFile.Open("e:/data1.txt", CFile::modeReadWrite | CFile::modeCreate | CFile::modeNoTruncate | CFile::shareDenyWrite, &err))
{
    err.ReportError();
    return 1;
}
logFile.SeekToEnd();

int rval = 0;

int bufferLen = (int) dataFile.GetLength();
char* pBuffer = new char[bufferLen];
if (dataFile.Read(pBuffer, bufferLen) == dataFile.GetLength())
{
    logFile.Write(pBuffer, bufferLen);
}
delete [] pBuffer;
return rval;




Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke

GeneralRe: troubles in making a filecopy program in visual c++ Pin
firebolt7714-Jul-05 0:21
firebolt7714-Jul-05 0:21 
QuestionDatabase existense in SQL Server ? Pin
Babarsaeed12-Jul-05 19:11
Babarsaeed12-Jul-05 19:11 
AnswerRe: Database existense in SQL Server ? Pin
Christian Graus12-Jul-05 19:51
protectorChristian Graus12-Jul-05 19:51 
AnswerRe: Database existense in SQL Server ? Pin
basementman13-Jul-05 5:00
basementman13-Jul-05 5:00 
Generalstatic global variables problem Pin
VV114412-Jul-05 19:07
VV114412-Jul-05 19:07 
GeneralRe: static global variables problem Pin
Christian Graus12-Jul-05 19:47
protectorChristian Graus12-Jul-05 19:47 
GeneralRe: static global variables problem Pin
Bob Stanneveld12-Jul-05 21:04
Bob Stanneveld12-Jul-05 21:04 
GeneralRe: static global variables problem Pin
VV114413-Jul-05 7:06
VV114413-Jul-05 7:06 
GeneralRe: static global variables problem Pin
Bob Stanneveld13-Jul-05 20:28
Bob Stanneveld13-Jul-05 20:28 
GeneralXP-Style menu in win32 Pin
Anonymous12-Jul-05 18:36
Anonymous12-Jul-05 18:36 
GeneralRe: XP-Style menu in win32 Pin
Graham Bradshaw12-Jul-05 22:03
Graham Bradshaw12-Jul-05 22:03 
GeneralVirtualAlloc at specific address Pin
Blake V. Miller12-Jul-05 18:10
Blake V. Miller12-Jul-05 18:10 
GeneralRe: VirtualAlloc at specific address Pin
Toby Opferman12-Jul-05 19:56
Toby Opferman12-Jul-05 19:56 
GeneralRe: VirtualAlloc at specific address Pin
Blake Miller13-Jul-05 8:06
Blake Miller13-Jul-05 8:06 
GeneralTLS in a static library Pin
Chintoo72312-Jul-05 18:06
Chintoo72312-Jul-05 18:06 
GeneralRe: TLS in a static library Pin
Chintoo72312-Jul-05 18:15
Chintoo72312-Jul-05 18:15 
GeneralRe: TLS in a static library Pin
Magnus Westin13-Jul-05 2:32
Magnus Westin13-Jul-05 2:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.