title: Is there anyway to make SOMETHING automatically add selected file extension to filename, when OPENFILENAME struct and GetSaveFileName() are used?
body: <p>I have this function:</p>
  
  <pre><code>void PickupFileAndSave(std::vector&lt;unsigned char&gt; file_data, int *error_code, char *file_mask = "All files (*.*)\0*.*\0\0")
  {
      OPENFILENAMEA ofn;       // common dialog box structure
      char szFile[MAX_PATH];   // buffer for file name
      char initial_dir[MAX_PATH] = { 0 };
      GetStartupPath(initial_dir);
  
      // Initialize OPENFILENAME
      ZeroMemory(&amp;ofn, sizeof(ofn));
      ofn.lStructSize = sizeof(ofn);
      ofn.hwndOwner = GetActiveWindow();
      ofn.lpstrFile = szFile;
      // Set lpstrFile[0] to '\0' so that GetOpenFileName does not 
      // use the contents of szFile to initialize itself.
      ofn.lpstrFile[0] = '\0';
      ofn.nMaxFile = sizeof(szFile);
      ofn.lpstrFilter = file_mask;
      ofn.nFilterIndex = 1;
      ofn.lpstrFileTitle = NULL;
      ofn.nMaxFileTitle = 0;
      ofn.lpstrInitialDir = initial_dir;
      ofn.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER;
  
      if (!GetSaveFileNameA(&amp;ofn))
      {
          *error_code = GetLastError();
          return;
      }
  
      char err_msg[1024] = { 0 };
      std::string file_name = ofn.lpstrFile; //this stores path to file without extension
      file_name.append(".");
      file_name.append(ofn.lpstrDefExt); //this is NULL and fails to copy too
      WriteAllBytes(file_name.c_str(), &amp;file_data[0], file_data.size(), &amp;err_msg[0]);
  
      if (strlen(err_msg) &gt; 0)
      {
          *error_code = GetLastError();
          return;
      }       
  }
  </code></pre>
  
  <p>I call it that way:     </p>
  
  <pre><code>int write_error = 0;
  PickupFileAndSave(compressed, &amp;write_error, "RLE compressed files (*.rle)\0*.rle\0\0");
  </code></pre>
  
  <p>When I choose file it shows in the filter needed extension, but do not add it to <strong>lpstrFile</strong>.</p>
  
  <p>Any ideas why and how to fix it?</p>