Passing Reference to Thread Delegate
-
I am using Managed C++ (VS .NET 2003 SP1), so I can't use any of the new features in C++/CLI (VS 2005). I have a function that needs to take in a
const
reference to a native class, e.g.,void MyManagedClass::f(const UnmanagedClass& u);
If I just call it straight, like (inside another member function of
MyManagedClass
):UnmanagedClass u;
f(u);then it works OK. However, I would like to call this function in another thread. I have something like this, but it doesn't work:
__delegate System::Void ThreadDelegate(const UnmanagedClass&);
// ...
UnmanagedClass u;
ThreadDelegate* td = new ThreadDelegate*(this, f);
Object* args[] = new Object*[1];
args[0] = &u;
Invoke(td, args);The problem is passing the parameter to the delegate. I would rather not have to write a managed wrapper for my unmanaged class if it can easily be avoided. Is there any way to do what I want? I have tried putting in
__nogc
in various parts of the array declaration but I can't get it to compile.-- Marcus Kwok