Microsoft DirectX 8.1 (C++) |
This topic applies to Windows XP Home Edition and Windows XP Professional only.
This article shows how to create an MFC application that hosts the Video Control. To set up the project, perform the following steps.
As mentioned in paragraph 4 above, msvidctl. dll contains two type libraries. But MFC only creates wrapper classes for some of the objects in one of the libraries. For an application developer, this means that you will be using a combination of techniques to access and control the various objects you will be working with. The following code snippets illustrate these techniques.
Create an instance of an MFC-generated wrapper class
All the COM calls are hidden. Notice that the method names in the wrapper classes are slightly different from the names generated by MIDL in the original header files.
CMSVidVideoRenderer myRenderer = m_VidCtl.GetActiveRenderer();
CRect sourceRect = myRenderer.GetSourceSize();
Create an instance of a Tuning Model COM object
Since MFC has not created any wrapper classes for the Tuning Model objects, we need to create and access them using the native COM methods such as CoCreateInstance and QueryInterface.
HRESULT hr;
CComPtr<ITuningSpaceContainer> pTuningSpaceContainer;
hr = CoCreateInstance(CLSID_SystemTuningSpaces,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITuningSpaceContainer,
reinterpret_cast<void**> (&pTuningSpaceContainer));
if(FAILED(hr){
AfxMessageBox("Failed to create system tuning spaces object");
return false;
}
long count = 0;
hr = pTuningSpaceContainer->get_Count(&count);
if(FAILED(hr)){
AfxMessageBox("Failed to get count");
return false;
}
Obtain a derived interface from a wrapper class
MFC does not give us a wrapper class for some derived interfaces such as IMSVidTuner, but the interface exists and we need to use it, so we have to use the m_lpDispatch member (an IDispatch pointer) of the wrapper class to call QueryInterface. It is in situations like this where we need the msvidctl.h file from the Platform SDK include file--in this case to supply the definition for IMSVidTuner.
CMSVidInputDevice inputDevice = m_VidCtl.GetInputActive();
if(inputDevice.m_lpDispatch) { //we have an active input
CComPtr<IMSVidTuner> myTuner;
inputDevice.m_lpDispatch->QueryInterface(__uuidof(IMSVidTuner),
reinterpret_cast<void**> &myTuner);
if(FAILED(hr)){AfxMessageBox("Failed to QI for tuner");return;}
//pATSCTR is an IATSCTuneRequest interface pointer
myTuner->put_Tune(pATSCTR);
} //end if