Adding a Custom Target Format for C++

long AddCustomFormat(IltmmConvert *pConvert)
{
   IltmmTargetFormats* pFormats;
   IltmmTargetFormat* pFormat;
   BSTR bstr;
   long count, lStreams;

   pConvert->get_TargetFormats(&pFormats);

   // add a new format at the end of the formats list
   bstr = SysAllocString(L"My Own Format");
   pFormats->Add(bstr, -1);

   // get the new format
   pFormats->get_Count(&count);
   pFormats->Item(count-1, &pFormat);

   // set the format's sink filter: this example uses "LEAD Network Sink"
   bstr = SysAllocString(L"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\\{E2B7DE05-38C5-11D5-91F6-00104BDB8FF9}");
   pFormat->put_Sink(bstr);
   SysFreeString(bstr);

   // set the format's mux filter: : this example uses "LEAD Network Multiplexer"
   bstr = SysAllocString(L"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\\{E2B7DE01-38C5-11D5-91F6-00104BDB8FF9}");
   pFormat->put_Mux(bstr);
   SysFreeString(bstr);

   // specify what streams your new format can have
   pFormat->put_Streams(ltmmTargetFormat_Stream_Audio|ltmmTargetFormat_Stream_Video);

   // get the streams
   pFormat->get_Streams(&lStreams);

   // verify them is needed ...

   // thats it
   pFormat->Release();
   pFormats->Release();

   // call put_TargetFormat(count-1) to use your new format.

   // return the format index
   return (count-1);
}