none
c++/cli interop and unmanaged entry point RRS feed

  • Question

  • I found nice tutorial how to call managed code from unmanaged code. However it requires me to create managed object first. Here is the problem - there can not be any static objects in managed code and my entry point is unmanaged. As you know we cant create managed objects in unmanaged classes so... What approach should i take to call managed code then?
    Saturday, July 26, 2008 7:58 AM

Answers

  • You can create a native class that is compiled to IL and use it to store a reference to a managed object through the gcroot<> template.  This native class can be created by your unmanaged entry point.

    Sasha Goldshtein | http://blogs.microsoft.co.il/blogs/sasha
    • Marked as answer by roxaz Saturday, July 26, 2008 11:52 AM
    Saturday, July 26, 2008 10:33 AM

All replies

  • You can create a native class that is compiled to IL and use it to store a reference to a managed object through the gcroot<> template.  This native class can be created by your unmanaged entry point.

    Sasha Goldshtein | http://blogs.microsoft.co.il/blogs/sasha
    • Marked as answer by roxaz Saturday, July 26, 2008 11:52 AM
    Saturday, July 26, 2008 10:33 AM
  • ok.. this is quite confusing cause IL isnt native code... anyway, how do i do that? my first guess is ref class NativeIL {} in #pragma unmanaged section, however its wrong..

    EDIT:
    i tried the other way around - class NativeIL{} in #pragma managed and this worked, not exactly how i wanted, but worked. app still crashes when managed method is invoked.

    EDIT2:
    ok, doesnt crash at all, i had to create a thread to run a GUI ;]
    • Edited by roxaz Saturday, July 26, 2008 11:01 AM Works ;]
    Saturday, July 26, 2008 10:51 AM
  • What I meant by a native class that is compiled to IL is exactly what you did and worked for you - a C++ class that is compiled to IL (as part of #pragma managed).

    Glad to hear it worked out.

    Sasha Goldshtein | http://blogs.microsoft.co.il/blogs/sasha
    Sunday, July 27, 2008 5:18 PM