Click to See Complete Forum and Search --> : Help! I can't create a file!


Isa
March 30th, 1999, 03:21 AM
I try to create a file with this code :

DWORD dwWritten;

HANDLE myNewFile;

try

{

myNewFile = CreateFile(newFileName,

GENERIC_WRITE,

FILE_SHARE_WRITE,

NULL,

CREATE_NEW,

FILE_ATTRIBUTE_NORMAL,

NULL);

WriteFile(myNewFile,

&pDouble,

myFile.GetLength(),

&dwWritten,

NULL);

CloseHandle(myNewFile);

}

catch (CDaoException* e)

{

AfxMessageBox(e->m_pErrorInfo->m_strDescription);

e->Delete();

}

But no file is created!!!

The compiler says there is no error and no warning.

Could anyone help me find what's wrong in the code?


Thanks a lot.

Franky Braem
March 30th, 1999, 04:12 AM
If you just want simple read/write : it's easier to use streams.

Corey@MIT
March 13th, 2002, 02:16 PM
I can't help with your code, but here is an easy way to write files.

add a memeber variable e.g. CStdioFile m_fLog;

Open or create the file if it doesn't exist:

//open or create logfile for writing
m_fLog.Open("temp.txt",CFile::modeCreate
|CFile::modeNoTruncate
|CFile::modeWrite);
m_fLog.SeekToEnd();//append mode




write to the file (you can write CStrings instead of the constant text below)

m_fLog.WriteString("Hello file\n");




close the file

m_fLog.Close();




You can read the file with m_fLog.ReadString. I hope this helps.

Julian-Serban
May 14th, 2002, 12:19 PM
Hej my names is Julian.
And I am also a beginner in visual basic and i think that you should not have so much lines.
Try to make fewer lines.