Re: HANDLE hFile
I am using vc 6
This is the code to create the file ..
fileName is variable.
it consists of current date, time and a number,
HANDLE hFile = CreateFile(_T(fileName),
GENERIC_WRITE, FILE_SHARE_READ,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
TRACE("\n Couldn't create the file (%d)",GetLastError());
AfxMessageBox(_T("Couldn't create the file!"));
}
Trace prints out 123.
--
-thiru
"Joseph M. Newcomer" wrote:
I hope you meant
_T("filename")
and that fileName is not a variable name; if it is a variable name, the _T() is completely
inappropriate, since it only makes sense when string or character literals are used.
Why can't it create the file? There is always a reason, and you didn't give the reason.
Use ::GetLastError() to retrieve the reason and display it (see most of my code examples
on my MVP Tips site for an ErrorString call that converts error codes to printable strings
using ::FormatMessage).
Any error message you issue must be of the form shown by the example below
Error creating log file
filename here
Access denied
There are always three lines: the first line is text of your choice; the second line is
always the name of the file as used by the CreateFile call (the exact same string!), and
the third line is the ::GetLastError() code converted to a string with FormatMessage. Any
other approach is merely sloppy programming.
joe
On Tue, 4 Jul 2006 09:17:01 -0700, Thiru <Thiru@discussions.microsoft.com> wrote:
Hi all,
I am having a problem..
I used
HANDLE hFile = CreateFile(_T(fileName),
GENERIC_WRITE, FILE_SHARE_READ,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
to create a log file for my application and
It works on debug mode.
When i run my application on Release mode it says cannot create file.
any help would be great..
Thanks,
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm