RE: [Boost-users] boost::bind and methods of managed classes
Hello Vasco,
From: Vasco Lohrenscheit [mailto:valoh@krautgames.de]
is there a easy way/workaround to use methods of managed classes with boost::bind?
It's not exactly easy, but I think it can be done.
First of all, you won't be able to take the address of
TestManagedClass::test because it's a managed class. Second, the calling
conventions of invoking the signal (default: __stdcall) and the function
test (__clrcall) are different. Here's a workaround that should work:
* Create a nested __nogc class in the __gc class (technically, it doesn't
need to be nested, just __nogc).
* In the nested class, store a pointer (using gcroot<>, as it's a managed
class) to the outer class.
* In the constructor of the outer class, create an instance of the nested
class.
* Define a callback member in both classes. In the inner class, simply
forward to the corresponding function in the outer class.
* Create the bind expression using the address of the nested class'
function.
* Invoke the signal and keep your fingers crossed.
Here's an example that demonstrates the technique:
#include "boost/bind.hpp"
#include "boost/signals.hpp"
#include "vcclr.h" // For gcroot<>
boost::signal
participants (1)
-
Bjorn.Karlsson@readsoft.com