Jamie
Jamie

Reputation: 1092

Passing unmanaged pointer to unmanaged object in managed class in C++/CLI

Let's assume the following situation:

class A
{
public:
  void MyMethod()
  {
    a->AnotherMethod(b);
  }
private:
  MyType* a;
  MyAnotherType* b;
};

and

typedef std::vector< int >MyAnotherType;

I want to pass a pointer to std::vector allocated (and filled in) in C++/CLI code to unmanaged C++. If I simply write a->AnotherMethod(b) then the vector is empty in unmanaged code (e.g. 4 elements in C++/CLI and 0 elements after passing to a.

What is the proper way to do that?

Upvotes: 1

Views: 1377

Answers (1)

Matěj Z&#225;bsk&#253;
Matěj Z&#225;bsk&#253;

Reputation: 17272

Try pragma managed and unmanaged.

Make sure the definition of the class you are passing into the DLL is defined in unmanaged section.

Upvotes: 1

Related Questions