views:

675

answers:

2

Hi,

say I have an asynchronous library, written in native C++, with an interface similar to this:

class connection {
public:
    boost::signal< void() > sig_connection_made;
    boost::signal< void(const std::string&) > sig_error;

    void connect(const std::string& host, const std::string& port);
};

that I want to wrap in C#. Does anyone know of a way, using SWIG or something similar, that will allow me to bind the signals to C# delegates?

+1  A: 

Sounds like a task for C++/CLI.

Also see Mixed Assemblies and Calling Native Functions from Managed Code.

Jason Baker
Not as simple as I would have liked, but it never is :). I'll definitely look into it and see if I can write an intermediate wrapper in C++/CLI which does the necessary translation.
Mic
Indeed. But this is one of .NET's biggest problems: getting it to interface with everything else. Good luck to you!
Jason Baker
+1  A: 

you can pass a delegate into c++ from C# using SWIG assign it to a function pointer and then call the function pointer and it will trigger the delegate.

iterationx