/// <summary>
/// Called instead of a constructor to acquire a WaveWriter
/// </summary>
/// <remarks>
/// Be sure to call Stop to close the object
/// </remarks>
/// <param name="fileName">Name the file to write to</param>
/// <param name="WaveFormat">Pointer to a WAVEFORMATEX structure describing the audio stream</param>
WaveWriter * WaveWriter::Start(const string& fileName,  const WAVEFORMATEX * WaveFormat )
{

    HANDLE fileHandle = CreateFile(fileName.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 
    FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 
    NULL);

    if (fileHandle == NULL)
    {
        return NULL;
    }

    WaveWriter * writer = new WaveWriter(fileHandle, WaveFormat);
    //StringCchCopy(writer->m_szFilename, _countof(writer->m_szFilename), "xxxxxxxxxxxxxx.wav");

    // Yes, we do this twice.... Once to advance the write pointer so we don't lose any samples,
    // and then once to put in the right length.
    writer->WriteFileHeader();

    return writer;
}