Click here to Skip to main content
15,889,864 members
Please Sign up or sign in to vote.
1.00/5 (2 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
Updated 26-Aug-15 19:59pm
v4
Comments
Richard MacCutchan 26-Aug-15 6:52am    
Study the documentation for the DLL and follow its rules.
Zon-cpp 26-Aug-15 7:08am    
thank you, but there isn't any document for the DLL.
Richard MacCutchan 26-Aug-15 7:35am    
So how do you think anyone here can guess what it does, or how it works?
Zon-cpp 26-Aug-15 7:45am    
when i use an activeX control in my VC++ project, i use the Properties window to add event handlers, an event sink map is declared and defined in my project.
But when i use Dll, i can't define and declare event handlers.


name of event is: TransactionDoneEvent(string msg)
when i call SendInfo() function of Dll, the event will be called.
Richard MacCutchan 26-Aug-15 7:54am    
A DLL is just a code library, and without the documentation it is impossible to guess how to use it, or what features it has.

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