LEADTOOLS Multimedia API Help > Programming with LEADTOOLS Multimedia > C++ Code > Copying ltmmMediaType Attributes and Data for C++ |
The following code demonstrates how to copy a media type's attributes and data to another media type.
// include the LEAD Multimedia TOOLKIT header #include "ltmm.h" ///////////////////////////////////////////////////////////////// // CopyMediaTypeAttributes // copies data and attributes from one media type to another // pDest - destination media type interface // pSource - source media type interface HRESULT CopyMediaTypeAttributes(IltmmMediaTypeDisp* pDest, IltmmMediaTypeDisp* pSource) { HRESULT hr; VARIANT_BOOL f; long l; BSTR bstr; long cbData; VARIANT var; // return error if NULL if(!pSource || !pDest) return E_POINTER; // get the format data size hr = pSource->get_FormatSize(&cbData); if(FAILED(hr)) return hr; // any format data if(cbData) { // yes, then copy away hr = pSource->GetFormatData(cbData, &var); if(FAILED(hr)) return hr; hr = pDest->SetFormatData(cbData, var); VariantClear(&var); if(FAILED(hr)) return hr; } else { // no, just set the dest to zero hr = pDest->put_FormatSize(0); if(FAILED(hr)) return hr; } // copy type bstr = NULL; pSource->get_Type(&bstr); pDest->put_Type(bstr); ::SysFreeString(bstr); // copy subtype bstr = NULL; pSource->get_Subtype(&bstr); pDest->put_Subtype(bstr); ::SysFreeString(bstr); // copy formattype bstr = NULL; pSource->get_FormatType(&bstr); pDest->put_FormatType(bstr); ::SysFreeString(bstr); // copy fixedsizesamples f = VARIANT_FALSE; pSource->get_FixedSizeSamples(&f); pDest->put_FixedSizeSamples(f); // copy temporalcompression f = VARIANT_FALSE; pSource->get_TemporalCompression(&f); pDest->put_TemporalCompression(f); // copy samplesize l = 0; pSource->get_SampleSize(&l); pDest->put_SampleSize(l); return S_OK; }