开发者

Pointer to "value struct x"

开发者 https://www.devze.com 2022-12-22 16:38 出处:网络
How do I dynamically allocate a value struct and get a pointer to it? If I have: value struct x { String ^myString;

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

0

精彩评论

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