title: Windows API - CreateFile() with OPEN_EXISTING set returns error code of ERROR_ALREADY_EXISTS (183)
body: <p>I am trying to open a named pipe using CreateFile(): </p>
  
  <pre><code>g_hPipe = CreateFile(szPipeName, 
                      GENERIC_READ | GENERIC_WRITE, 
                      0, 
                      NULL, 
                      OPEN_EXISTING, 
                      FILE_FLAG_OVERLAPPED, 
                      NULL);
  </code></pre>
  
  <p>where szPipeName looks like <code>\\\\.\\pipe\\service_name</code>, and I am getting INVALID_HANDLE_VALUE returned.</p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858%28v=vs.85%29.aspx" rel="nofollow">According to the MSDN</a>, the OPEN_EXISTING flag only returns an error if the file doesn't exist, yet <code>GetLastError()</code> shows ERROR_ALREADY_EXISTS (183). I know the file exists, that's why I'm using OPEN_EXISTING... The MSDN suggests this only occurs when OPEN_ALWAYS or CREATE_ALWAYS are set. I call <code>SetLastError(0)</code> immediately before <code>CreateFile()</code> to make sure the <code>GetLastError()</code> result is referring to the <code>CreateFile()</code> function. </p>
  
  <p>I've searched quite a bit and haven't found anything to suggest why I am receiving this error. Any help is appreciated.</p>