Adding a Custom Target Format for C

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

   IltmmConvert__get_TargetFormats(pConvert, &pFormats);

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

   // get the new format
   IltmmTargetFormats__get_Count(pFormats, &count);
   IltmmTargetFormats_Item(pFormats, 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}");

     IltmmTargetFormat__put_Sink(pFormat, 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}");
   IltmmTargetFormat__put_Mux(pFormat, bstr);
   SysFreeString(bstr);

   // specify what streams your new format can have 
IltmmTargetFormat__put_Streams
(pFormat, ltmmTargetFormat_Stream_Audio | ltmmTargetFormat_Stream_Video);

   // get the streams
   IltmmTargetFormat__get_Streams(pFormat, &lStreams);

   // verify them if needed ...

   // that is it
   IUnknown_Release(pFormat);
   IUnknown_Release(pFormats);

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

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