小弟我把Demos\Playcap裡的程式加上一個旋轉檯控制的程式碼後...可以執行,不過當選擇Device後要關閉時卻會出現下列錯誤!
或是
請問是哪裡出問題了..?謝謝~~
以下是部分程式碼..
//--------------------------------------------------------------------
#include
#pragma hdrstop
#include "main.h"
//--------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "DSPack"
#pragma resource "*.dfm"
TMainForm *MainForm;
TSysDevEnum *SysDev;
HANDLE hComm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
SysDev = new TSysDevEnum(CLSID_VideoInputDeviceCategory);
if (SysDev->CountFilters > 0) {
int i;
TMenuItem *Device;
for(i = 0; i < SysDev->CountFilters; i++) {
Device = new TMenuItem(Devices);
Device->Caption = SysDev->Filters[i].FriendlyName;
Device->Tag = i;
Device->OnClick = DevicesClick;
Devices->Add(Device);
}
}
//------------------------另外加的部分(開啟RS232),可能是這裡有問題
char *ComNo;
DCB dcb;
String Temp;
Temp="COM2";
ComNo=Temp.c_str();
hComm=CreateFile(ComNo,GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,0);
if(hComm==INVALID_HANDLE_VALUE)
{
MessageBox(0,"¶}±Ò³q°T°ð¿ù»~","Comm Error",MB_OK);
return;
}
GetCommState(hComm,&dcb);
dcb.BaudRate=CBR_9600;
dcb.ByteSize=8;
dcb.Parity=NOPARITY;
dcb.StopBits=ONESTOPBIT;
if(!SetCommState(hComm,&dcb))
{
MessageBox(0,"³q°T°ð³]©w¿ù»~","Set Error",MB_OK);
CloseHandle(hComm);
return;
}
//------------------------
}
//--------------------------------------------------------------------
void __fastcall TMainForm::DevicesClick(TObject *Sender)
{
FilterGraph->ClearGraph();
FilterGraph->Active = false;
Filter->BaseFilter->Moniker = SysDev->GetMoniker(((TMenuItem *)Sender)->Tag);
FilterGraph->Active = true;
ICaptureGraphBuilder2 *Graph = NULL;
IBaseFilter *SourceFilter = NULL;
IBaseFilter *VideoFilter = NULL;
CheckDSError(FilterGraph->QueryInterface(IID_ICaptureGraphBuilder2, &Graph));
CheckDSError(VideoWindow->QueryInterface(IID_IBaseFilter, &VideoFilter));
CheckDSError(Filter->QueryInterface(IID_IBaseFilter, &SourceFilter));
Graph->RenderStream(&PIN_CATEGORY_PREVIEW, NULL, SourceFilter, NULL, VideoFilter);
FilterGraph->Play();
Graph->Release();
VideoFilter->Release();
SourceFilter->Release();
}
//--------------------------------------------------------------------
void __fastcall TMainForm::FormDestroy(TObject *Sender)
{
delete SysDev;
}
//--------------------------------------------------------------------
void __fastcall TMainForm::FormCloseQuery(TObject *Sender, bool &CanClose)
{
FilterGraph->Active = false;
}
//--------------------------------------------------------------------
void __fastcall TMainForm::Button2Click(TObject *Sender)
{
Close();
}
//--------------------------------------------------------------------