Hi All,
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
1 2 3 4 5 6 7 8 9 10 11
|
#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);
}
|
4. The following is a part of my code in mfc_testDlg.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
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
}
|
My code generates an error due to the line:
VideoStream->NewFrame += gcnew AForge::Video::NewFrameEventHandler(this, &Cmfc_testDlg::VideoStream_NewFrame);
This is the generated error:
error C3364: 'AForge::Video::NewFrameEventHandler' : invalid argument for delegate constructor; delegate target needs to be a pointer to a member function
It seems I couldn’t register the event listener properly in C++/with .NET CLR support. Actually I am not expert in C++ but I am fairly experience in C# and Java. Can you please suggest what I should change in my code?
Best Regards,
Abdullah