Hi

I call CreateFile() in my program and write to it when receiving data. But sometime there could be errors in receiving data, and my program quits. But I found the empty file has been created in the location, and sometime I have problem to remove it - it throws "sharing violation error". How can I not to create the file unless I receive valid data

Here is how I call CreateFile()

HANDLE hFile = INVALID_HANDLE_VALUE
hFile = CreateFileA( sName
GENERIC_WRITE
0
NULL
OPEN_ALWAYS
FILE_FLAG_SEQUENTIAL_SCAN
0 )
if( hFile == INVALID_HANDLE_VALUE

//throw CCException( CWin32err(), GetLastError(), _T("Falied to create file") )
return CREATE_NFILE_ERR

..

Thanks
Peter

Re: Avoid the empty file when CreateFile() fails? by Igor

Igor
Wed Mar 03 16:34:39 CST 2004

"Peter" <anonymous@discussions.microsoft.com> wrote in message
news:222ECB7B-CAED-490A-AACD-AD4A7F3F3FD9@microsoft.com...
> I call CreateFile() in my program and write to it when receiving data.
But sometime there could be errors in receiving data, and my program
quits. But I found the empty file has been created in the location, and
sometime I have problem to remove it - it throws "sharing violation
error". How can I not to create the file unless I receive valid data?

Create it lazily - only create it when you have some data you can
immediately write to it.
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken