We had a line of code

```
    if( !CreateFile( m_hFile, szFile, GENERIC_READ|GENERIC_WRITE, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL ) )
    {
      DWORD dwErr = GetLastError();

      CString czInfo;
      czInfo.Format ("CMemoryMapFile::OpenAppend SetFilePointer call failed - GetLastError returned %d", dwErr);
      LOG(czInfo);

      return false;
    }

```

This code worked great for many years. A few weeks ago, we had a customer with a problem. Turns out, the problem could be traced to this line of code, where the function would return a INVALID\_HANDLE\_VALUE handle and GetLastError() returned ERROR\_FILE\_NOT\_FOUND(2).

Now, this is very confusing to us. OPEN\_ALWAYS should direct the file to be created if it does not exist. So, why are we getting a ERROR\_FILE\_NOT\_FOUND?

More confusion: For this customer, this only happened on one network share point (we were using a UNC path). Other UNC paths to other machines for this customer worked. Local paths worked. All our other customers (10000+ installs) have no problem at all.

The customer was using XP as the client OS, and the servers were running what appeared to be standard Windows Server 2003 (I think the Small Business Server version). We could not replicate their errors in our test lab using the same OS's. They could repeat the problem with several XP clients, but the problem was only on one server (other Server 2003 servers did not exhibit the problem).

We fixed the problem by nesting two CreateFile calls, the first with OPEN\_EXISTING, and the second with CREATE\_ALWAYS if OPEN\_EXISTING failed. So, we have no immediate need for a fix.

My question: Does anyone have any idea why this API call would fail in this particular way? We are puzzled.

Addendum:

The CreateFile function above is a wrapper on the Windows API function. Here's the code:

```
bool CMemoryMapFile::CreateFile( HANDLE & hFile, LPCSTR szFile, DWORD dwDesiredAccess, DWORD dwShareMode, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes )
{
  hFile = ::CreateFile (szFile, dwDesiredAccess, dwShareMode, NULL, 
                        dwCreationDisposition, dwFlagsAndAttributes, NULL);
  return (hFile != INVALID_HANDLE_VALUE) 
}

```