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 开发者_StackOverflow中文版and 0 elements after passing to a
.
What is the proper way to do that?
Try pragma managed and unmanaged.
Make sure the definition of the class you are passing into the DLL is defined in unmanaged section.
精彩评论