IndyJoe
Newbie
Karma: +0/-0
Posts: 2
|
 |
« on: June 22, 2009, 11:02:00 PM » |
|
I tried to create an application using the code generator, but I'm getting 60+ errors when I try to build the app. I've never tried to create a program using C++, so I'm sure I'm doing something wrong. I'm trying to create an app that will automatically run a GraphEditPlus file, so maybe this wouldn't work regardless. If anyone can help, I would appreciate it. Here's my code:
#include "stdafx.h" #include <DShow.h> #include <initguid.h> #include <dvdmedia.h>
BOOL hrcheck (HRESULT hr, TCHAR* errtext) { if (hr >=S_OK) return FALSE; TCHAR szErr[MAX_ERROR_TEXT_LEN]; DWORD res = AMGetErrorText (hr, szErr, MAX_ERROR_TEXT_LEN); if (res) printf("Error %x: %s\n%s\n",hr, errtext,szErr); else printf("Error %x: %s\n", hr, errtext); return TRUE; }
//change this macro to fit your style of error handling #define CHECK_HR(hr, msg) if (hrcheck(hr, msg)) return hr;
CComPtr<IBaseFilter> CreateFilter(WCHAR* displayName) { CComPtr<IBindCtx> pBindCtx; HRESULT hr = CreateBindCtx(0, &pBindCtx); if (hrcheck(hr, "Can't create bind context")) return NULL;
ULONG chEaten = 0; CComPtr<IMoniker> pMoniker; hr = MkParseDisplayName(pBindCtx, displayName, &chEaten, &pMoniker); if (hrcheck(hr, "Can't create parse display name of the filter")) return NULL; CComPtr<IBaseFilter> pFilter; if (SUCCEEDED(hr)) { hr = pMoniker->BindToObject (pBindCtx, NULL, IID_IBaseFilter, (void**)&pFilter); if (hrcheck(hr, "Can't bind moniker to filter object")) return NULL; } return pFilter; }
CComPtr<IPin> GetPin(IBaseFilter *pFilter, LPCOLESTR pinname) { CComPtr<IEnumPins> pEnum; CComPtr<IPin> pPin;
HRESULT hr = pFilter->EnumPins(&pEnum); if (hrcheck(hr, "Can't enumerate pins.")) return NULL;
while(pEnum->Next(1, &pPin, 0) == S_OK) { PIN_INFO pinfo; pPin->QueryPinInfo(&pinfo); BOOL found = !wcsicmp(pinname, pinfo.achName); if (pinfo.pFilter) pinfo.pFilter->Release(); if (found) return pPin; pPin.Release(); } printf("Pin not found!\n"); return NULL; }
// {A753A1EC-973E-4718-AF8E-A3F554D45C44} DEFINE_GUID(CLSID_AC3Filter, 0xA753A1EC, 0x973E, 0x4718, 0xAF, 0x8E, 0xA3, 0xF5, 0x54, 0xD4, 0x5C, 0x44); //ac3filter.ax
HRESULT BuildGraph(IGraphBuilder *pGraph) { HRESULT hr = S_OK;
//graph builder CComPtr<ICaptureGraphBuilder2> pBuilder; hr = pBuilder.CoCreateInstance(CLSID_CaptureGraphBuilder2); CHECK_HR(hr, "Can't create Capture Graph Builder"); hr = pBuilder->SetFiltergraph(pGraph); CHECK_HR(hr, "Can't SetFiltergraph");
//add Virtual Cable 1 CComPtr<IBaseFilter> pVirtualCable1 = CreateFilter(L"@device:cm:(33D9A762-90C8-11D0-BD43-00A0C911CE86}\\Virtual Cable 1"); hr = pGraph->AddFilter(pVirtualCable1, L"Virtual Cable 1"); CHECK_HR(hr, "Can't add Virtual Cable 1 to graph");
//add AC3FILTER CComPtr<IBaseFilter> pAC3FILTER; hr = pAC3Filter.CoCreateInstance(CLSID_AC3Filter); CHECK_HR(hr, "Can't create AC3Filter"); hr = pGraph->AddFilter(pAC3Filter, L"AC3Filter"); CHECK_HR(hr, "Can't add AC3Filter to graph");
//add DirectSound: Creative SB Extigy CComPtr<IBaseFilter> pDirectSoundCreativeSBExtigy = CreateFilter(L"@device:cm:(E0F158E1-CB04-11D0-BD4E-00A0C911CE86}\\DirectSound: Creative SB Extigy:); hr = pGraph->AddFilter(pDirectSoundCreativeSBExtigy, L"DirectSound: Creative SB Extigy"); CHECK_HR(hr, "Can't add DirectSound: Creative SB Extigy to graph");
//connect Virtual Cable 1 and AC3Filter hr = pGraph->ConnectDirect(GetPin(pVirtualCable1, L"Capture"), GetPin(pAC3Filter, L"In"), NULL); CHECK_HR(hr, "Can't connect Virtual Cable 1 and AC3Filter");
//connect AC3Filter and DirectSound: Creative SB Extigy hr = pGraph->ConnectDirect(GetPin(pAC3Filter, L"Out"), GetPin(pDirectSoundCreativeSBExtigy, L"Audio Input pin (rendered)"), NULL);
return S_OK; }
int main(int argc, char* argv[]) ( USES_CONVERSION; CoInitialize(NULL); CComPtr<IGraphBuilder> graph; graph.CoCreateInstance(CLSID_FilterGraph);
if (argc<3) return 0; printf("Building graph...\n"); HRESULT hr = BuildGraph(graph, T2W(argv[1]), T2W(argv[2])); if (hr==S_OK) { printf("Running"); CComQIPtr<IMediaControl, &IID_IMediaControl> mediaControl(graph); hr = mediaControl->Run(); CHECK_HR(hr, "Can't run the graph"); CComQIPtr<IMediaEvent, &IID_IMediaEvent> mediaEvent (graph); BOOL stop = FALSE; while(!stop) { long ev=0, p1=0, p2=0; Sleep(500); printf("."); if (mediaEvent->GetEvent(&ev, &p1, &p2, 0)==S_OK) { printf("Done!\n"); stop = TRUE; } else if (ev == EC_ERRORABORT) { printf("An error occured: HRESULT=%X\N", P1); mediaControl->Stop(); stop = TRUE; } mediaEvent->FreeEventParams(ev, p1, p2); } } } CoUninitialize(); return 0; }
|