开发者

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开发者_JAVA百科 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 ?


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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜