C++ cli 指向“的指针”;值结构x";

C++ cli 指向“的指针”;值结构x";,c++-cli,C++ Cli,如何动态分配值结构并获取指向它的指针 如果我有: value struct x { String ^myString; }; 我可以这样做: x vsInstance; x *pvs = &vsInstance; // "Unmanaged pointer" to managed object x ^vsInstance = gcnew x; 我可以做到: x vsInstance; x *pvs = &vsInstance; // "Unmanaged point

如何动态分配值结构并获取指向它的指针

如果我有:

value struct x
{
    String ^myString;
};
我可以这样做:

x vsInstance;
x *pvs = &vsInstance; // "Unmanaged pointer" to managed object
x ^vsInstance = gcnew x;
我可以做到:

x vsInstance;
x *pvs = &vsInstance; // "Unmanaged pointer" to managed object
x ^vsInstance = gcnew x;
但我不能这么做:

x *pvs = new vsInstance

我需要一个*指针而不是^,因为我试图将此值结构保存在非托管类中,并且每次创建类时我都需要动态分配此对象。

我发现我尝试做的是不必要的,我使用了gcroot解决了我的设计问题。然而,我发现我可以从pin_ptr获取本机指针,但在这种情况下它无法工作