📄 subject_25651.htm
字号:
<p>
序号:25651 发表者:笨蛋 发表日期:2002-12-24 16:00:28
<br>主题:SetFileName为什么不能生成预期的文件?
<br>内容:请帮忙看看:<BR> hr=CoCreateInstance(CLSID_FileWriter,NULL,CLSCTX_INPROC_SERVER,<BR> IID_IFileWriter,(void**)&pWriter);<BR> pSink->QueryInterface(IID_IFileSinkFilter, (void**)&pSink);<BR> if(SUCCEEDED(hr))<BR> hr=pGraphBuilder->AddFilter (pWriter,L"file writer");<BR> hr=pSink->SetFileName (L"d:\\myfile.avi",NULL);<BR>按理说,运行后应该生成文件:myfile,可是程序运行并没有生成,为什么?谢谢<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:super 回复日期:2002-12-24 16:24:22
<br>内容:你的代码本来就写错了啊。<BR>比如:pSink->QueryInterface(IID_IFileSinkFilter, (void**)&pSink);<BR>这一行中pSink既然没有值,如何能调用Query??<BR><BR>正确写法是:<BR>hr=CoCreateInstance(CLSID_FileWriter,NULL,CLSCTX_INPROC_SERVER,<BR> IID_IFileSinkFilter,(void**)&pSink);<BR>pSink->QueryInterface(IID_IFileWriter, (void**)&pWriter);<BR>if(SUCCEEDED(hr))<BR>{<BR> hr=pGraphBuilder->AddFilter (pWriter,L"file writer");<BR> hr=pSink->SetFileName (L"d:\\myfile.avi",NULL);<BR>}
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:禽兽 回复日期:2002-12-24 18:39:59
<br>内容:pWriter->QueryInterface(IID_IFileWriter, (void**)&pSink);<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:super 回复日期:2002-12-24 20:16:13
<br>内容:IID_IFileWriter的结果指针不是IFileSinkFilter
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:笨蛋 回复日期:2002-12-24 20:24:01
<br>内容:呵呵,我是笔误,我的代码是正如guanbo所说的那样,我也曾象super那样改过,但是结果还是不行
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:禽兽 回复日期:2002-12-24 22:05:32
<br>内容:不好意思,剪贴复制没有仔细看.
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:super 回复日期:2002-12-24 22:36:12
<br>内容:你先确定你用到的filter可以在graphedit中构造出来,检查是不是其他地方出错了,正常情况在AddFilter时就产生一个空的文件了。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:笨蛋 回复日期:2002-12-25 10:57:29
<br>内容:在graphedit中构造出来的FILTER没有问题,连接也是正确的,可是就是没有生成文件,还可能是什么地方出错呢?请指教哦
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:super 回复日期:2002-12-25 13:34:38
<br>内容:判断AddFilter和其他操作的返回值是否正确,不行就贴出全部相关代码
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:笨蛋 回复日期:2002-12-25 15:11:01
<br>内容:IBaseFilter *pFileSourceFilter = NULL;<BR>IBaseFilter*pAviDest = NULL,*pWriter = NULL; IFileSinkFilter *pSink= NULL;<BR>IGraphBuilder *pGraphBuilder;<BR>HRESULT hr;<BR> // IEnumPins *pEnum;<BR>// TODO: Add your control notification handler code here<BR>CoInitialize(NULL);<BR>CoCreateInstance<BR>(CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER,<BR>IID_IGraphBuilder,(void**)&pGraphBuilder);<BR> ////<BR>hr=CoCreateInstance(CLSID_AsyncReader,NULL,CLSCTX_INPROC_SERVER,<BR> IID_IBaseFilter,(void**)&pFileSourceFilter);<BR> //<BR>if(pFileSourceFilter)<BR><BR>hr=pGraphBuilder->AddSourceFilter(L"D:\\avi.avi",L"FileSource",&pFileSourceFilter);<BR><BR><BR> // Add the AVI mux and the File Writer.<BR> hr=CoCreateInstance(CLSID_AviDest, NULL, CLSCTX_INPROC_SERVER,<BR> IID_IBaseFilter, (void**)&pAviDest);<BR>if(SUCCEEDED(hr))<BR>if(pAviDest)<BR>pGraphBuilder->AddFilter(pAviDest,L"avidest");<BR><BR> CoCreateInstance(CLSID_FileWriter, NULL, CLSCTX_INPROC_SERVER,<BR> IID_IBaseFilter, (void**)&pWriter);<BR> if(pWriter)<BR> {<BR> hr=pGraphBuilder->AddFilter(pWriter,L"writer");<BR> // Set the file name.<BR> pWriter->QueryInterface(IID_IFileSinkFilter, (void**)&pSink);<BR> //#<BR> if(pSink)<BR> <BR> hr=pSink->SetFileName(L"D:\\myfile.avi", NULL);<BR><BR> }<BR><BR> IPin *pOut = GetPin(pFileSourceFilter, PINDIR_OUTPUT); <BR> if (pOut) <BR> {<BR> IPin *pIn=GetPin(pAviDest,PINDIR_INPUT);<BR> hr=pGraphBuilder->Connect(pOut,pIn);<BR> }<BR> <BR> IPin *pOut2 = GetPin(pAviDest, PINDIR_OUTPUT); <BR> if (pOut2) <BR> {<BR> IPin *pIn2 = GetPin(pWriter, PINDIR_INPUT);<BR> pGraphBuilder->ConnectDirect(pOut2, pIn2, NULL);<BR> }<BR><BR><BR><BR><BR>static IPin* GetPin( IBaseFilter* pFilter, PIN_DIRECTION dir )<BR>{<BR> IEnumPins* pEnumPins = 0;<BR> IPin* pPin = 0;<BR> <BR> if( pFilter )<BR> {<BR> <BR> pFilter->EnumPins( &pEnumPins );<BR> if( pEnumPins != 0 )<BR> {<BR> for(;;)<BR> {<BR> ULONG cFetched = 0;<BR> PIN_DIRECTION pinDir = PIN_DIRECTION(-1); <BR> pPin = 0;<BR><BR> pEnumPins->Next( 1, &pPin, &cFetched );<BR> if( cFetched == 0 || pPin == 0 ) break;<BR><BR> pPin->QueryDirection( &pinDir );<BR> if( pinDir == dir ) break;<BR> pPin->Release();<BR> }<BR> pEnumPins->Release();<BR> }<BR> }<BR><BR> return pPin;<BR>}<BR><BR>以上就是主要代码,多谢指教! <BR>2002-12-25 15:37:37
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -