I am using AForge library to capture live video stream from an IP camera. Initially, I tested my task in a simple C# application but I should convert my code into my existing MFC C++ application. I made some progress as the following:
1. I configured the project to become compatible with .NET common run-time language
a. Right click the project and select ‘Properties’.
b. From the left panel, I selected ‘Configuration Properties’
c. Select ‘General’.
d. In ‘Common Language Runtime Support’ list select Common Language Runtime Support (/clr))
2. I added the necessary AForge DLLs to the projct. (Right click the project and select ‘References’)
3. The following is a part of my code in mfc_testDlg.h
Expand|Select|Wrap|Line Numbers
- #include <vcclr.h> //to use gcroot
- using namespace AForge::Controls;
- using namespace AForge::Video;
- class Cmfc_testDlg : public CDialog
- {
- public:
- gcroot<AForge::Video::MJPEGStream^> VideoStream;
- void temp();
- void VideoStream_NewFrame(System::Object^ sender, AForge::Video::NewFrameEventArgs^ eventArgs);
- }
Expand|Select|Wrap|Line Numbers
- using namespace AForge::Controls;
- using namespace AForge::Video;
- void Cmfc_testDlg::temp()
- {
- VideoStream = (gcnew AForge::Video::MJPEGStream());
- VideoStream->Source = "http://IP Address/img/mjpeg.cgi";
- VideoStream->Login = "User Name";
- VideoStream->Password = "Password";
- VideoStream->NewFrame += gcnew AForge::Video::NewFrameEventHandler(this, &Cmfc_testDlg::VideoStream_NewFrame);
- VideoStream->Start();
- }
- void Cmfc_testDlg::VideoStream_NewFrame(System::Object^ sender, AForge::Video::NewFrameEventArgs^ eventArgs)
- {
- //Write Some Code
- }
Expand|Select|Wrap|Line Numbers
- VideoStream->NewFrame += gcnew AForge::Video::NewFrameEventHandler(this, &Cmfc_testDlg::VideoStream_NewFrame);
Expand|Select|Wrap|Line Numbers
- error C3364: 'AForge::Video::NewFrameEventHandler' : invalid argument for delegate constructor; delegate target needs to be a pointer to a member function
Best Regards,
Abdullah