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

C

cctv.star

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.
 
S

Sheng Jiang[MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top