Using C++/CLI wrapper to call .NET assembly from native code?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cctv.star@gmail.com

    #1

    Using C++/CLI wrapper to call .NET assembly from native code?

    I need to dynamically load and call .NET assembly from native
    application, written in C++.

    I'm trying to do this by creating a (managed) module, written in C++/
    CLI, whose header can be #included from native code like normal C++
    header, and whose .cpp file uses C++/CLI to actually load and
    call .NET assembly.

    It kind of works right now, but not exactly how I want it to. Ideally,
    I want to have something like a C++ wrapper class, which hides behing
    its public interface all .NET stuff. In particular, I want the
    lifetime of this wrapper to correspond to the time the .NET assembly
    is loaded and accessible. The trouble is, a C++ class cannot contain
    handles to any .NET objects. I cannot even create a global or static
    handle. Right now evey time I need to call the assembly, I need to
    load it. How to overcome this limitation?

    I suspect I can wrap all .NET stuff in COM, but ideally I'd like to
    stay away from (directly) calling COM and use C++/CLI instead.

  • Sheng Jiang[MVP]

    #2
    Re: Using C++/CLI wrapper to call .NET assembly from native code?

    >The trouble is, a C++ class cannot contain handles to any .NET objects.
    This is not true, you can search for "How to: Declare Handles in Native
    Types" in MSDN.


    --
    Sheng Jiang
    Microsoft MVP in VC++
    <cctv.star@gmai l.comwrote in message
    news:1183128481 .894383.76420@i 13g2000prf.goog legroups.com...
    I need to dynamically load and call .NET assembly from native
    application, written in C++.
    >
    I'm trying to do this by creating a (managed) module, written in C++/
    CLI, whose header can be #included from native code like normal C++
    header, and whose .cpp file uses C++/CLI to actually load and
    call .NET assembly.
    >
    It kind of works right now, but not exactly how I want it to. Ideally,
    I want to have something like a C++ wrapper class, which hides behing
    its public interface all .NET stuff. In particular, I want the
    lifetime of this wrapper to correspond to the time the .NET assembly
    is loaded and accessible. The trouble is, a C++ class cannot contain
    handles to any .NET objects. I cannot even create a global or static
    handle. Right now evey time I need to call the assembly, I need to
    load it. How to overcome this limitation?
    >
    I suspect I can wrap all .NET stuff in COM, but ideally I'd like to
    stay away from (directly) calling COM and use C++/CLI instead.
    >

    Comment

    Working...