开发者

C++/CLI umanaged pointer in constructor

开发者 https://www.devze.com 2023-03-07 09:34 出处:网络
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:

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

精彩评论

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

关注公众号