I want to connect c++ and c# side of my application using "inproc" binding. To do that I need to share context somehow, because both c# and c++ parts should use the same context. How can I do that? I'm using official c++ and c# bindings.
I.e. on c# side i need ZeroMQ.ZmqContext.
And on c++ side i need zmq::context_t.
And both instances should point to the same context so I can use "inproc".
ZContext
has apublic IntPtr ContextPtr { get; }
field.Albiet a hacky approach - using reflection seems to be the only way to access that field currently. Unless API is added to the C# wrappers to allow initialization from a raw pointer (and similarly add ownership API), this seems like the only route.
Something like this could be done:
Getting and passing the
IntPtr
to theContext
is up to you. There's several ways to do that:As a side note: It would be neat to have context initialization from raw pointers (with ownership API) in ZeroMQ wrappers. It would go a long way to allowing a lot of inter-process messaging between different language runtimes.
Hopefully the ZMQ team implements this!