Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Passing Reference to Thread Delegate

Passing Reference to Thread Delegate

Scheduled Pinned Locked Moved Managed C++/CLI
c++csharpvisual-studiodata-structureshelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ricecake
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups