title: Creating WAV chunks
body: <p>I'm trying to add custom chunks to existing WAV file. I'm using the mmioCreateChunk function but after it's execution nothing changes to the file. Here's the code of my program:</p>
  
  <pre><code>#include &lt;windows.h&gt; 
  #include &lt;mmsystem.h&gt; 
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  #pragma comment( lib, "winmm" )
  
  int main() 
  {
    HMMIO       hmmio;                 // file handle for open file 
    MMCKINFO    mmckinfoParent;        // parent chunk information 
    MMCKINFO    mmckinfoFormatChunk;   // Format chunk information structure 
    MMCKINFO    mmckinfoDataChunk;     // Data chunk information structure
    MMCKINFO    mmckinfoRdibChunk;     // Rdib chunk information structure
  
    // Open the file for reading with buffered I/O 
    // by using the default internal buffer   
    if(!(hmmio = mmioOpen(L"out.wav", NULL, 
      MMIO_READ))) 
    { 
      cout &lt;&lt; "Error opening file." &lt;&lt; endl;
      return 0; 
    }
  
    // Locate a "RIFF" chunk with a "WAVE" form type to make 
    // sure the file is a waveform-audio file. 
    mmckinfoParent.fccType = mmioFOURCC('W', 'A', 'V', 'E'); 
    if (mmioDescend(hmmio, (LPMMCKINFO) &amp;mmckinfoParent, NULL, 
      MMIO_FINDRIFF)) 
    { 
      cout &lt;&lt; "This is not a waveform-audio file." &lt;&lt; endl; 
      mmioClose(hmmio, 0); 
      return 0; 
    }
  
    // Find the "FMT" chunk (form type "FMT"); it must be 
    // a subchunk of the "RIFF" chunk. 
    mmckinfoFormatChunk.ckid = mmioFOURCC('f', 'm', 't', ' '); 
    if (mmioDescend(hmmio, &amp;mmckinfoFormatChunk, &amp;mmckinfoParent, 
      MMIO_FINDCHUNK)) 
    { 
      cout &lt;&lt; "Waveform-audio file has no \"FMT\" chunk." &lt;&lt; endl; 
      mmioClose(hmmio, 0); 
      return 0; 
    }
  
    unsigned int fmtSize = mmckinfoFormatChunk.cksize;
    char * waveFmt = new char[fmtSize];
    mmioRead(hmmio, waveFmt, mmckinfoFormatChunk.cksize);
  
    mmioAscend(hmmio, &amp;mmckinfoFormatChunk, 0); 
  
    // Find the data subchunk. The current file position should be at 
    // the beginning of the data chunk; however, you should not make 
    // this assumption. Use mmioDescend to locate the data chunk. 
    mmckinfoDataChunk.ckid = mmioFOURCC('d', 'a', 't', 'a'); 
    if (mmioDescend(hmmio, &amp;mmckinfoDataChunk, &amp;mmckinfoParent, 
      MMIO_FINDCHUNK)) 
    { 
      cout &lt;&lt; "Waveform-audio file has no data chunk." &lt;&lt; endl; 
      mmioClose(hmmio, 0); 
      return 0;
    }
  
    unsigned int size = mmckinfoDataChunk.cksize;
    char* data = new char[size];
    mmioRead(hmmio, data, size);
    mmioClose(hmmio, 0);
  
    ifstream fs;
    fs.open("out.txt");
  
    // get length of file:
    fs.seekg (0, ios::end);
    int length = fs.tellg();
    fs.seekg (0, ios::beg);
  
    // allocate memory:
    char* buffer = new char [length];
  
    // read data as a block:
    fs.read (buffer,length);
    fs.close();
  
    HMMIO hmmio_out;
  
    //Creating new wav file.
    hmmio_out = mmioOpen(L"test.wav", 0, MMIO_CREATE | MMIO_WRITE);
  
    //Creating RIFF chunk
    mmioCreateChunk(hmmio_out, &amp;mmckinfoParent, MMIO_CREATERIFF);
  
    //Creating format chunk and inserting information from source file
    mmioCreateChunk(hmmio_out, &amp;mmckinfoFormatChunk, 0);
    mmioWrite(hmmio_out, waveFmt, mmckinfoFormatChunk.cksize);
  
    mmioAscend(hmmio_out, &amp;mmckinfoFormatChunk, 0);
  
    //Creating data chunk and inserting information from source file
    mmioCreateChunk(hmmio_out, &amp;mmckinfoDataChunk, 0);
    mmioWrite(hmmio_out, data, mmckinfoDataChunk.cksize);
  
    mmioAscend(hmmio_out, &amp;mmckinfoDataChunk, 0);
  
    //Creating new rdib chunk and inserting information from out.txt
    mmckinfoRdibChunk.ckid = mmioFOURCC('r', 'd', 'i', 'b');
    mmckinfoRdibChunk.cksize = sizeof(char) * length;
    mmioCreateChunk(hmmio_out, &amp;mmckinfoRdibChunk, 0);
  
    mmioWrite(hmmio_out, buffer, sizeof(char) * length);
  
    mmioAscend(hmmio_out, &amp;mmckinfoRdibChunk, 0);
  
    // Close the file. 
    mmioClose(hmmio_out, 0); 
  
    return 0; 
  }
  </code></pre>
  
  <p>What I have to do to create new chunk?</p>