Yochai Timmer
Yochai Timmer

Reputation: 49251

C++/CLI umanaged pointer in constructor

I want to make a C++/CLI wrapper of some C++ class.

The problem is that I want the ref class to be initiated with a reference of the c++ object:

A (A& a);

This works fine as long as it is in the same aseembly and used in the same project.

But when I try to reference that project from a different project, and initiate a ref-class with a reference to an object from there, it won't recognize the types properly, and doesn't recognize the correct constructor.

Any ideas of how to solve this ?

Upvotes: 1

Views: 245

Answers (1)

mcdave
mcdave

Reputation: 2580

I don't think you will be able to use a reference to the C++ object in this instance, but you can pass a pointer to the C++ object across assembly boundaries by storing it in an IntPtr and then retrieving it using static_cast.

class nativeA; // Pre declaration

A (IntPtr a)
{
    nativeA * nativePtr = static_cast<nativeA*>(a.ToPointer());
    // Do something with nativeA
}

Upvotes: 1

Related Questions