Linked Questions

Popular Questions

Sharing the native pointer between managed wrappers in C++/CLI

Asked by At

Say I have two native (unmanaged) classes A and B. I create a managed wrapper around A as

public ref class AWrapper
    A *a;
        // Finalizer that frees pointer a
        // Destructor that calls the finalizer
        // Wrapped methods

Similarly for B to create BWrapper.

Now assume one of the methods of B has signature void (A*). How do I wrap such a method?

In my understanding, the wrapper method should have the signature void (AWrapper^) in this situation, but how do I get the A* from AWrapper^ then? I'm hoping there's a better way than to make all the native pointers (A*, B*) which need to be consumed by other classes have internal visibility.

Thanks in advance.

Related Questions