Re: HANDLE hFile

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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@xxxxxxxxxxxxxxxxxxxxxxxxx> 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@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

.



Relevant Pages

  • Re: HANDLE hFile
    ... and that fileName is not a variable name; if it is a variable name, ... since it only makes sense when string or character literals are used. ... There is always a reason, and you didn't give the reason. ... It works on debug mode. ...
    (microsoft.public.vc.mfc)
  • Re: unbuffered file IO?
    ... Just curious...any reason why you can't use File.ReadAllLines(string ... fileName) and just use the index of the line in the resulting string[] ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Controlling Javascript from server side
    ... but five different language implementations here. ... 'true' means that the request must be handled asynchronously. ... There is exactly *no* reason for such a thing here. ... | percent-endoded string). ...
    (comp.lang.javascript)
  • file class
    ... private String _FileName; ... /// filename and all reqired parameters must be set up by user ... public TextFileServer(string FileName, int FixedRecordLen) ... //End of line built from constructor or user manual ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: file class
    ... private String _FileName; ... /// filename and all reqired parameters must be set up by user ... public TextFileServer(string FileName, int FixedRecordLen) ... //End of line built from constructor or user manual ...
    (microsoft.public.dotnet.languages.csharp)