Error configuring event listener in C++ with .NET CLR support (managed and unmanaged

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fararjeh
    New Member
    • Jul 2012
    • 1

    #1

    Error configuring event listener in C++ with .NET CLR support (managed and unmanaged

    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
    Code:
     
    #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
    Code:
    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:
    Code:
    VideoStream->NewFrame += gcnew AForge::Video::NewFrameEventHandler(this, &Cmfc_testDlg::VideoStream_NewFrame);
    This is the generated error:
    Code:
    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
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Operators like
    Code:
    new
    or
    Code:
    gcnew
    return an address or a reference to a object so the += in your gcnew line looks suspicious. Unfortunately, I am not an expert with gcnew so I may be off base.

    Comment

    Working...