我正在尝试使用 SDK (PushSourceDesktop) 附带的桌面捕获过滤器。我编译它并且似乎成功使用它,因为它实际上捕获了我的桌面并将其保存到文件中。但是应用程序在完成/退出时崩溃。
当我打破错误时,它只说没有可用的源并且调用堆栈位置是 KernelBase.dll!7560280C()。
我想我在这里试一试,看看是否有人能识别出一些问题,或者我是否在做一些可能导致崩溃的公然错误的事情。提前致谢!
编辑:工作代码
int main()
{
HRESULT hr;
hr = CoInitialize(NULL);
{
CComPtr<IBaseFilter> pMux;
CComPtr<IMediaControl> pMC;
CComPtr<IBaseFilter> pFilterr;
CComPtr<IGraphBuilder> pGraph;
CComPtr<ICaptureGraphBuilder2> pBuild;
CComPtr<IUnknown> pUnk;
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER,
IID_ICaptureGraphBuilder2, (void**)&pBuild);
hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)(&pGraph));
hr = pBuild->SetFiltergraph(pGraph);
static CLSID const clsid = {0x4ea6930a, 0x2c8a, 0x4ae6, {0xa5, 0x61, 0x56, 0xe4, 0xb5, 0x4, 0x44, 0x37}}; //Pushsourcedesktop
hr = CreateObjectFromPath(TEXT("c:\\filters\\PushSource.dll"), clsid, &pUnk);
pFilterr = pUnk;
if (SUCCEEDED(hr))
{
HRESULT hr = pGraph->AddFilter(pFilterr, L"Private Filter");
}
hr = pBuild->SetOutputFileName(
&MEDIASUBTYPE_Avi, // Specifies AVI for the target file.
L"C:\\wav\\Example2.avi", // File name.
(IBaseFilter**)&pMux, // Receives a pointer to the mux.
NULL);
hr = pBuild->RenderStream(
NULL,//PIN_CATEGORY_CAPTURE,//NULL,//&PIN_CATEGORY_CAPTURE, // Pin category.
NULL,//&MEDIATYPE_Video,//&MEDIATYPE_Interleaved,//NULL,//&MEDIATYPE_Audio, // Media type.
pFilterr,//pSrc, // Capture filter.
NULL,//pCompression2, //pCompression, // Intermediate filter (optional).
(IBaseFilter*)pMux); // Mux or file sink filter.
hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pMC);
printf("START");
pMC->Pause();
hr = pMC->Run();
Sleep(4000);
hr = pMC->Stop();
printf("END");
}
CoUninitialize();
return 0;
}