title: An invalid parameter was passed to a function that considers invalid parameters fatal
body: <p>I hope you can help me. I've got this function that I use to save bitmap images but I'm having trouble with the file name. I would like to save the image with the current date on the file name but how I'm currently doing it it's giving me the "An invalid parameter was passed to a function that considers invalid parameters fatal" error and the program crashes.</p>
  
  <p>Here is the function that gets the name from the main program:</p>
  
  <pre><code>void DoSave(char *Name)
  {
      time_t rawTime;
      struct tm *timeInfo;
      char buffer[100];
      string date;
  
      time(&amp;rawTime);
      timeInfo = localtime(&amp;rawTime);
  
      strftime(buffer, 100, " %c", timeInfo);
      date = buffer;
  
      string url("Images/");
      string name(Name);
      string extension(".bmp");
  
      string path = url + name + date + extension;
  
      // Open the file for writing
      FILE *f = fopen((const char*)&amp;path, "wb");
  
      // Save the image as bmp file
      BmpHelper::SaveTo8bppBmpFile(f, (LONG)m_ImageSizeX, (LONG)m_ImageSizeY, (unsigned char*)videoImage);
      fclose(f);
  }
  </code></pre>
  
  <p>Here is the function that saves the bitmaps</p>
  
  <pre><code>void BmpHelper::SaveTo8bppBmpFile(FILE *output, LONG width, LONG height, unsigned char *buffer)
  {
      f8bppHeader_.bfSize = (DWORD)(s8bppHeader_ + width * height);
  
      i8bppHeader_.biWidth = (LONG)width;
      i8bppHeader_.biHeight = -(LONG)height;
  
      fwrite(&amp;f8bppHeader_, sizeof(BITMAPFILEHEADER), 1, output);
      fwrite(&amp;i8bppHeader_, sizeof(BITMAPINFOHEADER), 1, output); // I get the error in this line
      fwrite(p8bpp, sizeof(RGBQUAD), 256, output);
      fwrite(buffer, width, height, output);
  }
  </code></pre>
  
  <p>Not sure you need this bit but I'll add it as well.</p>
  
  <pre><code>void BmpHelper::Init8bppHeaders()
  {
      f8bppHeader_.bfType = 'MB'; // Will be inverted during the fwrite
      s8bppHeader_ = (DWORD)(sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD) + 256 * sizeof(RGBQUAD));
      f8bppHeader_.bfReserved1 = 0;
      f8bppHeader_.bfReserved2 = 0;
      f8bppHeader_.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
  
      i8bppHeader_.biSize = sizeof(BITMAPINFOHEADER);
      i8bppHeader_.biPlanes = 1;
      i8bppHeader_.biBitCount = 8;
      i8bppHeader_.biCompression = BI_RGB;
      i8bppHeader_.biSizeImage = 0;
      i8bppHeader_.biXPelsPerMeter = 0;
      i8bppHeader_.biYPelsPerMeter = 0;
      i8bppHeader_.biClrUsed = 0;
      i8bppHeader_.biClrImportant = 0;
  
      for (size_t index = 0; index &lt; 256; ++index)
      {
          p8bpp[index].rgbBlue = (BYTE)index;
          p8bpp[index].rgbGreen = (BYTE)index;
          p8bpp[index].rgbRed = (BYTE)index;
          p8bpp[index].rgbReserved = 0;
      }
  }
  </code></pre>
  
  <p>If I remove the date from the path it works all right but it only saves the file with the url + name given and file format. I need the date to differentiate between files. Can you guys spot anything wrong with the code? Thanks in advance.</p>