locked
Call managed member function from unmanaged code? RRS feed

  • Question

  • Is there anyway to do this? All I have seen are examples for calling static managed functions.
    Friday, July 17, 2009 10:40 PM

Answers

  • Okay well Mixed C++ actually did something right.

    void Test(gcroot<ITest^> t)
    {
        ITest^ c = t;
        c->Func();
    }

    Actually converts between gcroot and the actual class easily. So I guess I will store in a gcroot and typecast/call the function.

    Wasn't as hard as I originally thought, just CLI C++ isn't the most well documented(besides msdn).
    • Marked as answer by high6 Friday, July 17, 2009 11:19 PM
    Friday, July 17, 2009 11:19 PM

All replies

  • Yes. Obviously the unmanaged code need to instantiate the managed class before calling the managed method. This could be done directly using C++/CLI, or indirectly using a COM Interop.
    Friday, July 17, 2009 11:00 PM
  • I have read that you can store managed objects with gcroot which is probably what I will have to use, how do you call one of its functions though?
    Friday, July 17, 2009 11:10 PM
  • Okay well Mixed C++ actually did something right.

    void Test(gcroot<ITest^> t)
    {
        ITest^ c = t;
        c->Func();
    }

    Actually converts between gcroot and the actual class easily. So I guess I will store in a gcroot and typecast/call the function.

    Wasn't as hard as I originally thought, just CLI C++ isn't the most well documented(besides msdn).
    • Marked as answer by high6 Friday, July 17, 2009 11:19 PM
    Friday, July 17, 2009 11:19 PM