How do I dynamically allocate a value struct and get a pointer to it?
If I have:
value struct x
{
String ^myString;
};
I can do this:
x vsInstance;开发者_C百科
x *pvs = &vsInstance; // "Unmanaged pointer" to managed object
And I can do this:
x ^vsInstance = gcnew x;
But I can't do this:
x *pvs = new vsInstance
I need a * pointer rather than a ^ because I am trying to hold this value struct inside an unmanaged class, and I need to dynamically allocate this object every time a class is created.
I found that what I was trying to do was unnecessary, I used gcroot which solved my design problem. However, I found that I can get a native pointer from pin_ptr but that it would not work in this circumstance
精彩评论