Help! I can't create a file!
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.
Re: Help! I can't create a file!
If you just want simple read/write : it's easier to use streams.
Re: Help! I can't create a file!
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.
Re: Help! I can't create a file!
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.