//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <qedit.h>
#include <control.h>
#include <uuids.h>
#include <stdio.h>
#include <evcode.h>
//---------------------------------------------------------------------------
struct TCopyData
{
int dwData;
int cbData;
void *lpData;
} ;
typedef TCopyData *PCopyData;
//-- var, const, procedure ---------------------------------------------------
#pragma argsused
void TraceString(AnsiString Msg)
{
TCopyData *CopyData;
HWND TraceWin;
char Buf[256];
TraceWin = FindWindow("TfrmDGCTrace", "DGC Trace"
;
if(TraceWin == 0)
exit;
// if(Strlen(Msg.Length(Msg) > 255)
// SetLength(Msg, 255);
StrPCopy(Buf, Msg);
CopyData->dwData = 0;
CopyData->cbData = Msg.Length() + 1;
CopyData->lpData = Buf;
SendMessage(TraceWin, WM_COPYDATA, 0, (long)(&CopyData));
}
int main(int argc, char* argv[])
{
HRESULT hr;
IGraphBuilder *pGraph;
IMediaControl *pMediaControl;
IMediaEventEx *pEv;
IBaseFilter *pSAMI;
CoInitialize(NULL);
// Create the filter graph manager.
CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC,
IID_IGraphBuilder, (void **)&pGraph);
pGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl);
pGraph->QueryInterface(IID_IMediaEventEx, (void**)&pEv);
// Create the graph and find the SAMI parser.
pGraph->RenderFile(L"E://爱后余生.vob", NULL);
hr = pGraph->FindFilterByName(L"Morgan Stream Switcher", &pSAMI);
if (SUCCEEDED(hr))
{
IAMStreamSelect *pStrm = NULL;
hr = pSAMI->QueryInterface(IID_IAMStreamSelect, (void**)&pStrm);
if (SUCCEEDED(hr))
{
DWORD dwStreams = 0;
pStrm->Count(&dwStreams);
printf("Stream count: %d/n", dwStreams);
// Select French and "GreenText"
hr = pStrm->Enable(1, AMSTREAMSELECTENABLE_ENABLE);
hr = pStrm->Enable(3, AMSTREAMSELECTENABLE_ENABLE);
// Print the name of each logical stream.
for (DWORD index = 0;
index < dwStreams;
index++)
{
DWORD dwFlags;
WCHAR *wszName;
hr = pStrm->Info(index, NULL, &dwFlags, NULL, NULL,
&wszName, NULL, NULL);
if (hr == S_OK)
{
wprintf(L"Stream %d: %s [%s]/n", index, wszName,
(dwFlags ? L"ENABLED"
: L"DISABLED"
);
CoTaskMemFree(wszName);
}
}
pStrm->Release();
}
pSAMI->Release();
}
// Run the graph and display the captions.
pMediaControl->Run();
printf("/n"
;
hr = pGraph->FindFilterByName(L"Morgan Stream Switcher", &pSAMI);
if (SUCCEEDED(hr))
{
IAMStreamSelect *pStrm = NULL;
hr = pSAMI->QueryInterface(IID_IAMStreamSelect, (void**)&pStrm);
if (SUCCEEDED(hr))
{
DWORD dwStreams = 0;
pStrm->Count(&dwStreams);
printf("Stream count: %d/n", dwStreams);
// Select French and "GreenText"
hr = pStrm->Enable(1, AMSTREAMSELECTENABLE_ENABLE);
hr = pStrm->Enable(3, AMSTREAMSELECTENABLE_ENABLE);
// hr = pStrm->Enable(5, AMSTREAMSELECTENABLE_ENABLE);
// Print the name of each logical stream.
for (DWORD index = 0;
index < dwStreams;
index++)
{
DWORD dwFlags;
WCHAR *wszName;
hr = pStrm->Info(index, NULL, &dwFlags, NULL, NULL,
&wszName, NULL, NULL);
if (hr == S_OK)
{
wprintf(L"Stream %d: %s [%s]/n", index, wszName,
(dwFlags ? L"ENABLED"
: L"DISABLED"
);
CoTaskMemFree(wszName);
}
}
pStrm->Release();
}
pSAMI->Release();
}
while (1)
{
long evCode, lParam1, lParam2;
pEv->GetEvent(&evCode, &lParam1, &lParam2, 100);
if (evCode == EC_OLE_EVENT) {
wprintf(L"%s/n", (BSTR)lParam2);
}
pEv->FreeEventParams(evCode, lParam1, lParam2);
if (evCode == EC_USERABORT || evCode == EC_COMPLETE || evCode == EC_ERRORABORT)
break;
}
// Clean up.
pMediaControl->Release();
pEv->Release();
pGraph->Release();
CoUninitialize();
return 0;
}
//---------------------------------------------------------------------------