Dmitry_
asked on
DirectShow question
I'm trying to create simple application for capturing single frame:
IGraphBuilder *pGraphBuilder = NULL;
hr = CoCreateInstance(CLSID_Fil terGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraphBuilder);
IMediaControl *pMediaControl = NULL;
hr = pGraphBuilder->QueryInterf ace(IID_IM ediaContro l, (void **)&pMediaControl);
ICaptureGraphBuilder2 *pCapture = NULL;
hr = CoCreateInstance(CLSID_Cap tureGraphB uilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void **)&pCapture);
hr = pCapture->SetFiltergraph(p GraphBuild er);
IBaseFilter *pSrcFilter = NULL;
hr = FindVideoCaptureDevice(&pS rcFilter);
hr = pGraphBuilder->AddFilter(p SrcFilter, L"Video Capture");
hr = pCapture->RenderStream(&PI N_CATEGORY _PREVIEW, &MEDIATYPE_Video, pSrcFilter, NULL, NULL);
hr = pMediaControl->Run();
::MessageBox(NULL, "waiting", "debug", MB_OK);
hr = pMediaControl->Pause();
//here hr = S_FALSE
IBasicVideo* bv = NULL;
hr = pMediaControl->QueryInterf ace(IID_IB asicVideo, (void **)&bv);
long lWidth, lHeight;
hr = bv->GetVideoSize(&lWidth, &lHeight);
long size;
hr = bv->GetCurrentImage(&size, NULL);
char* buffer = new char[size];
hr = bv->GetCurrentImage(&size, (long*)buf fer);
//here hr = E_UNEXPECTED
What's wrong in this code? How can I get image ?
IGraphBuilder *pGraphBuilder = NULL;
hr = CoCreateInstance(CLSID_Fil
IMediaControl *pMediaControl = NULL;
hr = pGraphBuilder->QueryInterf
ICaptureGraphBuilder2 *pCapture = NULL;
hr = CoCreateInstance(CLSID_Cap
hr = pCapture->SetFiltergraph(p
IBaseFilter *pSrcFilter = NULL;
hr = FindVideoCaptureDevice(&pS
hr = pGraphBuilder->AddFilter(p
hr = pCapture->RenderStream(&PI
hr = pMediaControl->Run();
::MessageBox(NULL, "waiting", "debug", MB_OK);
hr = pMediaControl->Pause();
//here hr = S_FALSE
IBasicVideo* bv = NULL;
hr = pMediaControl->QueryInterf
long lWidth, lHeight;
hr = bv->GetVideoSize(&lWidth, &lHeight);
long size;
hr = bv->GetCurrentImage(&size,
char* buffer = new char[size];
hr = bv->GetCurrentImage(&size,
//here hr = E_UNEXPECTED
What's wrong in this code? How can I get image ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you, Kimpan.
I try to obtain instance of SampleGrabber:
hr = CoCreateInstance(CLSID_Sam pleGrabber , NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&pF);
I got an error: class not registered.
I'm working on Windows 2000 Service Pack 2.
Maybe I need install some update?
I try to obtain instance of SampleGrabber:
hr = CoCreateInstance(CLSID_Sam
I got an error: class not registered.
I'm working on Windows 2000 Service Pack 2.
Maybe I need install some update?
SampleGrabber is a part of DirextX 8.x SDK
download example from www.wordware.com/directshow
ASKER
I have Microsoft Platform SDK July 2002 installed.
It's contain DirectX 8.1 SDK.
I'm not understanding what the problem due creating istnace of SampleGrabber.
I download the file from www.wordware.com/directshow
It's containing 16 examples, but I can't find example of SampleGrabber.
It's contain DirectX 8.1 SDK.
I'm not understanding what the problem due creating istnace of SampleGrabber.
I download the file from www.wordware.com/directshow
It's containing 16 examples, but I can't find example of SampleGrabber.
ASKER
I have Microsoft Platform SDK July 2002 installed.
It's contain DirectX 8.1 SDK.
I'm not understanding what the problem due creating istnace of SampleGrabber.
I download the file from www.wordware.com/directshow
It's containing 16 examples, but I can't find example of SampleGrabber.
It's contain DirectX 8.1 SDK.
I'm not understanding what the problem due creating istnace of SampleGrabber.
I download the file from www.wordware.com/directshow
It's containing 16 examples, but I can't find example of SampleGrabber.
oh, too bad. I thought the example I saw in the book was there too. Microsoft DirectX 8.1 SDK comes with source code to examples. Look for project SampGrabCB in the Samples folder
ASKER
I try SampGrabCB example, but I get error during creating instance of IMediaDet: file:SampGrabCB.cpp, line 95.
hr = CoCreateInstance( CLSID_MediaDet, NULL, CLSCTX_INPROC_SERVER, IID_IMediaDet, (void**) &pDet );
hr returns "class not registered"!
Maybe something missing on my DirectX SDK installation?
hr = CoCreateInstance( CLSID_MediaDet, NULL, CLSCTX_INPROC_SERVER, IID_IMediaDet, (void**) &pDet );
hr returns "class not registered"!
Maybe something missing on my DirectX SDK installation?
try to register qedit.dll in Windows\System32\
regsvr32 windows\system32\qedit.dll
regsvr32 windows\system32\qedit.dll
Hi, Dmitry_
So, how was your problem solved? I am having the same issue, and could not find qedit.dll on my machine (Win2k, with DirectX 9 downloaded).....is that the correct DLL name for "qedit.h"?
So, how was your problem solved? I am having the same issue, and could not find qedit.dll on my machine (Win2k, with DirectX 9 downloaded).....is that the correct DLL name for "qedit.h"?
ASKER
Just reinstallation of the DirectX SDK solve the problem.
you declare smartpointers to specific Interface with typedef called _COM_SMART_PTR_TYPEDEF:
_COM_SMARTPTR_TYPEDEF(IGra
_COM_SMARTPTR_TYPEDEF(IMed
_COM_SMARTPTR_TYPEDEF(IFil
now you have declared smartpointers to IGraphBuilder, IMediaControl and IFilterGraph. You create a smartpointer by simply adding 'Ptr' after the Interface name. To create a smartpointer to IMediaControl, you write IMediaControlPtr. Now see how easy it is to create a instance of FilterGraph and get the default interface, IGraphBuilder and get IMediaControl and IFilterGraph:
// create an instance of FilterGraph and get IGraphBuilder Interface
IGraphBuilderPtr spGraph(CLSID_FilterGraph)
// get IMediaControl interface from the instance
IMediaControlPtr spMediaControl = spGraph;
// get IFilterGraph interface from the instance
IFilterGraphPtr spFilter = spGraph;
this is all you have to do. Once you leave the scope, the smartpointers will call Release and take care of deletion. And this smartpointer is reference counting as well. If one interface couldn't be retrieved or an instance couldn't be created, an '_com_error' exception will be thrown. So you could use try-catch:
try {
IGraphBuilderPtr spGraph(CLSID_FilterGraph)
IMediaControlPtr spMediaControl = spGraph; // say this failed -> execption
}
catch (_com_error &comerr)
{
cout << "comerror : " << comerr.ErrorInfo() << endl;
}