Click here to Skip to main content
15,891,923 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I want to use a dll in my VC++ project. The Dll, have some functions and some events. how do i handle events of dll in my project?

name of event is: TestEvent(int i , string msg) when i call test() function of Dll, the event will be called.

The Dll is written by C# whit this code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace My_Managed
{
    using System.Collections;

    // A delegate type for hooking up change notifications.
    public delegate void TestDelegate(int i , string msg);

    public class Class1
    {
        public event TestDelegate TestEvent;

        public virtual void OnTestEvent(int i , string msg)
        {
            if (TestEvent != null)
                OnTestEvent(i, msg);
        }
    }
}

// Interface declaration.
public interface MY_Interface
{
    bool test();
};

// Interface implementation.
public class MY_Class : MY_Interface
{
    MY_Managed.Class1 c = new MY_Managed.Class1();

    public MY_Class()
    {
    }

    public bool test()
    {
        c.OnTestEvent(99, "ok Test");
        return true;
    }
}



I register the Dll and use .tlb of it in my VC++ Project:
#import "..\..\MY_Managed.tlb" raw_interfaces_only
using namespace MY_Managed;

void CVCTestDlg::OnBnClickedButton1()
{
    try
    {
        MY_InterfacePtr pos(__uuidof(MY_Class));

        VARIANT_BOOL b;
        pos->test(&b);
    }
    catch(CException* ex)
    {
        WCHAR wch[1024];
        ex->GetErrorMessage(wch, 1024);
        AfxMessageBox(wch);
    }
}


Now, how do I Handle 'TestEvent' in VC++ Project? how do I hook it? Please help me.
Posted
Comments
[no name] 27-Aug-15 18:26pm    
You have received help on your other post. Have you read the comments? What information have you read on raising events and event handling VIA msdn?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900