佚名通过本文主要向大家介绍了同样的爱,同样的英文,同样,两根同样长的蜡烛,两根同样长的铁丝等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题: 同样的代码为什么在我的程序中PrepareToEncode失败?
描述:
线程中的代码:
HRESULT hr;
IWMEncoder* pEncoder;
IWMEncDataView* pPreview;
IWMEncDataView2* pPreview2;
IWMEncDataViewCollection* pPreviewColl;
IWMEncSourceGroupCollection* pSrcGrpColl;
IWMEncSourceGroup* pSrcGrp;
IWMEncSource* pSrcAud;
IWMEncSource* pSrcVid;
IWMEncProfileCollection* pProColl;
IWMEncProfile* pPro;
IWMEncBroadcast* pBrdCst;
CComBSTR bstrName = NULL;
// Initialize the COM library and retrieve a pointer
// to an IWMEncoder interface.
hr = CoInitialize(NULL);
if ( SUCCEEDED( hr ) )
{
hr = CoCreateInstance(CLSID_WMEncoder,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWMEncoder,
(void**) &pEncoder);
}
// Retrieve a pointer to an IWMEncSourceGroupCollection interface.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->get_SourceGroupCollection(&pSrcGrpColl);
}
// Add a source group to the collection.
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrpColl->Add(CComBSTR("SG_1"), &pSrcGrp);
}
// Add a video source and an audio source.
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->AddSource(WMENC_VIDEO, &pSrcVid);
}
// Specify the sources.
if ( SUCCEEDED( hr ) )
{
hr = pSrcVid->SetInput(CComBSTR("Device://TE One Video Capture No.1 (1)"));
}
// Select the 5th profile from the collection and set it into the source group.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->get_ProfileCollection(&pProColl);
}
if ( SUCCEEDED( hr ) )
{
hr = pProColl->Item(4, &pPro);
}
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->put_Profile(CComVariant(pPro));
}
// Retrieve a pointer to a preview object.
if ( SUCCEEDED( hr ) )
{
hr = CoCreateInstance( CLSID_WMEncPreview,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWMEncDataView,
(void**)&pPreview);
}
// Retrieve the preview collection.
if ( SUCCEEDED( hr ) )
{
hr = pSrcVid->get_PreviewCollection( &pPreviewColl );
}
// Add the postiew object to the data view collection. If you set the
// cookie to -1, the encoder engine automatically generates a unique cookie.
long lCookie = -1;
if ( SUCCEEDED( hr ) )
{
hr = pPreviewColl->Add( pPreview, &lCookie);
}
// Continue configuring the encoder engine.
// Initialize the encoder engine.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->PrepareToEncode(VARIANT_TRUE);
}
// Start encoding.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->Start();
}
// Start viewing the stream in a pop-up window.
if ( SUCCEEDED( hr ) )
{
hr = pPreview->Start(lCookie);
}
int i = 0;
while ( i < 10000 )
{
MSG msg;
Sleep ( 100 );
while ( PeekMessage( &msg, 0, 0, 0, PM_REMOVE) )
{
 
描述:
本帖最后由 lx20010 于 2011-07-12 21:35:16 编辑
为什么我新建了一个对话框项目启动如下线程执行正常,但在我的程序中却PrepareToEncode失败,报E_NOINTERFACE错误呢?甚至在我的已有项目中调用WinExec启动对话框项目不能正常预览,但单独启动对话框项目就可以,奇怪了!线程中的代码:
HRESULT hr;
IWMEncoder* pEncoder;
IWMEncDataView* pPreview;
IWMEncDataView2* pPreview2;
IWMEncDataViewCollection* pPreviewColl;
IWMEncSourceGroupCollection* pSrcGrpColl;
IWMEncSourceGroup* pSrcGrp;
IWMEncSource* pSrcAud;
IWMEncSource* pSrcVid;
IWMEncProfileCollection* pProColl;
IWMEncProfile* pPro;
IWMEncBroadcast* pBrdCst;
CComBSTR bstrName = NULL;
// Initialize the COM library and retrieve a pointer
// to an IWMEncoder interface.
hr = CoInitialize(NULL);
if ( SUCCEEDED( hr ) )
{
hr = CoCreateInstance(CLSID_WMEncoder,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWMEncoder,
(void**) &pEncoder);
}
// Retrieve a pointer to an IWMEncSourceGroupCollection interface.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->get_SourceGroupCollection(&pSrcGrpColl);
}
// Add a source group to the collection.
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrpColl->Add(CComBSTR("SG_1"), &pSrcGrp);
}
// Add a video source and an audio source.
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->AddSource(WMENC_VIDEO, &pSrcVid);
}
// Specify the sources.
if ( SUCCEEDED( hr ) )
{
hr = pSrcVid->SetInput(CComBSTR("Device://TE One Video Capture No.1 (1)"));
}
// Select the 5th profile from the collection and set it into the source group.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->get_ProfileCollection(&pProColl);
}
if ( SUCCEEDED( hr ) )
{
hr = pProColl->Item(4, &pPro);
}
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->put_Profile(CComVariant(pPro));
}
// Retrieve a pointer to a preview object.
if ( SUCCEEDED( hr ) )
{
hr = CoCreateInstance( CLSID_WMEncPreview,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWMEncDataView,
(void**)&pPreview);
}
// Retrieve the preview collection.
if ( SUCCEEDED( hr ) )
{
hr = pSrcVid->get_PreviewCollection( &pPreviewColl );
}
// Add the postiew object to the data view collection. If you set the
// cookie to -1, the encoder engine automatically generates a unique cookie.
long lCookie = -1;
if ( SUCCEEDED( hr ) )
{
hr = pPreviewColl->Add( pPreview, &lCookie);
}
// Continue configuring the encoder engine.
// Initialize the encoder engine.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->PrepareToEncode(VARIANT_TRUE);
}
// Start encoding.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->Start();
}
// Start viewing the stream in a pop-up window.
if ( SUCCEEDED( hr ) )
{
hr = pPreview->Start(lCookie);
}
int i = 0;
while ( i < 10000 )
{
MSG msg;
Sleep ( 100 );
while ( PeekMessage( &msg, 0, 0, 0, PM_REMOVE) )
{