这两天碰到了奇怪的问题,加入DeleteMediaType()释放内存后,编绎成功,但链接失败,找到N个重名符号.查找帮助文档,依葫芦画瓢,替换成以下代码就正常了,看来DirectShow也知道会有这个问题吧:
Use this function to release any media type structure that was allocated using either CoTaskMemAlloc or CreateMediaType.
If you prefer not to link to the base class library, you can use the following code directly:
void MyDeleteMediaType(AM_MEDIA_TYPE *pmt)
{
if (pmt != NULL)
{
MyFreeMediaType(*pmt); // See FreeMediaType for the implementation.
CoTaskMemFree(pmt);
}
}
void MyFreeMediaType(AM_MEDIA_TYPE& mt)
{
if (mt.cbFormat != 0)
{
CoTaskMemFree((PVOID)mt.pbFormat);
mt.cbFormat = 0;
mt.pbFormat = NULL;
}
if (mt.pUnk != NULL)
{
// Unecessary because pUnk should not be used, but safest.
mt.pUnk->Release();
mt.pUnk = NULL;
}
}